Implement medicine library and cabinet
This commit is contained in:
parent
db79af06f7
commit
1f66fab30f
72 changed files with 7642 additions and 319 deletions
|
|
@ -1,5 +1,7 @@
|
|||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import Fastify from 'fastify';
|
||||
import { fastifyAwilixPlugin } from '@fastify/awilix';
|
||||
import { asValue } from 'awilix';
|
||||
|
||||
// Mock jose for the auth plugin dependency
|
||||
vi.mock('jose', () => ({
|
||||
|
|
@ -10,19 +12,33 @@ vi.mock('jose', () => ({
|
|||
email: 'test@example.com',
|
||||
preferred_username: 'testuser',
|
||||
realm_access: { roles: ['member'] },
|
||||
householdIds: ['hh1'],
|
||||
},
|
||||
protectedHeader: { alg: 'RS256' },
|
||||
key: {},
|
||||
}),
|
||||
}));
|
||||
|
||||
const { mockFindByKeycloakId } = vi.hoisted(() => ({
|
||||
mockFindByKeycloakId: vi.fn(),
|
||||
}));
|
||||
|
||||
import authPlugin from './auth.plugin.js';
|
||||
import householdPlugin from './household.plugin.js';
|
||||
|
||||
describe('household.plugin', () => {
|
||||
async function buildApp() {
|
||||
const app = Fastify({ logger: false });
|
||||
await app.register(fastifyAwilixPlugin, {
|
||||
disposeOnClose: true,
|
||||
disposeOnResponse: true,
|
||||
strictBooleanEnforced: true,
|
||||
});
|
||||
app.diContainer.register({
|
||||
usersRepository: asValue({
|
||||
findByKeycloakId: mockFindByKeycloakId,
|
||||
upsertFromToken: vi.fn().mockResolvedValue({ householdIds: ['hh1'] }),
|
||||
}),
|
||||
});
|
||||
await app.register(authPlugin);
|
||||
await app.register(householdPlugin);
|
||||
return app;
|
||||
|
|
@ -30,6 +46,7 @@ describe('household.plugin', () => {
|
|||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
mockFindByKeycloakId.mockResolvedValue({ householdIds: ['hh1'] });
|
||||
});
|
||||
|
||||
it('skips household check for public routes', async () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue