mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
refactor(server): api keys (#1339)
* refactor: api keys * refactor: test module * chore: tests * chore: fix provider * refactor: test mock repos
This commit is contained in:
12
server/libs/domain/test/api-key.repository.mock.ts
Normal file
12
server/libs/domain/test/api-key.repository.mock.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { IKeyRepository } from '../src';
|
||||
|
||||
export const newKeyRepositoryMock = (): jest.Mocked<IKeyRepository> => {
|
||||
return {
|
||||
create: jest.fn(),
|
||||
update: jest.fn(),
|
||||
delete: jest.fn(),
|
||||
getKey: jest.fn(),
|
||||
getById: jest.fn(),
|
||||
getByUserId: jest.fn(),
|
||||
};
|
||||
};
|
||||
9
server/libs/domain/test/crypto.repository.mock.ts
Normal file
9
server/libs/domain/test/crypto.repository.mock.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { ICryptoRepository } from '../src';
|
||||
|
||||
export const newCryptoRepositoryMock = (): jest.Mocked<ICryptoRepository> => {
|
||||
return {
|
||||
randomBytes: jest.fn().mockReturnValue(Buffer.from('random-bytes', 'utf8')),
|
||||
compareSync: jest.fn().mockReturnValue(true),
|
||||
hash: jest.fn().mockImplementation((input) => Promise.resolve(`${input} (hashed)`)),
|
||||
};
|
||||
};
|
||||
44
server/libs/domain/test/fixtures.ts
Normal file
44
server/libs/domain/test/fixtures.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { UserEntity } from '@app/infra';
|
||||
import { AuthUserDto } from '../src';
|
||||
|
||||
export const authStub = {
|
||||
admin: Object.freeze<AuthUserDto>({
|
||||
id: 'admin_id',
|
||||
email: 'admin@test.com',
|
||||
isAdmin: true,
|
||||
isPublicUser: false,
|
||||
isAllowUpload: true,
|
||||
}),
|
||||
user1: Object.freeze<AuthUserDto>({
|
||||
id: 'immich_id',
|
||||
email: 'immich@test.com',
|
||||
isAdmin: false,
|
||||
isPublicUser: false,
|
||||
isAllowUpload: true,
|
||||
}),
|
||||
};
|
||||
|
||||
export const entityStub = {
|
||||
admin: Object.freeze<UserEntity>({
|
||||
...authStub.admin,
|
||||
password: 'admin_password',
|
||||
firstName: 'admin_first_name',
|
||||
lastName: 'admin_last_name',
|
||||
oauthId: '',
|
||||
shouldChangePassword: false,
|
||||
profileImagePath: '',
|
||||
createdAt: '2021-01-01',
|
||||
tags: [],
|
||||
}),
|
||||
user1: Object.freeze<UserEntity>({
|
||||
...authStub.user1,
|
||||
password: 'immich_password',
|
||||
firstName: 'immich_first_name',
|
||||
lastName: 'immich_last_name',
|
||||
oauthId: '',
|
||||
shouldChangePassword: false,
|
||||
profileImagePath: '',
|
||||
createdAt: '2021-01-01',
|
||||
tags: [],
|
||||
}),
|
||||
};
|
||||
4
server/libs/domain/test/index.ts
Normal file
4
server/libs/domain/test/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from './api-key.repository.mock';
|
||||
export * from './crypto.repository.mock';
|
||||
export * from './fixtures';
|
||||
export * from './user.repository.mock';
|
||||
15
server/libs/domain/test/user.repository.mock.ts
Normal file
15
server/libs/domain/test/user.repository.mock.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { IUserRepository } from '../src';
|
||||
|
||||
export const newUserRepositoryMock = (): jest.Mocked<IUserRepository> => {
|
||||
return {
|
||||
get: jest.fn(),
|
||||
getAdmin: jest.fn(),
|
||||
getByEmail: jest.fn(),
|
||||
getByOAuthId: jest.fn(),
|
||||
getList: jest.fn(),
|
||||
create: jest.fn(),
|
||||
update: jest.fn(),
|
||||
delete: jest.fn(),
|
||||
restore: jest.fn(),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user