refactor: e2e client (#7324)
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
import { ActivityCreateDto, ActivityResponseDto } from '@app/domain';
|
||||
import request from 'supertest';
|
||||
|
||||
export const activityApi = {
|
||||
create: async (server: any, accessToken: string, dto: ActivityCreateDto) => {
|
||||
const res = await request(server).post('/activity').set('Authorization', `Bearer ${accessToken}`).send(dto);
|
||||
expect(res.status === 200 || res.status === 201).toBe(true);
|
||||
return res.body as ActivityResponseDto;
|
||||
},
|
||||
delete: async (server: any, accessToken: string, id: string) => {
|
||||
const res = await request(server).delete(`/activity/${id}`).set('Authorization', `Bearer ${accessToken}`);
|
||||
expect(res.status).toEqual(204);
|
||||
},
|
||||
};
|
||||
@@ -1,28 +0,0 @@
|
||||
import { AddUsersDto, AlbumResponseDto, BulkIdResponseDto, BulkIdsDto, CreateAlbumDto } from '@app/domain';
|
||||
import request from 'supertest';
|
||||
|
||||
export const albumApi = {
|
||||
create: async (server: any, accessToken: string, dto: CreateAlbumDto) => {
|
||||
const res = await request(server).post('/album').set('Authorization', `Bearer ${accessToken}`).send(dto);
|
||||
expect(res.status).toEqual(201);
|
||||
return res.body as AlbumResponseDto;
|
||||
},
|
||||
addAssets: async (server: any, accessToken: string, id: string, dto: BulkIdsDto) => {
|
||||
const res = await request(server)
|
||||
.put(`/album/${id}/assets`)
|
||||
.set('Authorization', `Bearer ${accessToken}`)
|
||||
.send(dto);
|
||||
expect(res.status).toEqual(200);
|
||||
return res.body as BulkIdResponseDto[];
|
||||
},
|
||||
addUsers: async (server: any, accessToken: string, id: string, dto: AddUsersDto) => {
|
||||
const res = await request(server).put(`/album/${id}/users`).set('Authorization', `Bearer ${accessToken}`).send(dto);
|
||||
expect(res.status).toEqual(200);
|
||||
return res.body as AlbumResponseDto;
|
||||
},
|
||||
getAllAlbums: async (server: any, accessToken: string) => {
|
||||
const res = await request(server).get(`/album/`).set('Authorization', `Bearer ${accessToken}`).send();
|
||||
expect(res.status).toEqual(200);
|
||||
return res.body as AlbumResponseDto[];
|
||||
},
|
||||
};
|
||||
@@ -1,16 +0,0 @@
|
||||
import { APIKeyCreateResponseDto } from '@app/domain';
|
||||
import { apiKeyCreateStub } from '@test';
|
||||
import request from 'supertest';
|
||||
|
||||
export const apiKeyApi = {
|
||||
createApiKey: async (server: any, accessToken: string) => {
|
||||
const { status, body } = await request(server)
|
||||
.post('/api-key')
|
||||
.set('Authorization', `Bearer ${accessToken}`)
|
||||
.send(apiKeyCreateStub);
|
||||
|
||||
expect(status).toBe(201);
|
||||
|
||||
return body as APIKeyCreateResponseDto;
|
||||
},
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AuthDeviceResponseDto, LoginCredentialDto, LoginResponseDto, UserResponseDto } from '@app/domain';
|
||||
import { LoginCredentialDto, LoginResponseDto, UserResponseDto } from '@app/domain';
|
||||
import { adminSignupStub, loginResponseStub, loginStub } from '@test';
|
||||
import request from 'supertest';
|
||||
|
||||
@@ -27,19 +27,4 @@ export const authApi = {
|
||||
|
||||
return body as LoginResponseDto;
|
||||
},
|
||||
getAuthDevices: async (server: any, accessToken: string) => {
|
||||
const { status, body } = await request(server).get('/auth/devices').set('Authorization', `Bearer ${accessToken}`);
|
||||
|
||||
expect(body).toEqual(expect.any(Array));
|
||||
expect(status).toBe(200);
|
||||
|
||||
return body as AuthDeviceResponseDto[];
|
||||
},
|
||||
validateToken: async (server: any, accessToken: string) => {
|
||||
const { status, body } = await request(server)
|
||||
.post('/auth/validateToken')
|
||||
.set('Authorization', `Bearer ${accessToken}`);
|
||||
expect(body).toEqual({ authStatus: true });
|
||||
expect(status).toBe(200);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,25 +1,15 @@
|
||||
import { activityApi } from './activity-api';
|
||||
import { albumApi } from './album-api';
|
||||
import { apiKeyApi } from './api-key-api';
|
||||
import { assetApi } from './asset-api';
|
||||
import { authApi } from './auth-api';
|
||||
import { libraryApi } from './library-api';
|
||||
import { partnerApi } from './partner-api';
|
||||
import { serverInfoApi } from './server-info-api';
|
||||
import { sharedLinkApi } from './shared-link-api';
|
||||
import { trashApi } from './trash-api';
|
||||
import { userApi } from './user-api';
|
||||
|
||||
export const api = {
|
||||
activityApi,
|
||||
authApi,
|
||||
apiKeyApi,
|
||||
assetApi,
|
||||
libraryApi,
|
||||
serverInfoApi,
|
||||
sharedLinkApi,
|
||||
trashApi,
|
||||
albumApi,
|
||||
userApi,
|
||||
partnerApi,
|
||||
};
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
import { PartnerResponseDto } from '@app/domain';
|
||||
import request from 'supertest';
|
||||
|
||||
export const partnerApi = {
|
||||
create: async (server: any, accessToken: string, id: string) => {
|
||||
const { status, body } = await request(server).post(`/partner/${id}`).set('Authorization', `Bearer ${accessToken}`);
|
||||
expect(status).toBe(201);
|
||||
return body as PartnerResponseDto;
|
||||
},
|
||||
};
|
||||
@@ -1,10 +0,0 @@
|
||||
import { ServerConfigDto } from '@app/domain';
|
||||
import request from 'supertest';
|
||||
|
||||
export const serverInfoApi = {
|
||||
getConfig: async (server: any) => {
|
||||
const res = await request(server).get('/server-info/config');
|
||||
expect(res.status).toBe(200);
|
||||
return res.body as ServerConfigDto;
|
||||
},
|
||||
};
|
||||
@@ -10,11 +10,4 @@ export const sharedLinkApi = {
|
||||
expect(status).toBe(201);
|
||||
return body as SharedLinkResponseDto;
|
||||
},
|
||||
|
||||
getMySharedLink: async (server: any, key: string) => {
|
||||
const { status, body } = await request(server).get('/shared-link/me').query({ key });
|
||||
|
||||
expect(status).toBe(200);
|
||||
return body as SharedLinkResponseDto;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -18,16 +18,6 @@ export const userApi = {
|
||||
|
||||
return body as UserResponseDto;
|
||||
},
|
||||
get: async (server: any, accessToken: string, id: string) => {
|
||||
const { status, body } = await request(server)
|
||||
.get(`/user/info/${id}`)
|
||||
.set('Authorization', `Bearer ${accessToken}`);
|
||||
|
||||
expect(status).toBe(200);
|
||||
expect(body).toMatchObject({ id });
|
||||
|
||||
return body as UserResponseDto;
|
||||
},
|
||||
update: async (server: any, accessToken: string, dto: UpdateUserDto) => {
|
||||
const { status, body } = await request(server).put('/user').set('Authorization', `Bearer ${accessToken}`).send(dto);
|
||||
|
||||
@@ -39,12 +29,4 @@ export const userApi = {
|
||||
setExternalPath: async (server: any, accessToken: string, id: string, externalPath: string) => {
|
||||
return await userApi.update(server, accessToken, { id, externalPath });
|
||||
},
|
||||
delete: async (server: any, accessToken: string, id: string) => {
|
||||
const { status, body } = await request(server).delete(`/user/${id}`).set('Authorization', `Bearer ${accessToken}`);
|
||||
|
||||
expect(status).toBe(200);
|
||||
expect(body).toMatchObject({ id, deletedAt: expect.any(String) });
|
||||
|
||||
return body as UserResponseDto;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user