mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
feat(server): more e2e test cases
This commit is contained in:
116
packages/server/test/users.e2e-spec.ts
Normal file
116
packages/server/test/users.e2e-spec.ts
Normal file
@@ -0,0 +1,116 @@
|
||||
import * as request from 'supertest';
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { app, AuthorizationHeader, orgainzationId } from './init-app-test';
|
||||
|
||||
let userId;
|
||||
|
||||
describe('Users (e2e)', () => {
|
||||
beforeAll(async () => {
|
||||
const usersResponse = await request(app.getHttpServer())
|
||||
.get('/users')
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader);
|
||||
|
||||
if (usersResponse.body.length > 0) {
|
||||
userId = usersResponse.body[0].id;
|
||||
}
|
||||
});
|
||||
|
||||
it('/users (GET)', () => {
|
||||
return request(app.getHttpServer())
|
||||
.get('/users')
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader)
|
||||
.expect(200);
|
||||
});
|
||||
|
||||
it('/users/:id (GET)', async () => {
|
||||
if (!userId) {
|
||||
const usersResponse = await request(app.getHttpServer())
|
||||
.get('/users')
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader);
|
||||
|
||||
if (usersResponse.body.length > 0) {
|
||||
userId = usersResponse.body[0].id;
|
||||
}
|
||||
}
|
||||
|
||||
if (userId) {
|
||||
return request(app.getHttpServer())
|
||||
.get(`/users/${userId}`)
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader)
|
||||
.expect(200);
|
||||
}
|
||||
});
|
||||
|
||||
it('/users/:id (POST)', async () => {
|
||||
if (!userId) {
|
||||
const usersResponse = await request(app.getHttpServer())
|
||||
.get('/users')
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader);
|
||||
|
||||
if (usersResponse.body.length > 0) {
|
||||
userId = usersResponse.body[0].id;
|
||||
}
|
||||
}
|
||||
|
||||
if (userId) {
|
||||
return request(app.getHttpServer())
|
||||
.post(`/users/${userId}`)
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader)
|
||||
.send({
|
||||
firstName: faker.person.firstName(),
|
||||
lastName: faker.person.lastName(),
|
||||
email: faker.internet.email(),
|
||||
roleId: 1,
|
||||
})
|
||||
.expect(200);
|
||||
}
|
||||
});
|
||||
|
||||
it('/users/:id/activate (PUT)', async () => {
|
||||
if (!userId) {
|
||||
const usersResponse = await request(app.getHttpServer())
|
||||
.get('/users')
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader);
|
||||
|
||||
if (usersResponse.body.length > 0) {
|
||||
userId = usersResponse.body[0].id;
|
||||
}
|
||||
}
|
||||
|
||||
if (userId) {
|
||||
return request(app.getHttpServer())
|
||||
.put(`/users/${userId}/activate`)
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader)
|
||||
.expect(200);
|
||||
}
|
||||
});
|
||||
|
||||
it('/users/:id/inactivate (PUT)', async () => {
|
||||
if (!userId) {
|
||||
const usersResponse = await request(app.getHttpServer())
|
||||
.get('/users')
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader);
|
||||
|
||||
if (usersResponse.body.length > 0) {
|
||||
userId = usersResponse.body[0].id;
|
||||
}
|
||||
}
|
||||
|
||||
if (userId) {
|
||||
return request(app.getHttpServer())
|
||||
.put(`/users/${userId}/inactivate`)
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader)
|
||||
.expect(200);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user