mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
refactor: e2e tests for payments received
This commit is contained in:
107
packages/server-nest/test/payment-received.e2e-spec.ts
Normal file
107
packages/server-nest/test/payment-received.e2e-spec.ts
Normal file
@@ -0,0 +1,107 @@
|
||||
import * as request from 'supertest';
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { app } from './init-app-test';
|
||||
|
||||
const requestPaymentReceivedBody = (invoiceId: number) => ({
|
||||
customerId: 2,
|
||||
paymentDate: '2023-01-01',
|
||||
exchangeRate: 1,
|
||||
referenceNo: faker.string.uuid(),
|
||||
depositAccountId: 1000,
|
||||
paymentReceiveNo: faker.string.uuid(),
|
||||
statement: 'Payment received for invoice',
|
||||
entries: [{ index: 1, invoiceId, paymentAmount: 1 }],
|
||||
branchId: 1,
|
||||
});
|
||||
|
||||
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: 100,
|
||||
rate: 1000,
|
||||
description: 'Item description...',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
let invoice;
|
||||
|
||||
beforeEach(async () => {
|
||||
const response = await request(app.getHttpServer())
|
||||
.post('/sale-invoices')
|
||||
.set('organization-id', '4064541lv40nhca')
|
||||
.send(requestSaleInvoiceBody());
|
||||
|
||||
invoice = response.body;
|
||||
});
|
||||
|
||||
describe('Payment Received (e2e)', () => {
|
||||
it('/payments-received (POST)', () => {
|
||||
return request(app.getHttpServer())
|
||||
.post('/payments-received')
|
||||
.set('organization-id', '4064541lv40nhca')
|
||||
.send(requestPaymentReceivedBody(invoice.id))
|
||||
.expect(201);
|
||||
});
|
||||
|
||||
it('/payments-received/:id (DELETE)', async () => {
|
||||
const response = await request(app.getHttpServer())
|
||||
.post('/payments-received')
|
||||
.set('organization-id', '4064541lv40nhca')
|
||||
.send(requestPaymentReceivedBody(invoice.id));
|
||||
|
||||
const paymentReceivedId = response.body.id;
|
||||
|
||||
return request(app.getHttpServer())
|
||||
.delete(`/payments-received/${paymentReceivedId}`)
|
||||
.set('organization-id', '4064541lv40nhca')
|
||||
.expect(200);
|
||||
});
|
||||
|
||||
it('/payments-received/:id (GET)', async () => {
|
||||
const response = await request(app.getHttpServer())
|
||||
.post('/payments-received')
|
||||
.set('organization-id', '4064541lv40nhca')
|
||||
.send(requestPaymentReceivedBody(invoice.id));
|
||||
|
||||
const paymentReceivedId = response.body.id;
|
||||
|
||||
return request(app.getHttpServer())
|
||||
.get(`/payments-received/${paymentReceivedId}`)
|
||||
.set('organization-id', '4064541lv40nhca')
|
||||
.expect(200);
|
||||
});
|
||||
|
||||
it('/payments-received/:id/invoices (GET)', async () => {
|
||||
const response = await request(app.getHttpServer())
|
||||
.post('/payments-received')
|
||||
.set('organization-id', '4064541lv40nhca')
|
||||
.send(requestPaymentReceivedBody(invoice.id));
|
||||
|
||||
const paymentReceivedId = response.body.id;
|
||||
|
||||
return request(app.getHttpServer())
|
||||
.get(`/payments-received/${paymentReceivedId}/invoices`)
|
||||
.set('organization-id', '4064541lv40nhca')
|
||||
.expect(200);
|
||||
});
|
||||
|
||||
it('/payments-received/state (GET)', () => {
|
||||
return request(app.getHttpServer())
|
||||
.get('/payments-received/state')
|
||||
.set('organization-id', '4064541lv40nhca')
|
||||
.expect(200);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user