refactor: migrate to Nestjs

This commit is contained in:
Ahmed Bouhuolia
2024-12-30 15:54:53 +02:00
parent 77bbf6828d
commit 515a984714
23 changed files with 557 additions and 175 deletions

View File

@@ -0,0 +1,71 @@
import * as request from 'supertest';
import { app } from './init-app-test';
const requestCreditNote = () => ({
customerId: 2,
creditNoteDate: '2020-02-02',
branchId: 1,
warehouseId: 1,
entries: [
{
index: 1,
itemId: 1000,
quantity: 1,
rate: 1000,
description: "It's description here.",
},
],
discount: '100',
discountType: 'amount',
});
describe('Credit Notes (e2e)', () => {
it('/credit-notes (POST)', () => {
return request(app.getHttpServer())
.post('/credit-notes')
.set('organization-id', '4064541lv40nhca')
.send(requestCreditNote())
.expect(201);
});
it('/credit-notes/:id (DELETE)', async () => {
const response = await request(app.getHttpServer())
.post('/credit-notes')
.set('organization-id', '4064541lv40nhca')
.send(requestCreditNote());
const creditNoteId = response.body.id;
return request(app.getHttpServer())
.delete(`/credit-notes/${creditNoteId}`)
.set('organization-id', '4064541lv40nhca')
.expect(200);
});
it('/credit-notes/:id (PUT)', async () => {
const creditNote = requestCreditNote();
const response = await request(app.getHttpServer())
.post('/credit-notes')
.set('organization-id', '4064541lv40nhca')
.send(creditNote);
const creditNoteId = response.body.id;
return request(app.getHttpServer())
.put(`/credit-notes/${creditNoteId}`)
.set('organization-id', '4064541lv40nhca')
.send(creditNote)
.expect(200);
});
it('/credit-notes/:id/open (POST)', async () => {
const response = await request(app.getHttpServer())
.post('/credit-notes')
.set('organization-id', '4064541lv40nhca')
.send(requestCreditNote());
const creditNoteId = response.body.id;
return request(app.getHttpServer())
.put(`/credit-notes/${creditNoteId}/open`)
.set('organization-id', '4064541lv40nhca')
.expect(200);
});
});

View File

