refactoring magic strings in layout.server file (guard), including new routes and tests
This commit is contained in:
29
tests/Layout.test.ts
Normal file
29
tests/Layout.test.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { load } from '../src/routes/(angemeldet)/+layout.server';
|
||||
import { ROUTE_NAMES } from '../src/routes';
|
||||
import { baseData, mockEvent } from './fixtures';
|
||||
|
||||
describe('+layout.server load(): Teste korrekte URL', () => {
|
||||
test('Werfe redirect zu /anmeldung wenn User nicht eingeloggt', async () => {
|
||||
const mockEvent = {
|
||||
locals: {
|
||||
user: null
|
||||
},
|
||||
url: new URL(`https://example.com/not-anmeldung`)
|
||||
};
|
||||
try {
|
||||
load(mockEvent);
|
||||
throw new Error('Expected load() to throw');
|
||||
} catch (err) {
|
||||
expect(err.status).toBe(303);
|
||||
expect(err.location).toBe(ROUTE_NAMES.ANMELDUNG);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('+layout.server load(): Teste erfolgreichen Pfad', () => {
|
||||
test('Werfe kein Fehler', async () => {
|
||||
const result = load(mockEvent);
|
||||
expect(result).toEqual({ user: baseData.user });
|
||||
});
|
||||
});
|
||||
@@ -44,3 +44,10 @@ export const baseData = {
|
||||
url: `https://example.com/${testVorgangsList[0].vorgangToken}`,
|
||||
crimeNames: ['modell-A', 'Fall-A']
|
||||
};
|
||||
|
||||
export const mockEvent = {
|
||||
locals: {
|
||||
user: baseData.user
|
||||
},
|
||||
url: new URL(`https://example.com/anmeldung`)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user