mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
refactor(server): narrow auth types (#16066)
This commit is contained in:
parent
7c821dd205
commit
2d7c333c8c
25 changed files with 265 additions and 239 deletions
66
server/test/fixtures/auth.stub.ts
vendored
66
server/test/fixtures/auth.stub.ts
vendored
|
|
@ -1,25 +1,30 @@
|
|||
import { AuthDto } from 'src/dtos/auth.dto';
|
||||
import { SessionEntity } from 'src/entities/session.entity';
|
||||
import { SharedLinkEntity } from 'src/entities/shared-link.entity';
|
||||
import { UserMetadataEntity } from 'src/entities/user-metadata.entity';
|
||||
import { UserEntity } from 'src/entities/user.entity';
|
||||
|
||||
const authUser = {
|
||||
admin: {
|
||||
id: 'admin_id',
|
||||
name: 'admin',
|
||||
email: 'admin@test.com',
|
||||
isAdmin: true,
|
||||
quotaSizeInBytes: null,
|
||||
quotaUsageInBytes: 0,
|
||||
},
|
||||
user1: {
|
||||
id: 'user-id',
|
||||
name: 'User 1',
|
||||
email: 'immich@test.com',
|
||||
isAdmin: false,
|
||||
quotaSizeInBytes: null,
|
||||
quotaUsageInBytes: 0,
|
||||
},
|
||||
};
|
||||
|
||||
export const authStub = {
|
||||
admin: Object.freeze<AuthDto>({
|
||||
user: {
|
||||
id: 'admin_id',
|
||||
email: 'admin@test.com',
|
||||
isAdmin: true,
|
||||
metadata: [] as UserMetadataEntity[],
|
||||
} as UserEntity,
|
||||
}),
|
||||
admin: Object.freeze<AuthDto>({ user: authUser.admin }),
|
||||
user1: Object.freeze<AuthDto>({
|
||||
user: {
|
||||
id: 'user-id',
|
||||
email: 'immich@test.com',
|
||||
isAdmin: false,
|
||||
metadata: [] as UserMetadataEntity[],
|
||||
} as UserEntity,
|
||||
user: authUser.user1,
|
||||
session: {
|
||||
id: 'token-id',
|
||||
} as SessionEntity,
|
||||
|
|
@ -27,21 +32,18 @@ export const authStub = {
|
|||
user2: Object.freeze<AuthDto>({
|
||||
user: {
|
||||
id: 'user-2',
|
||||
email: 'user2@immich.app',
|
||||
name: 'User 2',
|
||||
email: 'user2@immich.cloud',
|
||||
isAdmin: false,
|
||||
metadata: [] as UserMetadataEntity[],
|
||||
} as UserEntity,
|
||||
quotaSizeInBytes: null,
|
||||
quotaUsageInBytes: 0,
|
||||
},
|
||||
session: {
|
||||
id: 'token-id',
|
||||
} as SessionEntity,
|
||||
}),
|
||||
adminSharedLink: Object.freeze<AuthDto>({
|
||||
user: {
|
||||
id: 'admin_id',
|
||||
email: 'admin@test.com',
|
||||
isAdmin: true,
|
||||
metadata: [] as UserMetadataEntity[],
|
||||
} as UserEntity,
|
||||
user: authUser.admin,
|
||||
sharedLink: {
|
||||
id: '123',
|
||||
showExif: true,
|
||||
|
|
@ -51,12 +53,7 @@ export const authStub = {
|
|||
} as SharedLinkEntity,
|
||||
}),
|
||||
adminSharedLinkNoExif: Object.freeze<AuthDto>({
|
||||
user: {
|
||||
id: 'admin_id',
|
||||
email: 'admin@test.com',
|
||||
isAdmin: true,
|
||||
metadata: [] as UserMetadataEntity[],
|
||||
} as UserEntity,
|
||||
user: authUser.admin,
|
||||
sharedLink: {
|
||||
id: '123',
|
||||
showExif: false,
|
||||
|
|
@ -66,12 +63,7 @@ export const authStub = {
|
|||
} as SharedLinkEntity,
|
||||
}),
|
||||
passwordSharedLink: Object.freeze<AuthDto>({
|
||||
user: {
|
||||
id: 'admin_id',
|
||||
email: 'admin@test.com',
|
||||
isAdmin: true,
|
||||
metadata: [] as UserMetadataEntity[],
|
||||
} as UserEntity,
|
||||
user: authUser.admin,
|
||||
sharedLink: {
|
||||
id: '123',
|
||||
allowUpload: false,
|
||||
|
|
|
|||
16
server/test/fixtures/user.stub.ts
vendored
16
server/test/fixtures/user.stub.ts
vendored
|
|
@ -1,10 +1,12 @@
|
|||
import { UserEntity } from 'src/entities/user.entity';
|
||||
import { UserAvatarColor, UserMetadataKey } from 'src/enum';
|
||||
import { UserAvatarColor, UserMetadataKey, UserStatus } from 'src/enum';
|
||||
import { authStub } from 'test/fixtures/auth.stub';
|
||||
|
||||
export const userStub = {
|
||||
admin: Object.freeze<UserEntity>({
|
||||
...authStub.admin.user,
|
||||
status: UserStatus.ACTIVE,
|
||||
profileChangedAt: new Date('2021-01-01'),
|
||||
password: 'admin_password',
|
||||
name: 'admin_name',
|
||||
id: 'admin_id',
|
||||
|
|
@ -23,6 +25,8 @@ export const userStub = {
|
|||
}),
|
||||
user1: Object.freeze<UserEntity>({
|
||||
...authStub.user1.user,
|
||||
status: UserStatus.ACTIVE,
|
||||
profileChangedAt: new Date('2021-01-01'),
|
||||
password: 'immich_password',
|
||||
name: 'immich_name',
|
||||
storageLabel: null,
|
||||
|
|
@ -36,7 +40,6 @@ export const userStub = {
|
|||
assets: [],
|
||||
metadata: [
|
||||
{
|
||||
user: authStub.user1.user,
|
||||
userId: authStub.user1.user.id,
|
||||
key: UserMetadataKey.PREFERENCES,
|
||||
value: { avatar: { color: UserAvatarColor.PRIMARY } },
|
||||
|
|
@ -47,6 +50,9 @@ export const userStub = {
|
|||
}),
|
||||
user2: Object.freeze<UserEntity>({
|
||||
...authStub.user2.user,
|
||||
status: UserStatus.ACTIVE,
|
||||
profileChangedAt: new Date('2021-01-01'),
|
||||
metadata: [],
|
||||
password: 'immich_password',
|
||||
name: 'immich_name',
|
||||
storageLabel: null,
|
||||
|
|
@ -63,6 +69,9 @@ export const userStub = {
|
|||
}),
|
||||
storageLabel: Object.freeze<UserEntity>({
|
||||
...authStub.user1.user,
|
||||
status: UserStatus.ACTIVE,
|
||||
profileChangedAt: new Date('2021-01-01'),
|
||||
metadata: [],
|
||||
password: 'immich_password',
|
||||
name: 'immich_name',
|
||||
storageLabel: 'label-1',
|
||||
|
|
@ -79,6 +88,9 @@ export const userStub = {
|
|||
}),
|
||||
profilePath: Object.freeze<UserEntity>({
|
||||
...authStub.user1.user,
|
||||
status: UserStatus.ACTIVE,
|
||||
profileChangedAt: new Date('2021-01-01'),
|
||||
metadata: [],
|
||||
password: 'immich_password',
|
||||
name: 'immich_name',
|
||||
storageLabel: 'label-1',
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { Mocked, vitest } from 'vitest';
|
|||
export const newUserRepositoryMock = (): Mocked<RepositoryInterface<UserRepository>> => {
|
||||
return {
|
||||
get: vitest.fn(),
|
||||
getMetadata: vitest.fn().mockResolvedValue([]),
|
||||
getAdmin: vitest.fn(),
|
||||
getByEmail: vitest.fn(),
|
||||
getByStorageLabel: vitest.fn(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue