-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fad4484
commit 81eb835
Showing
7 changed files
with
157 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const { Inventory } = require('../../../models').tenant; | ||
|
||
describe('Inventory Model', () => { | ||
describe('custom getters', () => { | ||
it('returns correct quantity value', () => { | ||
const inventory = Inventory.build({ quantity: 10 }); | ||
expect(inventory.quantity).toEqual(10); | ||
}); | ||
|
||
it('returns correct quantity reference value', () => { | ||
const inventory = Inventory.build({ quantityReference: 10 }); | ||
expect(inventory.quantityReference).toEqual(10); | ||
}); | ||
|
||
it('returns correct converter reference value', () => { | ||
const inventory = Inventory.build({ converterReference: 10 }); | ||
expect(inventory.converterReference).toEqual(10); | ||
}); | ||
|
||
it('returns correct expiry date value', () => { | ||
const inventory = Inventory.build({ expiryDate: null }); | ||
expect(inventory.expiryDate).toEqual(null); | ||
|
||
const expiryDate = new Date('2022-03-03'); | ||
inventory.expiryDate = expiryDate; | ||
expect(inventory.expiryDate).toEqual('2022-03-03 07:00:00'); | ||
}); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
src/modules/inventory/models/inventoryAuditItem.model.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const { InventoryAuditItem } = require('../../../models').tenant; | ||
|
||
describe('Inventory Audit Item Model', () => { | ||
describe('custom getters', () => { | ||
it('returns correct quantity value', () => { | ||
const inventoryAuditItem = InventoryAuditItem.build({ quantity: 10 }); | ||
expect(inventoryAuditItem.quantity).toEqual(10); | ||
}); | ||
|
||
it('returns correct expiry date value', () => { | ||
const inventoryAuditItem = InventoryAuditItem.build({ expiryDate: null }); | ||
expect(inventoryAuditItem.expiryDate).toEqual(null); | ||
|
||
const expiryDate = new Date('2022-03-03'); | ||
inventoryAuditItem.expiryDate = expiryDate; | ||
expect(inventoryAuditItem.expiryDate).toEqual('2022-03-03 07:00:00'); | ||
}); | ||
|
||
it('returns correct price value', () => { | ||
const inventoryAuditItem = InventoryAuditItem.build({ price: 10000 }); | ||
expect(inventoryAuditItem.price).toEqual(10000); | ||
}); | ||
|
||
it('returns correct converter value', () => { | ||
const inventoryAuditItem = InventoryAuditItem.build({ converter: 10 }); | ||
expect(inventoryAuditItem.converter).toEqual(10); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const factory = require('@root/tests/utils/factory'); | ||
const tenantDatabase = require('@src/models').tenant; | ||
const GetCurrentStock = require('./GetCurrentStock'); | ||
|
||
describe('Get Current Stock', () => { | ||
describe('when item require production number and expiry date', () => { | ||
let warehouse, item, inventory; | ||
beforeEach(async (done) => { | ||
const maker = await factory.user.create(); | ||
const branch = await factory.branch.create(); | ||
warehouse = await factory.warehouse.create({ branch }); | ||
item = await factory.item.create({ requireProductionNumber: true, requireExpiryDate: true }); | ||
const inventoryForm = await factory.form.create({ | ||
date: new Date('2022-01-01'), | ||
branch, | ||
number: 'PI2101001', | ||
formable: { id: 1 }, | ||
formableType: 'PurchaseInvoice', | ||
createdBy: maker.id, | ||
updatedBy: maker.id, | ||
}); | ||
inventory = await factory.inventory.create({ | ||
form: inventoryForm, | ||
warehouse, | ||
item, | ||
productionNumber: '001', | ||
expiryDate: new Date('2022-03-01'), | ||
}); | ||
|
||
done(); | ||
}); | ||
|
||
it('returns correct stock', async () => { | ||
const currentStock = await new GetCurrentStock(tenantDatabase, { | ||
item, | ||
date: new Date('2022-03-01'), | ||
warehouseId: warehouse.id, | ||
useDna: true, | ||
options: { | ||
productionNumber: '001', | ||
expiryDate: new Date('2022-03-01'), | ||
}, | ||
}).call(); | ||
|
||
expect(currentStock).toEqual(100); | ||
}); | ||
|
||
it('returns 0 when no inventories recorded', async () => { | ||
await inventory.destroy(); | ||
const currentStock = await new GetCurrentStock(tenantDatabase, { | ||
item, | ||
date: new Date('2022-03-01'), | ||
warehouseId: warehouse.id, | ||
useDna: true, | ||
options: { | ||
productionNumber: '001', | ||
expiryDate: new Date('2022-03-01'), | ||
}, | ||
}).call(); | ||
|
||
expect(currentStock).toEqual(0); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters