mirror of
https://github.com/immich-app/immich
synced 2026-08-29 13:15:45 +00:00
chore: update tests due to refactors
This commit is contained in:
parent
f5199e179f
commit
b979bbb06d
3 changed files with 5 additions and 16 deletions
|
|
@ -20,7 +20,7 @@ export class MaintenanceController {
|
|||
@Post('start')
|
||||
@Authenticated({ permission: Permission.Maintenance, admin: true })
|
||||
async startMaintenance(@Auth() auth: AuthDto, @Res({ passthrough: true }) response: Response): Promise<void> {
|
||||
const { jwt } = await this.service.startMaintenance(auth);
|
||||
const { jwt } = await this.service.startMaintenance(auth.user.name);
|
||||
response.cookie(ImmichCookie.MaintenanceToken, jwt);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,13 +57,13 @@ describe(MaintenanceService.name, () => {
|
|||
describe('startMaintenance', () => {
|
||||
it('should fail if in maintenance mode', async () => {
|
||||
mocks.systemMetadata.get.mockResolvedValue({ isMaintenanceMode: true, secret: '' });
|
||||
await expect(sut.startMaintenance()).rejects.toThrowError(BadRequestException);
|
||||
await expect(sut.startMaintenance('admin')).rejects.toThrowError(BadRequestException);
|
||||
});
|
||||
|
||||
it('should set maintenance mode and return a secret', async () => {
|
||||
mocks.systemMetadata.get.mockResolvedValue({ isMaintenanceMode: false });
|
||||
|
||||
await expect(sut.startMaintenance()).resolves.toMatchObject({
|
||||
await expect(sut.startMaintenance('admin')).resolves.toMatchObject({
|
||||
secret: expect.stringMatching(/^\w{128}$/),
|
||||
});
|
||||
|
||||
|
|
@ -124,14 +124,4 @@ describe(MaintenanceService.name, () => {
|
|||
expect(mocks.systemMetadata.get).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('createJwt', () => {
|
||||
it('should generate a JWT', async () => {
|
||||
await expect(
|
||||
sut.createJwt('secret', {
|
||||
username: '',
|
||||
}),
|
||||
).resolves.toEqual(expect.stringMatching(/^[A-Za-z0-9-_]*\.[A-Za-z0-9-_]*\.[A-Za-z0-9-_]*$/));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from 'src/decorators';
|
||||
import { AuthDto } from 'src/dtos/auth.dto';
|
||||
import { MaintenanceAuthDto } from 'src/dtos/maintenance.dto';
|
||||
import { SystemMetadataKey } from 'src/enum';
|
||||
import { BaseService } from 'src/services/base.service';
|
||||
|
|
@ -23,7 +22,7 @@ export class MaintenanceService extends BaseService {
|
|||
throw new BadRequestException('Not in maintenance mode');
|
||||
}
|
||||
|
||||
async startMaintenance(auth: AuthDto): Promise<{ jwt: string }> {
|
||||
async startMaintenance(username: string): Promise<{ jwt: string }> {
|
||||
const { isMaintenanceMode } = await this.getMaintenanceMode();
|
||||
if (isMaintenanceMode) {
|
||||
throw new BadRequestException('Already in maintenance mode');
|
||||
|
|
@ -35,7 +34,7 @@ export class MaintenanceService extends BaseService {
|
|||
|
||||
return {
|
||||
jwt: await signMaintenanceJwt(secret, {
|
||||
username: auth.user.name,
|
||||
username,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue