diff --git a/packages/server/test/accounts.e2e-spec.ts b/packages/server/test/accounts.e2e-spec.ts new file mode 100644 index 000000000..8c71dea77 --- /dev/null +++ b/packages/server/test/accounts.e2e-spec.ts @@ -0,0 +1,175 @@ +import * as request from 'supertest'; +import { faker } from '@faker-js/faker'; +import { + app, + AuthorizationHeader, + orgainzationId, +} from './init-app-test'; + +const makeAccountRequest = () => ({ + name: faker.finance.accountName(), + accountType: 'asset', + code: faker.string.alphanumeric({ length: 6 }).toUpperCase(), +}); + +describe('Accounts (e2e)', () => { + it('/accounts (POST)', () => { + return request(app.getHttpServer()) + .post('/accounts') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(makeAccountRequest()) + .expect(201); + }); + + it('/accounts (GET)', () => { + return request(app.getHttpServer()) + .get('/accounts') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/accounts/:id (GET)', async () => { + const response = await request(app.getHttpServer()) + .post('/accounts') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(makeAccountRequest()); + const accountId = response.body.id; + + return request(app.getHttpServer()) + .get(`/accounts/${accountId}`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/accounts/:id (PUT)', async () => { + const response = await request(app.getHttpServer()) + .post('/accounts') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(makeAccountRequest()); + const accountId = response.body.id; + + return request(app.getHttpServer()) + .put(`/accounts/${accountId}`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ + name: faker.finance.accountName(), + accountType: 'asset', + }) + .expect(200); + }); + + it('/accounts/:id (DELETE)', async () => { + const response = await request(app.getHttpServer()) + .post('/accounts') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(makeAccountRequest()); + const accountId = response.body.id; + + return request(app.getHttpServer()) + .delete(`/accounts/${accountId}`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/accounts/:id/activate (POST)', async () => { + const response = await request(app.getHttpServer()) + .post('/accounts') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ + ...makeAccountRequest(), + active: false, + }); + const accountId = response.body.id; + + return request(app.getHttpServer()) + .post(`/accounts/${accountId}/activate`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/accounts/:id/inactivate (POST)', async () => { + const response = await request(app.getHttpServer()) + .post('/accounts') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ + ...makeAccountRequest(), + active: true, + }); + const accountId = response.body.id; + + return request(app.getHttpServer()) + .post(`/accounts/${accountId}/inactivate`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/accounts/types (GET)', () => { + return request(app.getHttpServer()) + .get('/accounts/types') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/accounts/validate-bulk-delete (POST)', async () => { + const response1 = await request(app.getHttpServer()) + .post('/accounts') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(makeAccountRequest()); + const accountId1 = response1.body.id; + + const response2 = await request(app.getHttpServer()) + .post('/accounts') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(makeAccountRequest()); + const accountId2 = response2.body.id; + + return request(app.getHttpServer()) + .post('/accounts/validate-bulk-delete') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ + ids: [accountId1, accountId2], + }) + .expect(200); + }); + + it('/accounts/bulk-delete (POST)', async () => { + const response1 = await request(app.getHttpServer()) + .post('/accounts') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(makeAccountRequest()); + const accountId1 = response1.body.id; + + const response2 = await request(app.getHttpServer()) + .post('/accounts') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(makeAccountRequest()); + const accountId2 = response2.body.id; + + return request(app.getHttpServer()) + .post('/accounts/bulk-delete') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ + ids: [accountId1, accountId2], + }) + .expect(200); + }); +}); diff --git a/packages/server/test/api-keys.e2e-spec.ts b/packages/server/test/api-keys.e2e-spec.ts new file mode 100644 index 000000000..606f35902 --- /dev/null +++ b/packages/server/test/api-keys.e2e-spec.ts @@ -0,0 +1,24 @@ +import * as request from 'supertest'; +import { faker } from '@faker-js/faker'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +describe('API Keys (e2e)', () => { + it('/api-keys (GET)', () => { + return request(app.getHttpServer()) + .get('/api-keys') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/api-keys/generate (POST)', () => { + return request(app.getHttpServer()) + .post('/api-keys/generate') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ + name: faker.string.alphanumeric(10), + }) + .expect(201); + }); +}); diff --git a/packages/server/test/attachments.e2e-spec.ts b/packages/server/test/attachments.e2e-spec.ts new file mode 100644 index 000000000..e05b763a7 --- /dev/null +++ b/packages/server/test/attachments.e2e-spec.ts @@ -0,0 +1,12 @@ +import * as request from 'supertest'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +describe('Attachments (e2e)', () => { + it('/attachments/:id/presigned-url (GET)', () => { + return request(app.getHttpServer()) + .get('/attachments/test-id/presigned-url') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +}); diff --git a/packages/server/test/banking-accounts.e2e-spec.ts b/packages/server/test/banking-accounts.e2e-spec.ts new file mode 100644 index 000000000..93c9290e4 --- /dev/null +++ b/packages/server/test/banking-accounts.e2e-spec.ts @@ -0,0 +1,20 @@ +import * as request from 'supertest'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +describe('Banking Accounts (e2e)', () => { + it('/banking/accounts (GET)', () => { + return request(app.getHttpServer()) + .get('/banking/accounts') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/banking/accounts/:bankAccountId/summary (GET)', () => { + return request(app.getHttpServer()) + .get('/banking/accounts/1/summary') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +}); diff --git a/packages/server/test/banking-categorize.e2e-spec.ts b/packages/server/test/banking-categorize.e2e-spec.ts new file mode 100644 index 000000000..d32274be3 --- /dev/null +++ b/packages/server/test/banking-categorize.e2e-spec.ts @@ -0,0 +1,34 @@ +import * as request from 'supertest'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +describe('Banking Categorize (e2e)', () => { + it('/banking/categorize (POST)', () => { + return request(app.getHttpServer()) + .post('/banking/categorize') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ + uncategorizedTransactionIds: [1], + accountId: 1000, + categoryId: 1, + }) + .expect(200); + }); + + it('/banking/categorize/:id (DELETE)', () => { + return request(app.getHttpServer()) + .delete('/banking/categorize/1') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/banking/categorize/bulk (DELETE)', () => { + return request(app.getHttpServer()) + .delete('/banking/categorize/bulk') + .query({ uncategorizedTransactionIds: [1, 2] }) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +}); diff --git a/packages/server/test/banking-exclude.e2e-spec.ts b/packages/server/test/banking-exclude.e2e-spec.ts new file mode 100644 index 000000000..f36504e96 --- /dev/null +++ b/packages/server/test/banking-exclude.e2e-spec.ts @@ -0,0 +1,46 @@ +import * as request from 'supertest'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +describe('Banking Exclude (e2e)', () => { + it('/banking/exclude (GET)', () => { + return request(app.getHttpServer()) + .get('/banking/exclude') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/banking/exclude/:id (PUT)', () => { + return request(app.getHttpServer()) + .put('/banking/exclude/1') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/banking/exclude/bulk (PUT)', () => { + return request(app.getHttpServer()) + .put('/banking/exclude/bulk') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ ids: [1, 2] }) + .expect(200); + }); + + it('/banking/exclude/:id (DELETE)', () => { + return request(app.getHttpServer()) + .delete('/banking/exclude/1') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/banking/exclude/bulk (DELETE)', () => { + return request(app.getHttpServer()) + .delete('/banking/exclude/bulk') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ ids: [1, 2] }) + .expect(200); + }); +}); diff --git a/packages/server/test/banking-matching.e2e-spec.ts b/packages/server/test/banking-matching.e2e-spec.ts new file mode 100644 index 000000000..a5aabfe81 --- /dev/null +++ b/packages/server/test/banking-matching.e2e-spec.ts @@ -0,0 +1,32 @@ +import * as request from 'supertest'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +describe('Banking Matching (e2e)', () => { + it('/banking/matching/matched (GET)', () => { + return request(app.getHttpServer()) + .get('/banking/matching/matched') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/banking/matching/match (POST)', () => { + return request(app.getHttpServer()) + .post('/banking/matching/match') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ + uncategorizedTransactions: [1], + matchedTransactions: [1], + }) + .expect(200); + }); + + it('/banking/matching/unmatch/:uncategorizedTransactionId (POST)', () => { + return request(app.getHttpServer()) + .post('/banking/matching/unmatch/1') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +}); diff --git a/packages/server/test/banking-pending.e2e-spec.ts b/packages/server/test/banking-pending.e2e-spec.ts new file mode 100644 index 000000000..22421fd2f --- /dev/null +++ b/packages/server/test/banking-pending.e2e-spec.ts @@ -0,0 +1,12 @@ +import * as request from 'supertest'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +describe('Banking Pending Transactions (e2e)', () => { + it('/banking/pending (GET)', () => { + return request(app.getHttpServer()) + .get('/banking/pending') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +}); diff --git a/packages/server/test/banking-recognized.e2e-spec.ts b/packages/server/test/banking-recognized.e2e-spec.ts new file mode 100644 index 000000000..afffdc2b3 --- /dev/null +++ b/packages/server/test/banking-recognized.e2e-spec.ts @@ -0,0 +1,20 @@ +import * as request from 'supertest'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +describe('Banking Recognized Transactions (e2e)', () => { + it('/banking/recognized (GET)', () => { + return request(app.getHttpServer()) + .get('/banking/recognized') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/banking/recognized/:recognizedTransactionId (GET)', () => { + return request(app.getHttpServer()) + .get('/banking/recognized/1') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +}); diff --git a/packages/server/test/banking-uncategorized.e2e-spec.ts b/packages/server/test/banking-uncategorized.e2e-spec.ts new file mode 100644 index 000000000..58d7b2bf5 --- /dev/null +++ b/packages/server/test/banking-uncategorized.e2e-spec.ts @@ -0,0 +1,29 @@ +import * as request from 'supertest'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +describe('Banking Uncategorized Transactions (e2e)', () => { + it('/banking/uncategorized/:uncategorizedTransactionId (GET)', () => { + return request(app.getHttpServer()) + .get('/banking/uncategorized/1') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/banking/uncategorized/accounts/:accountId (GET)', () => { + return request(app.getHttpServer()) + .get('/banking/uncategorized/accounts/1') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/banking/uncategorized/autofill (GET)', () => { + return request(app.getHttpServer()) + .get('/banking/uncategorized/autofill') + .query({ uncategorizedTransactionIds: [1] }) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +}); diff --git a/packages/server/test/bill-landed-costs.e2e-spec.ts b/packages/server/test/bill-landed-costs.e2e-spec.ts new file mode 100644 index 000000000..5cfa2f9e1 --- /dev/null +++ b/packages/server/test/bill-landed-costs.e2e-spec.ts @@ -0,0 +1,20 @@ +import * as request from 'supertest'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +describe('Bill Landed Costs (e2e)', () => { + it('/landed-cost/transactions (GET)', () => { + return request(app.getHttpServer()) + .get('/landed-cost/transactions') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/landed-cost/bills/:billId/transactions (GET)', () => { + return request(app.getHttpServer()) + .get('/landed-cost/bills/1/transactions') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +}); diff --git a/packages/server/test/bill-payments.e2e-spec.ts b/packages/server/test/bill-payments.e2e-spec.ts new file mode 100644 index 000000000..e8da200a7 --- /dev/null +++ b/packages/server/test/bill-payments.e2e-spec.ts @@ -0,0 +1,172 @@ +import * as request from 'supertest'; +import { faker } from '@faker-js/faker'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +let vendorId; +let billId; +let itemId; + +const createBillPaymentRequest = () => ({ + vendorId: vendorId, + paymentAccountId: 1000, + paymentDate: '2023-01-01', + paymentNumber: faker.string.alphanumeric(10), + entries: [ + { + billId: billId, + paymentAmount: 1000, + }, + ], +}); + +describe('Bill Payments (e2e)', () => { + beforeAll(async () => { + const vendor = await request(app.getHttpServer()) + .post('/vendors') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ displayName: 'Test Vendor' }); + + vendorId = vendor.body.id; + + const item = await request(app.getHttpServer()) + .post('/items') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ + name: faker.commerce.productName(), + sellable: true, + purchasable: true, + sellAccountId: 1026, + costAccountId: 1019, + costPrice: 100, + sellPrice: 100, + }); + itemId = parseInt(item.text, 10); + + const bill = await request(app.getHttpServer()) + .post('/bills') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ + vendorId: vendorId, + billDate: '2023-01-01', + dueDate: '2023-02-01', + billNumber: faker.string.alphanumeric(10), + branchId: 1, + warehouseId: 1, + entries: [ + { + index: 1, + itemId: itemId, + quantity: 2, + rate: 1000, + description: 'Item description...', + }, + ], + }); + billId = bill.body.id; + }); + + it('/bill-payments (POST)', () => { + return request(app.getHttpServer()) + .post('/bill-payments') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createBillPaymentRequest()) + .expect(201); + }); + + it('/bill-payments (GET)', () => { + return request(app.getHttpServer()) + .get('/bill-payments') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/bill-payments/:id (GET)', async () => { + const response = await request(app.getHttpServer()) + .post('/bill-payments') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createBillPaymentRequest()); + const billPaymentId = response.body.id; + + return request(app.getHttpServer()) + .get(`/bill-payments/${billPaymentId}`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/bill-payments/:id (PUT)', async () => { + const response = await request(app.getHttpServer()) + .post('/bill-payments') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createBillPaymentRequest()); + const billPaymentId = response.body.id; + + return request(app.getHttpServer()) + .put(`/bill-payments/${billPaymentId}`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createBillPaymentRequest()) + .expect(200); + }); + + it('/bill-payments/:id (DELETE)', async () => { + const response = await request(app.getHttpServer()) + .post('/bill-payments') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createBillPaymentRequest()); + const billPaymentId = response.body.id; + + return request(app.getHttpServer()) + .delete(`/bill-payments/${billPaymentId}`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/bill-payments/:id/bills (GET)', async () => { + const response = await request(app.getHttpServer()) + .post('/bill-payments') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createBillPaymentRequest()); + const billPaymentId = response.body.id; + + return request(app.getHttpServer()) + .get(`/bill-payments/${billPaymentId}/bills`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/bill-payments/new-page/entries (GET)', () => { + return request(app.getHttpServer()) + .get('/bill-payments/new-page/entries') + .query({ vendorId: vendorId }) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/bill-payments/:id/edit-page (GET)', async () => { + const response = await request(app.getHttpServer()) + .post('/bill-payments') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createBillPaymentRequest()); + const billPaymentId = response.body.id; + + return request(app.getHttpServer()) + .get(`/bill-payments/${billPaymentId}/edit-page`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +}); diff --git a/packages/server/test/bills.e2e-spec.ts b/packages/server/test/bills.e2e-spec.ts new file mode 100644 index 000000000..d06c4d8e2 --- /dev/null +++ b/packages/server/test/bills.e2e-spec.ts @@ -0,0 +1,195 @@ +import * as request from 'supertest'; +import { faker } from '@faker-js/faker'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +let vendorId; +let itemId; + +const createBillRequest = () => ({ + vendorId: vendorId, + billDate: '2023-01-01', + dueDate: '2023-02-01', + billNumber: faker.string.alphanumeric(10), + referenceNo: 'REF-000201', + branchId: 1, + warehouseId: 1, + entries: [ + { + index: 1, + itemId: itemId, + quantity: 2, + rate: 1000, + description: 'Item description...', + }, + ], +}); + +describe('Bills (e2e)', () => { + beforeAll(async () => { + const vendor = await request(app.getHttpServer()) + .post('/vendors') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ displayName: 'Test Vendor' }); + + vendorId = vendor.body.id; + + const item = await request(app.getHttpServer()) + .post('/items') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ + name: faker.commerce.productName(), + sellable: true, + purchasable: true, + sellAccountId: 1026, + costAccountId: 1019, + costPrice: 100, + sellPrice: 100, + }); + itemId = parseInt(item.text, 10); + }); + + it('/bills (POST)', () => { + return request(app.getHttpServer()) + .post('/bills') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createBillRequest()) + .expect(201); + }); + + it('/bills (GET)', () => { + return request(app.getHttpServer()) + .get('/bills') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/bills/:id (GET)', async () => { + const response = await request(app.getHttpServer()) + .post('/bills') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createBillRequest()); + const billId = response.body.id; + + return request(app.getHttpServer()) + .get(`/bills/${billId}`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/bills/:id (PUT)', async () => { + const response = await request(app.getHttpServer()) + .post('/bills') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createBillRequest()); + const billId = response.body.id; + + return request(app.getHttpServer()) + .put(`/bills/${billId}`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createBillRequest()) + .expect(200); + }); + + it('/bills/:id (DELETE)', async () => { + const response = await request(app.getHttpServer()) + .post('/bills') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createBillRequest()); + const billId = response.body.id; + + return request(app.getHttpServer()) + .delete(`/bills/${billId}`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/bills/:id/open (POST)', async () => { + const response = await request(app.getHttpServer()) + .post('/bills') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createBillRequest()); + const billId = response.body.id; + + return request(app.getHttpServer()) + .post(`/bills/${billId}/open`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/bills/:id/payment-transactions (GET)', async () => { + const response = await request(app.getHttpServer()) + .post('/bills') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createBillRequest()); + const billId = response.body.id; + + return request(app.getHttpServer()) + .get(`/bills/${billId}/payment-transactions`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/bills/validate-bulk-delete (POST)', async () => { + const response1 = await request(app.getHttpServer()) + .post('/bills') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createBillRequest()); + const billId1 = response1.body.id; + + const response2 = await request(app.getHttpServer()) + .post('/bills') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createBillRequest()); + const billId2 = response2.body.id; + + return request(app.getHttpServer()) + .post('/bills/validate-bulk-delete') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ + ids: [billId1, billId2], + }) + .expect(200); + }); + + it('/bills/bulk-delete (POST)', async () => { + const response1 = await request(app.getHttpServer()) + .post('/bills') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createBillRequest()); + const billId1 = response1.body.id; + + const response2 = await request(app.getHttpServer()) + .post('/bills') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createBillRequest()); + const billId2 = response2.body.id; + + return request(app.getHttpServer()) + .post('/bills/bulk-delete') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ + ids: [billId1, billId2], + }) + .expect(200); + }); +}); diff --git a/packages/server/test/contacts.e2e-spec.ts b/packages/server/test/contacts.e2e-spec.ts new file mode 100644 index 000000000..92bfc4736 --- /dev/null +++ b/packages/server/test/contacts.e2e-spec.ts @@ -0,0 +1,50 @@ +import * as request from 'supertest'; +import { faker } from '@faker-js/faker'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +let customerId; +let vendorId; + +describe('Contacts (e2e)', () => { + beforeAll(async () => { + const customer = await request(app.getHttpServer()) + .post('/customers') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ displayName: 'Test Customer' }); + + customerId = customer.body.id; + + const vendor = await request(app.getHttpServer()) + .post('/vendors') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ displayName: 'Test Vendor' }); + + vendorId = vendor.body.id; + }); + + it('/contacts/auto-complete (GET)', () => { + return request(app.getHttpServer()) + .get('/contacts/auto-complete') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/contacts/:id/activate (POST)', () => { + return request(app.getHttpServer()) + .post(`/contacts/${customerId}/activate`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/contacts/:id/inactivate (POST)', () => { + return request(app.getHttpServer()) + .post(`/contacts/${vendorId}/inactivate`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +}); diff --git a/packages/server/test/credit-note-refunds.e2e-spec.ts b/packages/server/test/credit-note-refunds.e2e-spec.ts new file mode 100644 index 000000000..eb50954bb --- /dev/null +++ b/packages/server/test/credit-note-refunds.e2e-spec.ts @@ -0,0 +1,12 @@ +import * as request from 'supertest'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +describe('Credit Note Refunds (e2e)', () => { + it('/credit-notes/:creditNoteId/refunds (GET)', () => { + return request(app.getHttpServer()) + .get('/credit-notes/1/refunds') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +}); diff --git a/packages/server/test/credit-notes-apply-invoice.e2e-spec.ts b/packages/server/test/credit-notes-apply-invoice.e2e-spec.ts new file mode 100644 index 000000000..783e1beb8 --- /dev/null +++ b/packages/server/test/credit-notes-apply-invoice.e2e-spec.ts @@ -0,0 +1,12 @@ +import * as request from 'supertest'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +describe('Credit Notes Apply Invoice (e2e)', () => { + it('/credit-notes/:creditNoteId/applied-invoices (GET)', () => { + return request(app.getHttpServer()) + .get('/credit-notes/1/applied-invoices') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +}); diff --git a/packages/server/test/currencies.e2e-spec.ts b/packages/server/test/currencies.e2e-spec.ts new file mode 100644 index 000000000..03df041ef --- /dev/null +++ b/packages/server/test/currencies.e2e-spec.ts @@ -0,0 +1,79 @@ +import * as request from 'supertest'; +import { faker } from '@faker-js/faker'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +const createCurrencyRequest = () => ({ + currencyName: faker.finance.currencyName(), + currencyCode: faker.string.alpha({ length: 3 }).toUpperCase(), + currencySign: faker.finance.currencySymbol(), +}); + +describe('Currencies (e2e)', () => { + it('/currencies (POST)', () => { + return request(app.getHttpServer()) + .post('/currencies') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createCurrencyRequest()) + .expect(201); + }); + + it('/currencies (GET)', () => { + return request(app.getHttpServer()) + .get('/currencies') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/currencies/:currencyCode (GET)', async () => { + const currency = createCurrencyRequest(); + await request(app.getHttpServer()) + .post('/currencies') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(currency); + + return request(app.getHttpServer()) + .get(`/currencies/${currency.currencyCode}`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/currencies/:id (PUT)', async () => { + const currency = createCurrencyRequest(); + const response = await request(app.getHttpServer()) + .post('/currencies') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(currency); + const currencyId = response.body.id; + + return request(app.getHttpServer()) + .put(`/currencies/${currencyId}`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ + currencyName: faker.finance.currencyName(), + currencyCode: currency.currencyCode, + currencySign: faker.finance.currencySymbol(), + }) + .expect(200); + }); + + it('/currencies/:code (DELETE)', async () => { + const currency = createCurrencyRequest(); + await request(app.getHttpServer()) + .post('/currencies') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(currency); + + return request(app.getHttpServer()) + .delete(`/currencies/${currency.currencyCode}`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +}); diff --git a/packages/server/test/dashboard.e2e-spec.ts b/packages/server/test/dashboard.e2e-spec.ts new file mode 100644 index 000000000..f50027223 --- /dev/null +++ b/packages/server/test/dashboard.e2e-spec.ts @@ -0,0 +1,12 @@ +import * as request from 'supertest'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +describe('Dashboard (e2e)', () => { + it('/dashboard/boot (GET)', () => { + return request(app.getHttpServer()) + .get('/dashboard/boot') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +}); diff --git a/packages/server/test/export.e2e-spec.ts b/packages/server/test/export.e2e-spec.ts new file mode 100644 index 000000000..b8d8af876 --- /dev/null +++ b/packages/server/test/export.e2e-spec.ts @@ -0,0 +1,14 @@ +import * as request from 'supertest'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +describe('Export (e2e)', () => { + it('/export (GET)', () => { + return request(app.getHttpServer()) + .get('/export') + .query({ resource: 'items' }) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .set('Accept', 'application/json') + .expect(200); + }); +}); diff --git a/packages/server/test/financial-statements.e2e-spec.ts b/packages/server/test/financial-statements.e2e-spec.ts new file mode 100644 index 000000000..0558dee28 --- /dev/null +++ b/packages/server/test/financial-statements.e2e-spec.ts @@ -0,0 +1,171 @@ +import * as request from 'supertest'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +describe('Financial Statements (e2e)', () => { + const baseQuery = { + fromDate: '2023-01-01', + toDate: '2023-12-31', + }; + + it('/reports/balance-sheet (GET)', () => { + return request(app.getHttpServer()) + .get('/reports/balance-sheet') + .query(baseQuery) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/reports/profit-loss-sheet (GET)', () => { + return request(app.getHttpServer()) + .get('/reports/profit-loss-sheet') + .query(baseQuery) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/reports/trial-balance-sheet (GET)', () => { + return request(app.getHttpServer()) + .get('/reports/trial-balance-sheet') + .query(baseQuery) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/reports/general-ledger (GET)', () => { + return request(app.getHttpServer()) + .get('/reports/general-ledger') + .query(baseQuery) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/reports/journal (GET)', () => { + return request(app.getHttpServer()) + .get('/reports/journal') + .query(baseQuery) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/reports/cashflow-statement (GET)', () => { + return request(app.getHttpServer()) + .get('/reports/cashflow-statement') + .query(baseQuery) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/reports/receivable-aging-summary (GET)', () => { + return request(app.getHttpServer()) + .get('/reports/receivable-aging-summary') + .query(baseQuery) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/reports/payable-aging-summary (GET)', () => { + return request(app.getHttpServer()) + .get('/reports/payable-aging-summary') + .query(baseQuery) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/reports/customer-balance-summary (GET)', () => { + return request(app.getHttpServer()) + .get('/reports/customer-balance-summary') + .query(baseQuery) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/reports/vendor-balance-summary (GET)', () => { + return request(app.getHttpServer()) + .get('/reports/vendor-balance-summary') + .query(baseQuery) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/reports/sales-by-items (GET)', () => { + return request(app.getHttpServer()) + .get('/reports/sales-by-items') + .query(baseQuery) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/reports/purchases-by-items (GET)', () => { + return request(app.getHttpServer()) + .get('/reports/purchases-by-items') + .query(baseQuery) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/reports/inventory-valuation (GET)', () => { + return request(app.getHttpServer()) + .get('/reports/inventory-valuation') + .query(baseQuery) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/reports/inventory-item-details (GET)', () => { + return request(app.getHttpServer()) + .get('/reports/inventory-item-details') + .query(baseQuery) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/reports/sales-tax-liability-summary (GET)', () => { + return request(app.getHttpServer()) + .get('/reports/sales-tax-liability-summary') + .query(baseQuery) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/reports/transactions-by-customers (GET)', () => { + return request(app.getHttpServer()) + .get('/reports/transactions-by-customers') + .query(baseQuery) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/reports/transactions-by-vendors (GET)', () => { + return request(app.getHttpServer()) + .get('/reports/transactions-by-vendors') + .query(baseQuery) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/reports/transactions-by-reference (GET)', () => { + return request(app.getHttpServer()) + .get('/reports/transactions-by-reference') + .query(baseQuery) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +}); diff --git a/packages/server/test/import.e2e-spec.ts b/packages/server/test/import.e2e-spec.ts new file mode 100644 index 000000000..e5048619f --- /dev/null +++ b/packages/server/test/import.e2e-spec.ts @@ -0,0 +1,13 @@ +import * as request from 'supertest'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +describe('Import (e2e)', () => { + it('/import/sample (GET)', () => { + return request(app.getHttpServer()) + .get('/import/sample') + .query({ resource: 'items', format: 'csv' }) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +}); diff --git a/packages/server/test/inventory-cost.e2e-spec.ts b/packages/server/test/inventory-cost.e2e-spec.ts new file mode 100644 index 000000000..c83093aee --- /dev/null +++ b/packages/server/test/inventory-cost.e2e-spec.ts @@ -0,0 +1,13 @@ +import * as request from 'supertest'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +describe('Inventory Cost (e2e)', () => { + it('/inventory-cost/items (GET)', () => { + return request(app.getHttpServer()) + .get('/inventory-cost/items') + .query({ itemsIds: [1], date: '2023-01-01' }) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +}); diff --git a/packages/server/test/items.e2e-spec.ts b/packages/server/test/items.e2e-spec.ts index 5db51f9a9..655778051 100644 --- a/packages/server/test/items.e2e-spec.ts +++ b/packages/server/test/items.e2e-spec.ts @@ -34,7 +34,31 @@ describe('Items (e2e)', () => { .put(`/items/${itemId}`) .set('organization-id', orgainzationId) .set('Authorization', AuthorizationHeader) + .send(makeItemRequest()) + .expect(200); + }); + + it('/items (GET)', () => { + return request(app.getHttpServer()) + .get('/items') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/items/:id (GET)', async () => { + const response = await request(app.getHttpServer()) + .post('/items') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) .send(makeItemRequest()); + const itemId = response.body.id; + + return request(app.getHttpServer()) + .get(`/items/${itemId}`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); }); it('/items/:id/inactivate (PATCH)', async () => { @@ -43,7 +67,7 @@ describe('Items (e2e)', () => { .set('organization-id', orgainzationId) .set('Authorization', AuthorizationHeader) .send(makeItemRequest()); - const itemId = response.text; + const itemId = response.body.id; return request(app.getHttpServer()) .patch(`/items/${itemId}/inactivate`) @@ -57,8 +81,11 @@ describe('Items (e2e)', () => { .post('/items') .set('organization-id', orgainzationId) .set('Authorization', AuthorizationHeader) - .send(makeItemRequest()); - const itemId = response.text; + .send({ + ...makeItemRequest(), + active: false, + }); + const itemId = response.body.id; return request(app.getHttpServer()) .patch(`/items/${itemId}/activate`) @@ -73,7 +100,7 @@ describe('Items (e2e)', () => { .set('organization-id', orgainzationId) .set('Authorization', AuthorizationHeader) .send(makeItemRequest()); - const itemId = response.text; + const itemId = response.body.id; return request(app.getHttpServer()) .delete(`/items/${itemId}`) @@ -88,8 +115,7 @@ describe('Items (e2e)', () => { .set('organization-id', orgainzationId) .set('Authorization', AuthorizationHeader) .send(makeItemRequest()); - - const itemId = response.text; + const itemId = response.body.id; return request(app.getHttpServer()) .get(`/items/${itemId}/invoices`) @@ -104,8 +130,7 @@ describe('Items (e2e)', () => { .set('organization-id', orgainzationId) .set('Authorization', AuthorizationHeader) .send(makeItemRequest()); - - const itemId = response.text; + const itemId = response.body.id; return request(app.getHttpServer()) .get(`/items/${itemId}/bills`) @@ -120,8 +145,7 @@ describe('Items (e2e)', () => { .set('organization-id', orgainzationId) .set('Authorization', AuthorizationHeader) .send(makeItemRequest()); - - const itemId = response.text; + const itemId = response.body.id; return request(app.getHttpServer()) .get(`/items/${itemId}/estimates`) @@ -136,8 +160,7 @@ describe('Items (e2e)', () => { .set('organization-id', orgainzationId) .set('Authorization', AuthorizationHeader) .send(makeItemRequest()); - - const itemId = response.text; + const itemId = response.body.id; return request(app.getHttpServer()) .get(`/items/${itemId}/receipts`) @@ -145,4 +168,54 @@ describe('Items (e2e)', () => { .set('Authorization', AuthorizationHeader) .expect(200); }); + + it('/items/validate-bulk-delete (POST)', async () => { + const response1 = await request(app.getHttpServer()) + .post('/items') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(makeItemRequest()); + const itemId1 = response1.body.id; + + const response2 = await request(app.getHttpServer()) + .post('/items') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(makeItemRequest()); + const itemId2 = response2.body.id; + + return request(app.getHttpServer()) + .post('/items/validate-bulk-delete') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ + ids: [itemId1, itemId2], + }) + .expect(200); + }); + + it('/items/bulk-delete (POST)', async () => { + const response1 = await request(app.getHttpServer()) + .post('/items') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(makeItemRequest()); + const itemId1 = response1.body.id; + + const response2 = await request(app.getHttpServer()) + .post('/items') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(makeItemRequest()); + const itemId2 = response2.body.id; + + return request(app.getHttpServer()) + .post('/items/bulk-delete') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ + ids: [itemId1, itemId2], + }) + .expect(200); + }); }); diff --git a/packages/server/test/payment-links.e2e-spec.ts b/packages/server/test/payment-links.e2e-spec.ts new file mode 100644 index 000000000..325db0d52 --- /dev/null +++ b/packages/server/test/payment-links.e2e-spec.ts @@ -0,0 +1,12 @@ +import * as request from 'supertest'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +describe('Payment Links (e2e)', () => { + it('/payment-links/:paymentLinkId/invoice (GET)', () => { + return request(app.getHttpServer()) + .get('/payment-links/test-link-id/invoice') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +}); diff --git a/packages/server/test/payment-services.e2e-spec.ts b/packages/server/test/payment-services.e2e-spec.ts new file mode 100644 index 000000000..2885cd9d1 --- /dev/null +++ b/packages/server/test/payment-services.e2e-spec.ts @@ -0,0 +1,28 @@ +import * as request from 'supertest'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +describe('Payment Services (e2e)', () => { + it('/payment-services (GET)', () => { + return request(app.getHttpServer()) + .get('/payment-services') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/payment-services/state (GET)', () => { + return request(app.getHttpServer()) + .get('/payment-services/state') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/payment-services/:paymentServiceId (GET)', () => { + return request(app.getHttpServer()) + .get('/payment-services/1') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +}); diff --git a/packages/server/test/resource.e2e-spec.ts b/packages/server/test/resource.e2e-spec.ts new file mode 100644 index 000000000..47301886f --- /dev/null +++ b/packages/server/test/resource.e2e-spec.ts @@ -0,0 +1,12 @@ +import * as request from 'supertest'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +describe('Resource (e2e)', () => { + it('/resources/:resourceModel/meta (GET)', () => { + return request(app.getHttpServer()) + .get('/resources/items/meta') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +}); diff --git a/packages/server/test/roles.e2e-spec.ts b/packages/server/test/roles.e2e-spec.ts new file mode 100644 index 000000000..a5d31fa52 --- /dev/null +++ b/packages/server/test/roles.e2e-spec.ts @@ -0,0 +1,104 @@ +import * as request from 'supertest'; +import { faker } from '@faker-js/faker'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +const createRoleRequest = () => ({ + roleName: faker.string.alphanumeric(10), + roleDescription: faker.lorem.sentence(), + permissions: [ + { + subject: 'items', + ability: 'read', + value: true, + }, + { + subject: 'items', + ability: 'create', + value: true, + }, + ], +}); + +describe('Roles (e2e)', () => { + it('/roles (POST)', () => { + return request(app.getHttpServer()) + .post('/roles') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createRoleRequest()) + .expect(200); + }); + + it('/roles (GET)', () => { + return request(app.getHttpServer()) + .get('/roles') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/roles/permissions/schema (GET)', () => { + return request(app.getHttpServer()) + .get('/roles/permissions/schema') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/roles/:id (GET)', async () => { + const response = await request(app.getHttpServer()) + .post('/roles') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createRoleRequest()); + const roleId = response.body.data.roleId; + + return request(app.getHttpServer()) + .get(`/roles/${roleId}`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/roles/:id (POST)', async () => { + const response = await request(app.getHttpServer()) + .post('/roles') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createRoleRequest()); + const roleId = response.body.data.roleId; + + return request(app.getHttpServer()) + .post(`/roles/${roleId}`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ + roleName: faker.string.alphanumeric(10), + roleDescription: faker.lorem.sentence(), + permissions: [ + { + permissionId: 1, + subject: 'items', + ability: 'read', + value: true, + }, + ], + }) + .expect(200); + }); + + it('/roles/:id (DELETE)', async () => { + const response = await request(app.getHttpServer()) + .post('/roles') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createRoleRequest()); + const roleId = response.body.data.roleId; + + return request(app.getHttpServer()) + .delete(`/roles/${roleId}`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +}); diff --git a/packages/server/test/users-invite.e2e-spec.ts b/packages/server/test/users-invite.e2e-spec.ts new file mode 100644 index 000000000..79e9bf373 --- /dev/null +++ b/packages/server/test/users-invite.e2e-spec.ts @@ -0,0 +1,17 @@ +import * as request from 'supertest'; +import { faker } from '@faker-js/faker'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +describe('Users Invite (e2e)', () => { + it('/invite (POST)', () => { + return request(app.getHttpServer()) + .post('/invite') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ + email: faker.internet.email(), + roleId: 1, + }) + .expect(200); + }); +}); diff --git a/packages/server/test/users.e2e-spec.ts b/packages/server/test/users.e2e-spec.ts new file mode 100644 index 000000000..8be71cbc2 --- /dev/null +++ b/packages/server/test/users.e2e-spec.ts @@ -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); + } + }); +}); diff --git a/packages/server/test/vendor-credits-apply-bills.e2e-spec.ts b/packages/server/test/vendor-credits-apply-bills.e2e-spec.ts new file mode 100644 index 000000000..2b4269482 --- /dev/null +++ b/packages/server/test/vendor-credits-apply-bills.e2e-spec.ts @@ -0,0 +1,20 @@ +import * as request from 'supertest'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +describe('Vendor Credits Apply Bills (e2e)', () => { + it('/vendor-credits/:vendorCreditId/bills-to-apply (GET)', () => { + return request(app.getHttpServer()) + .get('/vendor-credits/1/bills-to-apply') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/vendor-credits/:vendorCreditId/applied-bills (GET)', () => { + return request(app.getHttpServer()) + .get('/vendor-credits/1/applied-bills') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +}); diff --git a/packages/server/test/vendor-credits-refund.e2e-spec.ts b/packages/server/test/vendor-credits-refund.e2e-spec.ts new file mode 100644 index 000000000..201e12839 --- /dev/null +++ b/packages/server/test/vendor-credits-refund.e2e-spec.ts @@ -0,0 +1,12 @@ +import * as request from 'supertest'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +describe('Vendor Credits Refund (e2e)', () => { + it('/vendor-credits/:vendorCreditId/refund (GET)', () => { + return request(app.getHttpServer()) + .get('/vendor-credits/1/refund') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +}); diff --git a/packages/server/test/views.e2e-spec.ts b/packages/server/test/views.e2e-spec.ts new file mode 100644 index 000000000..1f1dc672c --- /dev/null +++ b/packages/server/test/views.e2e-spec.ts @@ -0,0 +1,12 @@ +import * as request from 'supertest'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +describe('Views (e2e)', () => { + it('/views/resource/:resourceModel (GET)', () => { + return request(app.getHttpServer()) + .get('/views/resource/items') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +}); diff --git a/packages/server/test/warehouse-transfers.e2e-spec.ts b/packages/server/test/warehouse-transfers.e2e-spec.ts new file mode 100644 index 000000000..a2a45e9b9 --- /dev/null +++ b/packages/server/test/warehouse-transfers.e2e-spec.ts @@ -0,0 +1,126 @@ +import * as request from 'supertest'; +import { faker } from '@faker-js/faker'; +import { app, AuthorizationHeader, orgainzationId } from './init-app-test'; + +let itemId; +let warehouseId1; +let warehouseId2; + +const createWarehouseTransferRequest = () => ({ + fromWarehouseId: warehouseId1, + toWarehouseId: warehouseId2, + date: '2023-01-01', + transactionNumber: faker.string.alphanumeric(10), + entries: [ + { + index: 1, + itemId: itemId, + quantity: 10, + description: 'Transfer description', + }, + ], +}); + +describe('Warehouse Transfers (e2e)', () => { + beforeAll(async () => { + const item = await request(app.getHttpServer()) + .post('/items') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ + name: faker.commerce.productName(), + sellable: true, + purchasable: true, + sellAccountId: 1026, + costAccountId: 1019, + costPrice: 100, + sellPrice: 100, + }); + itemId = parseInt(item.text, 10); + + const warehouse1 = await request(app.getHttpServer()) + .post('/warehouses') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ + name: faker.company.name(), + code: faker.string.alphanumeric(5).toUpperCase(), + address: faker.location.streetAddress(), + }); + warehouseId1 = warehouse1.body.id; + + const warehouse2 = await request(app.getHttpServer()) + .post('/warehouses') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send({ + name: faker.company.name(), + code: faker.string.alphanumeric(5).toUpperCase(), + address: faker.location.streetAddress(), + }); + warehouseId2 = warehouse2.body.id; + }); + + it('/warehouse-transfers (POST)', () => { + return request(app.getHttpServer()) + .post('/warehouse-transfers') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createWarehouseTransferRequest()) + .expect(200); + }); + + it('/warehouse-transfers (GET)', () => { + return request(app.getHttpServer()) + .get('/warehouse-transfers') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/warehouse-transfers/:id (GET)', async () => { + const response = await request(app.getHttpServer()) + .post('/warehouse-transfers') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createWarehouseTransferRequest()); + const transferId = response.body.id; + + return request(app.getHttpServer()) + .get(`/warehouse-transfers/${transferId}`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); + + it('/warehouse-transfers/:id (POST)', async () => { + const response = await request(app.getHttpServer()) + .post('/warehouse-transfers') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createWarehouseTransferRequest()); + const transferId = response.body.id; + + return request(app.getHttpServer()) + .post(`/warehouse-transfers/${transferId}`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createWarehouseTransferRequest()) + .expect(200); + }); + + it('/warehouse-transfers/:id (DELETE)', async () => { + const response = await request(app.getHttpServer()) + .post('/warehouse-transfers') + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .send(createWarehouseTransferRequest()); + const transferId = response.body.id; + + return request(app.getHttpServer()) + .delete(`/warehouse-transfers/${transferId}`) + .set('organization-id', orgainzationId) + .set('Authorization', AuthorizationHeader) + .expect(200); + }); +});