refactor(nestjs): organization module e2e

This commit is contained in:
Ahmed Bouhuolia
2025-04-04 20:29:08 +02:00
parent 503d0016ea
commit e47ca98171
6 changed files with 77 additions and 4 deletions

View File

@@ -23,7 +23,6 @@ export class AuthenticationApplication {
/** /**
* Signin and generates JWT token. * Signin and generates JWT token.
* @throws {ServiceError}
* @param {string} email - Email address. * @param {string} email - Email address.
* @param {string} password - Password. * @param {string} password - Password.
*/ */

View File

@@ -80,6 +80,7 @@ export class AuthSignupService {
return { return {
userId: user.id, userId: user.id,
tenantId: user.tenantId, tenantId: user.tenantId,
organizationId: tenant.organizationId,
}; };
} }

View File

@@ -53,7 +53,7 @@ export class OrganizationController {
}); });
} }
@Get() @Get('current')
@ApiOperation({ summary: 'Get current organization' }) @ApiOperation({ summary: 'Get current organization' })
@ApiResponse({ @ApiResponse({
status: 200, status: 200,

View File

@@ -25,7 +25,7 @@ export class OrganizationBuildProcessor extends WorkerHost {
@Process(OrganizationBuildQueueJob) @Process(OrganizationBuildQueueJob)
@UseCls() @UseCls()
async process(job: Job<OrganizationBuildQueueJobPayload>) { async process(job: Job<OrganizationBuildQueueJobPayload>) {
console.log('Processing organization build job:', job.data); console.log('Processing organization build job:', job.id);
this.clsService.set('organizationId', job.data.organizationId); this.clsService.set('organizationId', job.data.organizationId);
this.clsService.set('userId', job.data.userId); this.clsService.set('userId', job.data.userId);

View File

@@ -126,7 +126,6 @@ class GetInvoiceMailTemplateItemAttrsTransformer extends Transformer {
} }
public label(entry): string { public label(entry): string {
console.log(entry);
return entry?.item?.name; return entry?.item?.name;
} }

View File

@@ -0,0 +1,74 @@
import * as request from 'supertest';
import { faker } from '@faker-js/faker';
import { app } from './init-app-test';
let signinResponse = null;
let signupResponse = null;
describe('Organization (e2e)', () => {
beforeAll(async () => {
const signupBody = {
firstName: faker.person.firstName(),
lastName: faker.person.lastName(),
email: faker.internet.email(),
password: '123123123',
};
signupResponse = await request(app.getHttpServer())
.post('/auth/signup')
.send(signupBody);
signinResponse = await request(app.getHttpServer())
.post('/auth/signin')
.send({
email: signupBody.email,
password: signupBody.password,
});
});
it('/organization (POST)', async () => {
return request(app.getHttpServer())
.post('/organization/build')
.set('Accept', 'application/json')
.set('Content-Type', 'application/json')
.set('Authorization', `Bearer ${signinResponse.body.access_token}`)
.set('organization-id', signupResponse.body.organization_id)
.send({
name: 'BIGCAPITAL, INC',
baseCurrency: 'USD',
location: 'US',
language: 'en',
fiscalYear: 'march',
timezone: 'US/Central',
})
.expect(200);
});
it('/organization (GET)', () => {
return request(app.getHttpServer())
.get('/organization/current')
.set('Accept', 'application/json')
.set('Content-Type', 'application/json')
.set('Authorization', `Bearer ${signinResponse.body.access_token}`)
.set('organization-id', signupResponse.body.organization_id)
.send()
.expect(200);
});
it('/organization (PUT)', () => {
return request(app.getHttpServer())
.put('/organization')
.set('Accept', 'application/json')
.set('Content-Type', 'application/json')
.set('Authorization', `Bearer ${signinResponse.body.access_token}`)
.set('organization-id', signupResponse.body.organization_id)
.send({
name: 'BIGCAPITAL, INC',
baseCurrency: 'USD',
location: 'US',
language: 'en',
fiscalYear: 'march',
timezone: 'US/Central',
})
.expect(200);
});
});