@@ -2,32 +2,148 @@ import * as request from 'supertest';
import { faker } from '@faker-js/faker';
import { app } from './init-app-test';
const requestSaleInvoiceBody = () => ({
customerId: 2,
invoiceDate: '2023-01-01',
dueDate: '2023-02-01',
invoiceNo: faker.string.uuid(),
referenceNo: 'REF-000201',
delivered: true,
discountType: 'percentage',
discount: 10,
branchId: 1,
warehouseId: 1,
entries: [
{
index: 1,
itemId: 1001,
quantity: 2,
rate: 1000,
description: 'Item description...',
},
],
});
describe('Sale Invoices (e2e)', () => {
it('/sale-invoices (POST)', () => {
return request(app.getHttpServer())
.post('/sale-invoices')
.set('organization-id', '4064541lv40nhca')
.send({
customerId: 2,
invoiceDate: '2023-01-01',
dueDate: '2023-02-01',
invoiceNo: 'INV-002005',
referenceNo: 'REF-000201',
delivered: true,
discountType: 'percentage',
discount: 10,
branchId: 1,
warehouseId: 1,
entries: [
{
index: 1,
itemId: 1001,
quantity: 2,
rate: 1000,
description: 'Item description...',
},
],
})
.send(requestSaleInvoiceBody())
.expect(201);
});
it('/sale-invoices/:id (DELETE)', async () => {
const response = await request(app.getHttpServer())
.post('/sale-invoices')
.set('organization-id', '4064541lv40nhca')
.send(requestSaleInvoiceBody());
return request(app.getHttpServer())
.delete(`/sale-invoices/${response.body.id}`)
.set('organization-id', '4064541lv40nhca')
.expect(200);
});
it('/sale-invoices/:id (PUT)', async () => {
const response = await request(app.getHttpServer())
.post('/sale-invoices')
.set('organization-id', '4064541lv40nhca')
.send(requestSaleInvoiceBody());
return request(app.getHttpServer())
.put(`/sale-invoices/${response.body.id}`)
.set('organization-id', '4064541lv40nhca')
.send(requestSaleInvoiceBody())
.expect(200);
});
it('/sale-invoices/:id (GET)', async () => {
const response = await request(app.getHttpServer())
.post('/sale-invoices')
.set('organization-id', '4064541lv40nhca')
.send(requestSaleInvoiceBody());
return request(app.getHttpServer())
.get(`/sale-invoices/${response.body.id}`)
.set('organization-id', '4064541lv40nhca')
.expect(200);
});
it('/sale-invoices/:id/state (GET)', async () => {
const response = await request(app.getHttpServer())
.post('/sale-invoices')
.set('organization-id', '4064541lv40nhca')
.send(requestSaleInvoiceBody());
return request(app.getHttpServer())
.get(`/sale-invoices/${response.body.id}/state`)
.set('organization-id', '4064541lv40nhca')
.expect(200);
});
it('/sale-invoices/:id/payments (GET)', async () => {
const response = await request(app.getHttpServer())
.post('/sale-invoices')
.set('organization-id', '4064541lv40nhca')
.send(requestSaleInvoiceBody());
return request(app.getHttpServer())
.get(`/sale-invoices/${response.body.id}/payments`)
.set('organization-id', '4064541lv40nhca')
.expect(200);
});
it('/sale-invoices/:id/writeoff (POST)', async () => {
const response = await request(app.getHttpServer())
.post('/sale-invoices')
.set('organization-id', '4064541lv40nhca')
.send(requestSaleInvoiceBody());
return request(app.getHttpServer())
.post(`/sale-invoices/${response.body.id}/writeoff`)
.set('organization-id', '4064541lv40nhca')
.send({
expenseAccountId: 1024,
date: '2023-01-01',
reason: 'Write off reason',
})
.expect(200);
});
it('/sale-invoices/:id/cancel-writeoff (POST)', async () => {
const response = await request(app.getHttpServer())
.post('/sale-invoices')
.set('organization-id', '4064541lv40nhca')
.send(requestSaleInvoiceBody());
await request(app.getHttpServer())
.post(`/sale-invoices/${response.body.id}/writeoff`)
.set('organization-id', '4064541lv40nhca')
.send({
expenseAccountId: 1024,
date: '2023-01-01',
reason: 'Write off reason',
});
return request(app.getHttpServer())
.post(`/sale-invoices/${response.body.id}/cancel-writeoff`)
.set('organization-id', '4064541lv40nhca')
.expect(200);
});
it('/sale-invoices/:id/deliver (PUT)', async () => {
const response = await request(app.getHttpServer())
.post('/sale-invoices')
.set('organization-id', '4064541lv40nhca')
.send({
...requestSaleInvoiceBody(),
delivered: false,
});
return request(app.getHttpServer())
.post(`/sale-invoices/${response.body.id}/deliver`)
.set('organization-id', '4064541lv40nhca')
.expect(200);
});
});

View File

@@ -0,0 +1,73 @@
import * as request from 'supertest';
import { app } from './init-app-test';
import { faker } from '@faker-js/faker';
const requestVendorCredit = () => ({
vendorId: 3,
exchangeRate: 1,
vendorCreditNumber: faker.string.uuid(),
vendorCreditDate: '2025-01-01',
entries: [
{
index: 1,
item_id: 1000,
quantity: 1,
rate: 1000,
description: "It's description here.",
},
],
branchId: 1,
warehouseId: 1,
});
describe('Vendor Credits (e2e)', () => {
it('/vendor-credits (POST)', () => {
return request(app.getHttpServer())
.post('/vendor-credits')
.set('organization-id', '4064541lv40nhca')
.send(requestVendorCredit())
.expect(201);
});
it('/vendor-credits/:id (DELETE)', async () => {
const response = await request(app.getHttpServer())
.post('/vendor-credits')
.set('organization-id', '4064541lv40nhca')
.send(requestVendorCredit());
const vendorCreditId = response.body.id;
return request(app.getHttpServer())
.delete(`/vendor-credits/${vendorCreditId}`)
.set('organization-id', '4064541lv40nhca')
.expect(200);
});
it('/vendor-credits/:id/open (POST)', async () => {
const response = await request(app.getHttpServer())
.post('/vendor-credits')
.set('organization-id', '4064541lv40nhca')
.send(requestVendorCredit());
const vendorCreditId = response.body.id;
return request(app.getHttpServer())
.put(`/vendor-credits/${vendorCreditId}/open`)
.set('organization-id', '4064541lv40nhca')
.expect(200);
});
it('/vendor-credits/:id (GET)', async () => {
const response = await request(app.getHttpServer())
.post('/vendor-credits')
.set('organization-id', '4064541lv40nhca')
.send(requestVendorCredit());
const vendorCreditId = response.body.id;
return request(app.getHttpServer())
.get(`/vendor-credits/${vendorCreditId}`)
.set('organization-id', '4064541lv40nhca')
.expect(200);
});
});