From 6c460988f18925c6a8a1595b687252389e0840e4 Mon Sep 17 00:00:00 2001 From: arc-alex Date: Wed, 28 May 2025 17:06:08 +0200 Subject: [PATCH] fix test --- .../common/utils/__tests__/urlPresets.test.ts | 27 ++++++++--------- .../session/__tests__/session.service.test.ts | 29 ++++++++++++++++--- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/apps/client/src/common/utils/__tests__/urlPresets.test.ts b/apps/client/src/common/utils/__tests__/urlPresets.test.ts index 7b127d703..15e76367a 100644 --- a/apps/client/src/common/utils/__tests__/urlPresets.test.ts +++ b/apps/client/src/common/utils/__tests__/urlPresets.test.ts @@ -64,13 +64,13 @@ describe('getRouteFromPreset()', () => { describe('handle url sharing edge cases', () => { it('finds the correct preset when the url contains extra arguments', () => { const location = resolvePath('/demopage?locked=true&token=123'); - expect(getRouteFromPreset(location, presets)?.startsWith('timer?user=guest&alias=demopage')).toBeTruthy() - }) + expect(getRouteFromPreset(location, presets)?.startsWith('timer?user=guest&alias=demopage')).toBeTruthy(); + }); it('appends the feature params to the alias', () => { const location = resolvePath('/demopage?locked=true&token=123'); - expect(getRouteFromPreset(location, presets)).toBe('timer?user=guest&alias=demopage&locked=true&token=123') - }) + expect(getRouteFromPreset(location, presets)).toBe('timer?user=guest&alias=demopage&locked=true&token=123'); + }); }); }); @@ -79,29 +79,30 @@ describe('generatePathFromPreset()', () => { ['timer?user=guest', 'demopage', 'timer?user=guest&alias=demopage'], ['timer?user=admin', 'demopage', 'timer?user=admin&alias=demopage'], ])('generates a path from a preset: %s', (path, alias, expected) => { - expect(generatePathFromPreset(path, alias, null, null)).toEqual(expected); + expect(generatePathFromPreset(path, alias, null, null, null, null)).toEqual(expected); }); test('appends the feature params to the alias', () => { - expect(generatePathFromPreset('timer?user=guest', 'demopage', 'true', '123')).toBe('timer?user=guest&alias=demopage&locked=true&token=123'); + expect(generatePathFromPreset('timer?user=guest', 'demopage', 'true', '123', null, null)).toBe( + 'timer?user=guest&alias=demopage&locked=true&token=123', + ); }); }); describe('arePathsEquivalent()', () => { - it("checks whether the paths match", () => { + it('checks whether the paths match', () => { expect(arePathsEquivalent('demopage', 'timer')).toBeFalsy(); expect(arePathsEquivalent('timer', 'timer')).toBeTruthy(); expect(arePathsEquivalent('timer?user=guest', 'timer?user=guest')).toBeTruthy(); - }) + }); - it("checks whether the params match", () => { + it('checks whether the params match', () => { expect(arePathsEquivalent('timer?test=a', 'timer?test=b')).toBeFalsy(); expect(arePathsEquivalent('timer?test=a', 'timer?test=a')).toBeTruthy(); - }) + }); - it("considers edge cases for the url sharing feature", () => { + it('considers edge cases for the url sharing feature', () => { expect(arePathsEquivalent('timer?test=a&locked=true=token=123', 'timer?test=b')).toBeFalsy(); expect(arePathsEquivalent('timer?test=a&locked=true=token=123', 'timer?test=a')).toBeTruthy(); - }) + }); }); - diff --git a/apps/server/src/api-data/session/__tests__/session.service.test.ts b/apps/server/src/api-data/session/__tests__/session.service.test.ts index 82b11e41f..4c18cb770 100644 --- a/apps/server/src/api-data/session/__tests__/session.service.test.ts +++ b/apps/server/src/api-data/session/__tests__/session.service.test.ts @@ -3,17 +3,26 @@ import { generateAuthenticatedUrl } from '../session.service.js'; describe('generateAuthenticatedUrl()', () => { describe('for local IP addresses', () => { it('generates a link without locking or authentication', () => { - const localhostNotLocked = generateAuthenticatedUrl('http://localhost:3000', 'timer', false, false); + const localhostNotLocked = generateAuthenticatedUrl('http://localhost:3000', 'timer', false, false, false, false); expect(localhostNotLocked.toString()).toBe('http://localhost:3000/timer'); }); it('generates a link with IP locking enabled', () => { - const ipLocked = generateAuthenticatedUrl('http://192.168.10.173:4001', 'timer', true, false); + const ipLocked = generateAuthenticatedUrl('http://192.168.10.173:4001', 'timer', true, false, false, false); expect(ipLocked.toString()).toBe('http://192.168.10.173:4001/timer?locked=true'); }); it('generates a link with authentication token and IP locking', () => { - const withAuth = generateAuthenticatedUrl('http://192.168.10.173:4001', 'timer', true, true, undefined, '1234'); + const withAuth = generateAuthenticatedUrl( + 'http://192.168.10.173:4001', + 'timer', + true, + false, + false, + true, + undefined, + '1234', + ); expect(withAuth.toString()).toBe('http://192.168.10.173:4001/timer?token=1234&locked=true'); }); }); @@ -25,13 +34,23 @@ describe('generateAuthenticatedUrl()', () => { 'timer', false, false, + false, + false, 'prefix', ); expect(cloudNotLocked.toString()).toBe('https://cloud.getontime.no/prefix/timer'); }); it('generates a link with IP locking enabled', () => { - const ipLocked = generateAuthenticatedUrl('https://cloud.getontime.no/prefix', 'timer', true, false, 'prefix'); + const ipLocked = generateAuthenticatedUrl( + 'https://cloud.getontime.no/prefix', + 'timer', + true, + false, + false, + false, + 'prefix', + ); expect(ipLocked.toString()).toBe('https://cloud.getontime.no/prefix/timer?locked=true'); }); @@ -40,6 +59,8 @@ describe('generateAuthenticatedUrl()', () => { 'https://cloud.getontime.no/prefix', 'timer', true, + false, + false, true, 'prefix', '1234',