From 31910767625dd0b99e38cc6b360cba7e7211bdff Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Mon, 30 Dec 2024 20:59:19 +0200 Subject: [PATCH] refactor: e2e tests for payments received --- .../test/payment-received.e2e-spec.ts | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 packages/server-nest/test/payment-received.e2e-spec.ts diff --git a/packages/server-nest/test/payment-received.e2e-spec.ts b/packages/server-nest/test/payment-received.e2e-spec.ts new file mode 100644 index 000000000..6934f8271 --- /dev/null +++ b/packages/server-nest/test/payment-received.e2e-spec.ts @@ -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); + }); +});