mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
wip
This commit is contained in:
@@ -1,20 +1,49 @@
|
||||
import * as request from 'supertest';
|
||||
import { faker } from '@faker-js/faker';
|
||||
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 (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);
|
||||
// });
|
||||
it('/banking/accounts/:bankAccountId/summary (GET)', async () => {
|
||||
// First, get the list of bank accounts
|
||||
const accountsResponse = await request(app.getHttpServer())
|
||||
.get('/banking/accounts')
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader)
|
||||
.expect(200);
|
||||
|
||||
let bankAccountId: number;
|
||||
|
||||
// If there are no bank accounts, create one
|
||||
if (accountsResponse.body.length === 0) {
|
||||
const createResponse = await request(app.getHttpServer())
|
||||
.post('/accounts')
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader)
|
||||
.send({
|
||||
name: `${faker.finance.accountName()} ${Date.now()}-${faker.string.alphanumeric({ length: 4 })}`,
|
||||
accountType: 'bank',
|
||||
code: faker.string.alphanumeric({ length: 6 }).toUpperCase(),
|
||||
})
|
||||
.expect(201);
|
||||
|
||||
bankAccountId = createResponse.body.id;
|
||||
} else {
|
||||
// Use the first bank account's ID
|
||||
bankAccountId = accountsResponse.body[0].id;
|
||||
}
|
||||
|
||||
return request(app.getHttpServer())
|
||||
.get(`/banking/accounts/${bankAccountId}/summary`)
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader)
|
||||
.expect(200);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,9 +22,9 @@ describe('Banking Matching (e2e)', () => {
|
||||
.expect(200);
|
||||
});
|
||||
|
||||
it('/banking/matching/unmatch/:uncategorizedTransactionId (POST)', () => {
|
||||
it('/banking/matching/unmatch/:uncategorizedTransactionId (PATCH)', () => {
|
||||
return request(app.getHttpServer())
|
||||
.post('/banking/matching/unmatch/1')
|
||||
.patch('/banking/matching/unmatch/1')
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader)
|
||||
.expect(200);
|
||||
|
||||
@@ -42,7 +42,7 @@ describe('Bill Payments (e2e)', () => {
|
||||
costPrice: 100,
|
||||
sellPrice: 100,
|
||||
});
|
||||
itemId = parseInt(item.text, 10);
|
||||
itemId = parseInt(item.body.id, 10);
|
||||
|
||||
const bill = await request(app.getHttpServer())
|
||||
.post('/bills')
|
||||
@@ -53,8 +53,8 @@ describe('Bill Payments (e2e)', () => {
|
||||
billDate: '2023-01-01',
|
||||
dueDate: '2023-02-01',
|
||||
billNumber: faker.string.alphanumeric(10),
|
||||
branchId: 1,
|
||||
warehouseId: 1,
|
||||
// branchId: 1,
|
||||
// warehouseId: 1,
|
||||
entries: [
|
||||
{
|
||||
index: 1,
|
||||
@@ -68,13 +68,15 @@ describe('Bill Payments (e2e)', () => {
|
||||
billId = bill.body.id;
|
||||
});
|
||||
|
||||
it('/bill-payments (POST)', () => {
|
||||
return request(app.getHttpServer())
|
||||
it('/bill-payments (POST)', async () => {
|
||||
const response = await request(app.getHttpServer())
|
||||
.post('/bill-payments')
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader)
|
||||
.send(createBillPaymentRequest())
|
||||
.expect(201);
|
||||
|
||||
console.log(response.body);
|
||||
});
|
||||
|
||||
it('/bill-payments (GET)', () => {
|
||||
|
||||
@@ -47,7 +47,7 @@ describe('Bills (e2e)', () => {
|
||||
costPrice: 100,
|
||||
sellPrice: 100,
|
||||
});
|
||||
itemId = parseInt(item.text, 10);
|
||||
itemId = parseInt(item.body.id, 10);
|
||||
});
|
||||
|
||||
it('/bills (POST)', () => {
|
||||
@@ -113,7 +113,7 @@ describe('Bills (e2e)', () => {
|
||||
.expect(200);
|
||||
});
|
||||
|
||||
it('/bills/:id/open (POST)', async () => {
|
||||
it('/bills/:id/open (PATCH)', async () => {
|
||||
const response = await request(app.getHttpServer())
|
||||
.post('/bills')
|
||||
.set('organization-id', orgainzationId)
|
||||
@@ -122,7 +122,7 @@ describe('Bills (e2e)', () => {
|
||||
const billId = response.body.id;
|
||||
|
||||
return request(app.getHttpServer())
|
||||
.post(`/bills/${billId}/open`)
|
||||
.patch(`/bills/${billId}/open`)
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader)
|
||||
.expect(200);
|
||||
|
||||
@@ -46,7 +46,7 @@ describe('Credit Notes (e2e)', () => {
|
||||
costPrice: 100,
|
||||
sellPrice: 100,
|
||||
});
|
||||
itemId = parseInt(item.text, 10);
|
||||
itemId = parseInt(item.body.id, 10);
|
||||
});
|
||||
|
||||
it('/credit-notes (POST)', () => {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { AppModule } from '../src/modules/App/App.module';
|
||||
|
||||
let app: INestApplication;
|
||||
|
||||
const email = 'big@big.com';
|
||||
const email = 'bigcapital@bigcapital.com';
|
||||
const password = '123123123';
|
||||
|
||||
let orgainzationId = '';
|
||||
@@ -24,8 +24,6 @@ beforeAll(async () => {
|
||||
.post('/auth/signin')
|
||||
.send({ email, password });
|
||||
|
||||
console.log(signinResponse.body);
|
||||
|
||||
authenticationToken = signinResponse.body.access_token;
|
||||
AuthorizationHeader = `Bearer ${authenticationToken}`;
|
||||
orgainzationId = signinResponse.body.organization_id;
|
||||
@@ -34,6 +32,6 @@ beforeAll(async () => {
|
||||
afterAll(async () => {
|
||||
await app.close();
|
||||
});
|
||||
// jest.retryTimes(3, { logErrorsBeforeRetry: true });
|
||||
jest.retryTimes(3, { logErrorsBeforeRetry: true });
|
||||
|
||||
export { app, orgainzationId, authenticationToken, AuthorizationHeader };
|
||||
|
||||
@@ -33,7 +33,7 @@ describe('Inventory Adjustments (e2e)', () => {
|
||||
.send(makeItemRequest())
|
||||
.expect(201);
|
||||
|
||||
const itemId = itemResponse.text;
|
||||
const itemId = itemResponse.body.id;
|
||||
|
||||
return request(app.getHttpServer())
|
||||
.post('/inventory-adjustments/quick')
|
||||
@@ -51,7 +51,7 @@ describe('Inventory Adjustments (e2e)', () => {
|
||||
.send(makeItemRequest())
|
||||
.expect(201);
|
||||
|
||||
const itemId = itemResponse.text;
|
||||
const itemId = itemResponse.body.id;
|
||||
|
||||
const inventoryAdjustmentResponse = await request(app.getHttpServer())
|
||||
.post('/inventory-adjustments/quick')
|
||||
@@ -77,7 +77,7 @@ describe('Inventory Adjustments (e2e)', () => {
|
||||
.send(makeItemRequest())
|
||||
.expect(201);
|
||||
|
||||
const itemId = itemResponse.text;
|
||||
const itemId = itemResponse.body.id;
|
||||
const inventoryAdjustmentResponse = await request(app.getHttpServer())
|
||||
.post('/inventory-adjustments/quick')
|
||||
.set('organization-id', orgainzationId)
|
||||
@@ -102,7 +102,7 @@ describe('Inventory Adjustments (e2e)', () => {
|
||||
.send(makeItemRequest())
|
||||
.expect(201);
|
||||
|
||||
const itemId = itemResponse.text;
|
||||
const itemId = itemResponse.body.id;
|
||||
const inventoryAdjustmentResponse = await request(app.getHttpServer())
|
||||
.post('/inventory-adjustments/quick')
|
||||
.set('organization-id', orgainzationId)
|
||||
|
||||
@@ -23,7 +23,7 @@ const makeManualJournalRequest = () => ({
|
||||
],
|
||||
});
|
||||
|
||||
describe.only('Manual Journals (e2e)', () => {
|
||||
describe('Manual Journals (e2e)', () => {
|
||||
it('/manual-journals (POST)', () => {
|
||||
return request(app.getHttpServer())
|
||||
.post('/manual-journals')
|
||||
@@ -85,7 +85,7 @@ describe.only('Manual Journals (e2e)', () => {
|
||||
.expect(200);
|
||||
});
|
||||
|
||||
it('/manual-journals/:id/publish (PUT)', async () => {
|
||||
it('/manual-journals/:id/publish (PATCH)', async () => {
|
||||
const response = await request(app.getHttpServer())
|
||||
.post('/manual-journals')
|
||||
.set('organization-id', orgainzationId)
|
||||
@@ -95,7 +95,7 @@ describe.only('Manual Journals (e2e)', () => {
|
||||
const journalId = response.body.id;
|
||||
|
||||
return request(app.getHttpServer())
|
||||
.put(`/manual-journals/${journalId}/publish`)
|
||||
.patch(`/manual-journals/${journalId}/publish`)
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader)
|
||||
.send()
|
||||
|
||||
@@ -1,10 +1,82 @@
|
||||
import * as request from 'supertest';
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { app, AuthorizationHeader, orgainzationId } from './init-app-test';
|
||||
|
||||
let customerId;
|
||||
let itemId;
|
||||
|
||||
const requestSaleInvoiceBody = () => ({
|
||||
customerId: customerId,
|
||||
invoiceDate: '2023-01-01',
|
||||
dueDate: '2023-02-01',
|
||||
invoiceNo: faker.string.uuid(),
|
||||
referenceNo: 'REF-000201',
|
||||
delivered: true,
|
||||
discountType: 'percentage',
|
||||
discount: 10,
|
||||
entries: [
|
||||
{
|
||||
index: 1,
|
||||
itemId: itemId,
|
||||
quantity: 2,
|
||||
rate: 1000,
|
||||
description: 'Item description...',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
describe('Payment Links (e2e)', () => {
|
||||
it('/payment-links/:paymentLinkId/invoice (GET)', () => {
|
||||
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 item = await request(app.getHttpServer())
|
||||
.post('/items')
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader)
|
||||
.send({
|
||||
name: `${faker.commerce.productName()} ${Date.now()}-${faker.string.alphanumeric({ length: 4 })}`,
|
||||
sellable: true,
|
||||
purchasable: true,
|
||||
sellAccountId: 1026,
|
||||
costAccountId: 1019,
|
||||
costPrice: 100,
|
||||
sellPrice: 100,
|
||||
});
|
||||
itemId = item.body.id;
|
||||
});
|
||||
|
||||
it('/payment-links/:paymentLinkId/invoice (GET)', async () => {
|
||||
// Create a sale invoice
|
||||
const invoiceResponse = await request(app.getHttpServer())
|
||||
.post('/sale-invoices')
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader)
|
||||
.send(requestSaleInvoiceBody())
|
||||
.expect(201);
|
||||
|
||||
const invoiceId = invoiceResponse.body.id;
|
||||
|
||||
// Generate a payment link for the invoice
|
||||
const paymentLinkResponse = await request(app.getHttpServer())
|
||||
.post(`/sale-invoices/${invoiceId}/generate-link`)
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader)
|
||||
.expect(201);
|
||||
|
||||
// Extract payment link ID from the URL
|
||||
// Format: {BASE_URL}/payment/{PAYMENT_LINK_ID}
|
||||
const paymentLinkUrl = paymentLinkResponse.body.link;
|
||||
const paymentLinkId = paymentLinkUrl.split('/payment/')[1];
|
||||
|
||||
// Test the payment link endpoint
|
||||
return request(app.getHttpServer())
|
||||
.get('/payment-links/test-link-id/invoice')
|
||||
.get(`/payment-links/${paymentLinkId}/invoice`)
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader)
|
||||
.expect(200);
|
||||
|
||||
@@ -63,7 +63,7 @@ describe('Payment Received (e2e)', () => {
|
||||
costPrice: 100,
|
||||
sellPrice: 100,
|
||||
});
|
||||
itemId = parseInt(item.text, 10);
|
||||
itemId = parseInt(item.body.id, 10);
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
|
||||
@@ -21,6 +21,7 @@ const createRoleRequest = () => ({
|
||||
|
||||
describe('Roles (e2e)', () => {
|
||||
it('/roles (POST)', () => {
|
||||
console.log(createRoleRequest())
|
||||
return request(app.getHttpServer())
|
||||
.post('/roles')
|
||||
.set('organization-id', orgainzationId)
|
||||
@@ -51,7 +52,7 @@ describe('Roles (e2e)', () => {
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader)
|
||||
.send(createRoleRequest());
|
||||
const roleId = response.body.data.roleId;
|
||||
const roleId = response.body.data.id;
|
||||
|
||||
return request(app.getHttpServer())
|
||||
.get(`/roles/${roleId}`)
|
||||
@@ -66,7 +67,7 @@ describe('Roles (e2e)', () => {
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader)
|
||||
.send(createRoleRequest());
|
||||
const roleId = response.body.data.roleId;
|
||||
const roleId = response.body.data.id;
|
||||
|
||||
return request(app.getHttpServer())
|
||||
.post(`/roles/${roleId}`)
|
||||
|
||||
@@ -49,7 +49,7 @@ describe('Sale Estimates (e2e)', () => {
|
||||
costPrice: 100,
|
||||
sellPrice: 100,
|
||||
});
|
||||
itemId = parseInt(item.text, 10);
|
||||
itemId = item.body.id;
|
||||
});
|
||||
|
||||
it('/sale-estimates (POST)', async () => {
|
||||
|
||||
@@ -14,8 +14,8 @@ const requestSaleInvoiceBody = () => ({
|
||||
delivered: true,
|
||||
discountType: 'percentage',
|
||||
discount: 10,
|
||||
branchId: 1,
|
||||
warehouseId: 1,
|
||||
// branchId: 1,
|
||||
// warehouseId: 1,
|
||||
entries: [
|
||||
{
|
||||
index: 1,
|
||||
@@ -50,7 +50,7 @@ describe('Sale Invoices (e2e)', () => {
|
||||
costPrice: 100,
|
||||
sellPrice: 100,
|
||||
});
|
||||
itemId = parseInt(item.text, 10);
|
||||
itemId = item.body.id;
|
||||
});
|
||||
|
||||
it('/sale-invoices (POST)', () => {
|
||||
@@ -119,15 +119,9 @@ describe('Sale Invoices (e2e)', () => {
|
||||
.expect(200);
|
||||
});
|
||||
|
||||
it('/sale-invoices/:id/state (GET)', async () => {
|
||||
const response = await request(app.getHttpServer())
|
||||
.post('/sale-invoices')
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader)
|
||||
.send(requestSaleInvoiceBody());
|
||||
|
||||
it('/sale-invoices/state (GET)', async () => {
|
||||
return request(app.getHttpServer())
|
||||
.get(`/sale-invoices/${response.body.id}/state`)
|
||||
.get('/sale-invoices/state')
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader)
|
||||
.expect(200);
|
||||
@@ -207,7 +201,7 @@ describe('Sale Invoices (e2e)', () => {
|
||||
.expect(200);
|
||||
});
|
||||
|
||||
it('/sale-invoices/:id/mail-state (GET)', async () => {
|
||||
it('/sale-invoices/:id/mail (GET)', async () => {
|
||||
const response = await request(app.getHttpServer())
|
||||
.post('/sale-invoices')
|
||||
.set('organization-id', orgainzationId)
|
||||
@@ -215,7 +209,7 @@ describe('Sale Invoices (e2e)', () => {
|
||||
.send(requestSaleInvoiceBody());
|
||||
|
||||
return request(app.getHttpServer())
|
||||
.get(`/sale-invoices/${response.body.id}/mail-state`)
|
||||
.get(`/sale-invoices/${response.body.id}/mail`)
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader)
|
||||
.expect(200);
|
||||
|
||||
@@ -3,9 +3,9 @@ import { faker } from '@faker-js/faker';
|
||||
import { app, AuthorizationHeader, orgainzationId } from './init-app-test';
|
||||
|
||||
describe('Users Invite (e2e)', () => {
|
||||
it('/invite (POST)', () => {
|
||||
it('/invite (PATCH)', () => {
|
||||
return request(app.getHttpServer())
|
||||
.post('/invite')
|
||||
.patch('/invite')
|
||||
.set('organization-id', orgainzationId)
|
||||
.set('Authorization', AuthorizationHeader)
|
||||
.send({
|
||||
|
||||
@@ -56,7 +56,6 @@ describe('Users (e2e)', () => {
|
||||
userId = usersResponse.body[0].id;
|
||||
}
|
||||
}
|
||||
|
||||
if (userId) {
|
||||
return request(app.getHttpServer())
|
||||
.post(`/users/${userId}`)
|
||||
@@ -65,52 +64,50 @@ describe('Users (e2e)', () => {
|
||||
.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);
|
||||
// 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 (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);
|
||||
}
|
||||
});
|
||||
// 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);
|
||||
// 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 (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);
|
||||
}
|
||||
});
|
||||
// if (userId) {
|
||||
// return request(app.getHttpServer())
|
||||
// .put(`/users/${userId}/inactivate`)
|
||||
// .set('organization-id', orgainzationId)
|
||||
// .set('Authorization', AuthorizationHeader)
|
||||
// .expect(200);
|
||||
// }
|
||||
// });
|
||||
});
|
||||
|
||||
@@ -46,7 +46,7 @@ describe('Vendor Credits (e2e)', () => {
|
||||
costPrice: 100,
|
||||
sellPrice: 100,
|
||||
});
|
||||
itemId = parseInt(item.text, 10);
|
||||
itemId = parseInt(item.body.id, 10);
|
||||
});
|
||||
|
||||
it('/vendor-credits (POST)', () => {
|
||||
|
||||
@@ -36,7 +36,7 @@ describe('Warehouse Transfers (e2e)', () => {
|
||||
costPrice: 100,
|
||||
sellPrice: 100,
|
||||
});
|
||||
itemId = parseInt(item.text, 10);
|
||||
itemId = parseInt(item.body.id, 10);
|
||||
|
||||
const warehouse1 = await request(app.getHttpServer())
|
||||
.post('/warehouses')
|
||||
|
||||
Reference in New Issue
Block a user