diff --git a/server/test/medium/specs/services/auth.service.spec.ts b/server/test/medium/specs/services/auth.service.spec.ts index 8208137e00..f74872c575 100644 --- a/server/test/medium/specs/services/auth.service.spec.ts +++ b/server/test/medium/specs/services/auth.service.spec.ts @@ -16,6 +16,7 @@ import { UserRepository } from 'src/repositories/user.repository'; import { DB } from 'src/schema'; import { AuthService } from 'src/services/auth.service'; import { mediumFactory, newMediumService } from 'test/medium.factory'; +import { mockEnvData } from 'test/repositories/config.repository.mock'; import { factory } from 'test/small.factory'; import { getKyselyDB } from 'test/utils'; @@ -67,6 +68,19 @@ describe(AuthService.name, () => { await expect(response).rejects.toThrow(BadRequestException); await expect(response).rejects.toThrow('Admin setup is not available'); }); + + it('should not allow signup when setup is disabled', async () => { + // a database without an admin, so that the env var is the only thing rejecting the signup + const { sut, ctx } = setup(await getKyselyDB()); + vi.spyOn(ctx.get(ConfigRepository), 'getEnv').mockReturnValue(mockEnvData({ setup: { allow: false } })); + const dto = { name: 'Admin', email: 'admin@immich.cloud', password: 'password' }; + + const response = sut.adminSignUp(dto); + await expect(response).rejects.toThrow(BadRequestException); + await expect(response).rejects.toThrow('Admin setup is not available'); + + await expect(ctx.get(UserRepository).hasAdmin()).resolves.toBe(false); + }); }); describe('login', () => {