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 e79ee7d
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 27 deletions.
6 changes: 4 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 @@ -75,7 +77,7 @@ describe('/user', () => {

it('should include deleted users', async () => {
const { status, body } = await request(app)
.get(`/user`)
.get(`/user/admin`)
.query({ isAll: false })
.set('Authorization', `Bearer ${admin.accessToken}`);

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
2 changes: 1 addition & 1 deletion server/src/services/user.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe(UserService.name, () => {
describe('getAll', () => {
it('should get all users', async () => {
userMock.getList.mockResolvedValue([userStub.admin]);
await expect(sut.getAll(authStub.admin, false)).resolves.toEqual([
await expect(sut.getAll(false)).resolves.toEqual([
expect.objectContaining({
id: authStub.admin.user.id,
email: authStub.admin.user.email,
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 e79ee7d

Please sign in to comment.