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 be49280
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 26 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:35:58.357Z", "deletedAt": null, "email": "admin@immich.cloud", "id": "e3705569-f826-4264-812e-59d2f999b2d5", "isAdmin": true, "memoriesEnabled": true, "name": "Name", "oauthId": "", "profileImagePath": "", "quotaSizeInBytes": null, "quotaUsageInBytes": 0, "shouldChangePassword": true, "status": "active", "storageLabel": "admin", - "updatedAt": "2024-04-24T18:35:58.357Z", + "updatedAt": "2024-04-24T18:35:59.088Z", } ❯ 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 server/test/fixtures/shared-link.stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AlbumResponseDto } from 'src/dtos/album.dto';
import { AssetResponseDto } from 'src/dtos/asset-response.dto';
import { ExifResponseDto } from 'src/dtos/exif.dto';
import { SharedLinkResponseDto } from 'src/dtos/shared-link.dto';
import { mapUser } from 'src/dtos/user.dto';
import { mapSimpleUser } from 'src/dtos/user.dto';
import { AssetOrder } from 'src/entities/album.entity';
import { AssetType } from 'src/entities/asset.entity';
import { SharedLinkEntity, SharedLinkType } from 'src/entities/shared-link.entity';
Expand Down Expand Up @@ -101,7 +101,7 @@ const albumResponse: AlbumResponseDto = {
updatedAt: today,
id: 'album-123',
ownerId: 'admin_id',
owner: mapUser(userStub.admin),
owner: mapSimpleUser(userStub.admin),
sharedUsers: [],
shared: false,
hasSharedLink: false,
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

0 comments on commit be49280

Please sign in to comment.