fix: e2e test cases

This commit is contained in:
Ahmed Bouhuolia
2025-01-11 18:03:59 +02:00
parent 7e82080cb7
commit ddaea20d16
32 changed files with 503 additions and 248 deletions

View File

@@ -1,16 +1,19 @@
import * as request from 'supertest';
import { app } from './init-app-test';
import { faker } from '@faker-js/faker';
import { app, orgainzationId } from './init-app-test';
let vendorId;
let itemId;
const requestVendorCredit = () => ({
vendorId: 3,
vendorId: vendorId,
exchangeRate: 1,
vendorCreditNumber: faker.string.uuid(),
vendorCreditDate: '2025-01-01',
entries: [
{
index: 1,
item_id: 1000,
item_id: itemId,
quantity: 1,
rate: 1000,
description: "It's description here.",
@@ -21,10 +24,33 @@ const requestVendorCredit = () => ({
});
describe('Vendor Credits (e2e)', () => {
beforeAll(async () => {
const vendor = await request(app.getHttpServer())
.post('/vendors')
.set('organization-id', orgainzationId)
.send({ displayName: 'Test Customer' });
vendorId = vendor.body.id;
const item = await request(app.getHttpServer())
.post('/items')
.set('organization-id', orgainzationId)
.send({
name: faker.commerce.productName(),
sellable: true,
purchasable: true,
sellAccountId: 1026,
costAccountId: 1019,
costPrice: 100,
sellPrice: 100,
});
itemId = parseInt(item.text, 10);
});
it('/vendor-credits (POST)', () => {
return request(app.getHttpServer())
.post('/vendor-credits')
.set('organization-id', '4064541lv40nhca')
.set('organization-id', orgainzationId)
.send(requestVendorCredit())
.expect(201);
});
@@ -32,42 +58,42 @@ describe('Vendor Credits (e2e)', () => {
it('/vendor-credits/:id (DELETE)', async () => {
const response = await request(app.getHttpServer())
.post('/vendor-credits')
.set('organization-id', '4064541lv40nhca')
.set('organization-id', orgainzationId)
.send(requestVendorCredit());
const vendorCreditId = response.body.id;
return request(app.getHttpServer())
.delete(`/vendor-credits/${vendorCreditId}`)
.set('organization-id', '4064541lv40nhca')
.set('organization-id', orgainzationId)
.expect(200);
});
it('/vendor-credits/:id/open (POST)', async () => {
const response = await request(app.getHttpServer())
.post('/vendor-credits')
.set('organization-id', '4064541lv40nhca')
.set('organization-id', orgainzationId)
.send(requestVendorCredit());
const vendorCreditId = response.body.id;
return request(app.getHttpServer())
.put(`/vendor-credits/${vendorCreditId}/open`)
.set('organization-id', '4064541lv40nhca')
.set('organization-id', orgainzationId)
.expect(200);
});
it('/vendor-credits/:id (GET)', async () => {
const response = await request(app.getHttpServer())
.post('/vendor-credits')
.set('organization-id', '4064541lv40nhca')
.set('organization-id', orgainzationId)
.send(requestVendorCredit());
const vendorCreditId = response.body.id;
return request(app.getHttpServer())
.get(`/vendor-credits/${vendorCreditId}`)
.set('organization-id', '4064541lv40nhca')
.set('organization-id', orgainzationId)
.expect(200);
});
});