Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martabal committed Apr 24, 2024
1 parent cf18d2a commit f5c02f2
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 24 deletions.
5 changes: 3 additions & 2 deletions e2e/src/api/specs/user.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ describe('/user', () => {
});

it('should get users', async () => {
const { status, body } = await request(app).get('/user').set('Authorization', `Bearer ${admin.accessToken}`);
const { status, body } = await request(app)
.get('/user/admin')
.set('Authorization', `Bearer ${admin.accessToken}`);
expect(status).toEqual(200);
expect(body).toHaveLength(5);
expect(body).toEqual(
Expand Down Expand Up @@ -288,7 +290,6 @@ describe('/user', () => {
expect(status).toBe(200);
expect(body).toEqual({

Check failure on line 291 in e2e/src/api/specs/user.e2e-spec.ts

View workflow job for this annotation

GitHub Actions / End-to-End Tests

src/api/specs/user.e2e-spec.ts > /user > PUT /user > should update first and last name

AssertionError: expected { …(16) } to deeply equal { …(16) } - Expected + Received Object { "avatarColor": "orange", "createdAt": "2024-04-24T18:29:18.677Z", "deletedAt": null, "email": "admin@immich.cloud", "id": "a6f1afc4-44bd-4980-ab33-26a8508e4d87", "isAdmin": true, "memoriesEnabled": true, "name": "Name", "oauthId": "", "profileImagePath": "", "quotaSizeInBytes": null, "quotaUsageInBytes": 0, "shouldChangePassword": true, "status": "active", "storageLabel": "admin", - "updatedAt": "2024-04-24T18:29:18.677Z", + "updatedAt": "2024-04-24T18:29:19.434Z", } ❯ src/api/specs/user.e2e-spec.ts:291:20
...before,
updatedAt: expect.any(String),
name: 'Name',
});
expect(before.updatedAt).not.toEqual(body.updatedAt);
Expand Down
3 changes: 2 additions & 1 deletion mobile/openapi/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 59 additions & 3 deletions mobile/openapi/doc/UserApi.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 51 additions & 3 deletions mobile/openapi/lib/api/user_api.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion mobile/openapi/test/user_api_test.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 43 additions & 1 deletion open-api/immich-openapi-specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -6844,7 +6844,7 @@
]
}
},
"/user/info/{id}": {
"/user/admin/info/{id}": {
"get": {
"operationId": "getUserById",
"parameters": [
Expand All @@ -6858,6 +6858,48 @@
}
}
],
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UserResponseDto"
}
}
},
"description": ""
}
},
"security": [
{
"bearer": []
},
{
"cookie": []
},
{
"api_key": []
}
],
"tags": [
"User"
]
}
},
"/user/info/{id}": {
"get": {
"operationId": "getPublicUserById",
"parameters": [
{
"name": "id",
"required": true,
"in": "path",
"schema": {
"format": "uuid",
"type": "string"
}
}
],
"responses": {
"200": {
"content": {
Expand Down
10 changes: 10 additions & 0 deletions open-api/typescript-sdk/src/fetch-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2832,6 +2832,16 @@ export function getAllUsers({ isAll }: {
}
export function getUserById({ id }: {
id: string;
}, opts?: Oazapfts.RequestOpts) {
return oazapfts.ok(oazapfts.fetchJson<{
status: 200;
data: UserResponseDto;
}>(`/user/admin/info/${encodeURIComponent(id)}`, {
...opts
}));
}
export function getPublicUserById({ id }: {
id: string;
}, opts?: Oazapfts.RequestOpts) {
return oazapfts.ok(oazapfts.fetchJson<{
status: 200;
Expand Down
16 changes: 11 additions & 5 deletions server/src/controllers/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,24 @@ export class UserController {
constructor(private service: UserService) {}

@Get()
getAllPublicUsers(@Auth() auth: AuthDto): Promise<UserDto[]> {
return this.service.getAllPublic(auth);
getAllPublicUsers(): Promise<UserDto[]> {
return this.service.getAllPublic();
}

@AdminRoute()
@Get('admin')
getAllUsers(@Auth() auth: AuthDto, @Query('isAll') isAll: boolean): Promise<UserResponseDto[]> {
return this.service.getAll(auth, isAll);
getAllUsers(@Query('isAll') isAll: boolean): Promise<UserResponseDto[]> {
return this.service.getAll(isAll);
}

@Get('info/:id')
getUserById(@Param() { id }: UUIDParamDto): Promise<UserDto> {
getPublicUserById(@Param() { id }: UUIDParamDto): Promise<UserDto> {
return this.service.getPublic(id);
}

@AdminRoute()
@Get('admin/info/:id')
getUserById(@Param() { id }: UUIDParamDto): Promise<UserResponseDto> {
return this.service.get(id);
}

Expand Down
13 changes: 11 additions & 2 deletions server/src/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,25 @@ export class UserService {
return users.map((user) => mapUser(user));
}

async getAll(auth: AuthDto, isAll: boolean): Promise<UserResponseDto[]> {
async getAll(isAll: boolean): Promise<UserResponseDto[]> {
const users = await this.userRepository.getList({ withDeleted: !isAll });
return users.map((user) => mapUser(user));
}

async getAllPublic(auth: AuthDto): Promise<UserDto[] | UserResponseDto[]> {
async getAllPublic(): Promise<UserDto[] | UserResponseDto[]> {
const users = await this.userRepository.getList({ withDeleted: false });
return users.map((user) => mapSimpleUser(user));
}

async getPublic(userId: string): Promise<UserDto> {
const user = await this.userRepository.get(userId, { withDeleted: false });
if (!user) {
throw new NotFoundException('User not found');
}

return mapSimpleUser(user);
}

async get(userId: string): Promise<UserResponseDto> {
const user = await this.userRepository.get(userId, { withDeleted: false });
if (!user) {
Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/(user)/partners/[userId]/+page.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { authenticate } from '$lib/utils/auth';
import { getUserById } from '@immich/sdk';
import { getPublicUserById } from '@immich/sdk';
import type { PageLoad } from './$types';

export const load = (async ({ params }) => {
await authenticate();

const partner = await getUserById({ id: params.userId });
const partner = await getPublicUserById({ id: params.userId });

return {
partner,
Expand Down
8 changes: 4 additions & 4 deletions web/src/routes/admin/library-management/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
deleteLibrary,
getAllLibraries,
getLibraryStatistics,
getUserById,
LibraryType,
removeOfflineFiles,
scanLibrary,
updateLibrary,
type LibraryResponseDto,
type LibraryStatsResponseDto,
type UserResponseDto,
type UserDto,
getPublicUserById,
} from '@immich/sdk';
import { mdiDatabase, mdiDotsVertical, mdiPlusBoxOutline, mdiSync, mdiUpload } from '@mdi/js';
import { onMount } from 'svelte';
Expand All @@ -43,7 +43,7 @@
let libraries: LibraryResponseDto[] = [];
let stats: LibraryStatsResponseDto[] = [];
let owner: UserResponseDto[] = [];
let owner: UserDto[] = [];
let photos: number[] = [];
let videos: number[] = [];
let totalCount: number[] = [];
Expand Down Expand Up @@ -99,7 +99,7 @@
const refreshStats = async (listIndex: number) => {
stats[listIndex] = await getLibraryStatistics({ id: libraries[listIndex].id });
owner[listIndex] = await getUserById({ id: libraries[listIndex].ownerId });
owner[listIndex] = await getPublicUserById({ id: libraries[listIndex].ownerId });
photos[listIndex] = stats[listIndex].photos;
videos[listIndex] = stats[listIndex].videos;
totalCount[listIndex] = stats[listIndex].total;
Expand Down

0 comments on commit f5c02f2

Please sign in to comment.