From ccc5e97000b2e30e587910e0e00781a0a8af4e76 Mon Sep 17 00:00:00 2001 From: claude_code Date: Sun, 21 Jun 2026 18:49:32 +0300 Subject: [PATCH] test(server): port missing returnToken/env edge cases from #116 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR #120 rewrote auth.controller.spec.ts and environment.service.spec.ts in a leaner style but dropped several edge cases that PR #116 covered. Port the gaps so the server coverage matches the original review intent: - auth.controller: returnToken=false must behave like the omitted case (no token in the response body, cookie still set) — guards an `!== undefined`-style regression. - environment.getCorsAllowedOrigins: empty string -> [], single origin, and leading/trailing/duplicate commas with spaces -> trimmed list. - environment.isSwaggerEnabled: mixed-case "True" -> true; "false"/""/"1" -> false. Co-Authored-By: Claude Opus 4.8 --- .../src/core/auth/auth.controller.spec.ts | 20 ++++++++++ .../environment/environment.service.spec.ts | 37 ++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/apps/server/src/core/auth/auth.controller.spec.ts b/apps/server/src/core/auth/auth.controller.spec.ts index 103d1ec9..a25c90cb 100644 --- a/apps/server/src/core/auth/auth.controller.spec.ts +++ b/apps/server/src/core/auth/auth.controller.spec.ts @@ -81,5 +81,25 @@ describe('AuthController', () => { expect(result).toBeUndefined(); expect(res.setCookie).toHaveBeenCalledTimes(1); }); + + // Guards against an `!== undefined`-style bug: an explicit `false` must + // behave exactly like the omitted case (cookie set, no token in the body). + it('returns no body token but still sets the cookie when returnToken is false', async () => { + const { ctrl, res } = makeController(); + const loginInput = { + email: 'a@b.com', + password: 'pw', + returnToken: false, + }; + + const result = await ctrl.login( + workspace as any, + res as any, + loginInput as any, + ); + + expect(result).toBeUndefined(); + expect(res.setCookie).toHaveBeenCalledTimes(1); + }); }); }); diff --git a/apps/server/src/integrations/environment/environment.service.spec.ts b/apps/server/src/integrations/environment/environment.service.spec.ts index 1af7522f..565755de 100644 --- a/apps/server/src/integrations/environment/environment.service.spec.ts +++ b/apps/server/src/integrations/environment/environment.service.spec.ts @@ -25,8 +25,7 @@ describe('EnvironmentService', () => { describe('getCorsAllowedOrigins', () => { it('splits, trims, and drops empty entries', () => { const svc = makeService({ - CORS_ALLOWED_ORIGINS: - 'https://a.com, https://b.com ,, https://c.com', + CORS_ALLOWED_ORIGINS: 'https://a.com, https://b.com ,, https://c.com', }); expect(svc.getCorsAllowedOrigins()).toEqual([ 'https://a.com', @@ -39,6 +38,25 @@ describe('EnvironmentService', () => { const svc = makeService({}); expect(svc.getCorsAllowedOrigins()).toEqual([]); }); + + it('returns an empty array for an empty string', () => { + const svc = makeService({ CORS_ALLOWED_ORIGINS: '' }); + expect(svc.getCorsAllowedOrigins()).toEqual([]); + }); + + it('returns a single origin unchanged', () => { + const svc = makeService({ + CORS_ALLOWED_ORIGINS: 'https://app.example', + }); + expect(svc.getCorsAllowedOrigins()).toEqual(['https://app.example']); + }); + + // Adversarial case: leading/trailing/duplicate commas with surrounding + // spaces must be dropped, exercising both .map(trim) and .filter(Boolean). + it('drops leading/trailing commas with surrounding spaces', () => { + const svc = makeService({ CORS_ALLOWED_ORIGINS: ' , a , , b ' }); + expect(svc.getCorsAllowedOrigins()).toEqual(['a', 'b']); + }); }); describe('isSwaggerEnabled', () => { @@ -54,6 +72,12 @@ describe('EnvironmentService', () => { ); }); + it('is true for mixed-case "True"', () => { + expect(makeService({ SWAGGER_ENABLED: 'True' }).isSwaggerEnabled()).toBe( + true, + ); + }); + it('defaults to false when absent', () => { expect(makeService({}).isSwaggerEnabled()).toBe(false); }); @@ -65,6 +89,15 @@ describe('EnvironmentService', () => { expect(makeService({ SWAGGER_ENABLED: 'yes' }).isSwaggerEnabled()).toBe( false, ); + expect(makeService({ SWAGGER_ENABLED: 'false' }).isSwaggerEnabled()).toBe( + false, + ); + expect(makeService({ SWAGGER_ENABLED: '' }).isSwaggerEnabled()).toBe( + false, + ); + expect(makeService({ SWAGGER_ENABLED: '1' }).isSwaggerEnabled()).toBe( + false, + ); }); }); });