UNPKG

purespectrum-lib

Version:

shared code between front and backend projects

77 lines 4.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var allocation_1 = require("./allocation"); var allocationMocks_1 = require("../mock/allocationMocks"); describe('Allocations Evenly Distribution', function () { it('should distribute 200 complete evenly between the suppliers', function () { var allocation = allocation_1.AllocationFactory.allocation(allocationMocks_1.suppliersMock, 200, allocation_1.Blend.empty(), true, 0); expect(allocation.quantity(1)).toEqual(50); expect(allocation.percentage(1)).toEqual(25); expect(allocation.quantity(2)).toEqual(50); expect(allocation.percentage(1)).toEqual(25); expect(allocation.quantity(3)).toEqual(50); expect(allocation.percentage(1)).toEqual(25); expect(allocation.quantity(4)).toEqual(50); expect(allocation.percentage(1)).toEqual(25); }); it('should distribute 401 complete evenly between the suppliers', function () { var allocation = allocation_1.AllocationFactory.allocation(allocationMocks_1.suppliersMock, 401, allocation_1.Blend.empty(), true, 0); expect(allocation.quantity(1)).toEqual(101); expect(allocation.percentage(1)).toEqual(25); expect(allocation.quantity(2)).toEqual(100); expect(allocation.percentage(1)).toEqual(25); expect(allocation.quantity(3)).toEqual(100); expect(allocation.percentage(1)).toEqual(25); expect(allocation.quantity(4)).toEqual(100); expect(allocation.percentage(1)).toEqual(25); }); it('should allocate 1 for all suppliers when we distribute 1 complete', function () { var allocation = allocation_1.AllocationFactory.allocation(allocationMocks_1.suppliersMock, 1, allocation_1.Blend.empty(), true, 0); expect(allocation.quantity(1)).toEqual(1); expect(allocation.percentage(1)).toEqual(100); expect(allocation.quantity(2)).toEqual(1); expect(allocation.percentage(1)).toEqual(100); expect(allocation.quantity(3)).toEqual(1); expect(allocation.percentage(1)).toEqual(100); expect(allocation.quantity(4)).toEqual(1); expect(allocation.percentage(1)).toEqual(100); }); }); describe('Allocations Blend Distribution', function () { it('should distribute 200 complete evenly between the suppliers', function () { var allocation = allocation_1.AllocationFactory.allocation(allocationMocks_1.suppliersMock, 200, allocationMocks_1.blendMock, true, 0); expect(allocation.quantity(1)).toEqual(100); expect(allocation.percentage(1)).toEqual(50); expect(allocation.quantity(2)).toEqual(100); expect(allocation.percentage(2)).toEqual(50); expect(allocation.quantity(3)).toEqual(50); expect(allocation.percentage(3)).toEqual(25); expect(allocation.quantity(4)).toEqual(50); expect(allocation.percentage(4)).toEqual(25); }); }); //When Suppliers has a quantity and we want to add more //This is used in CPI Dropdown Menu for distribution of the quantity from the suppliers removed(unchecked). describe('Allocations Additional Distribution', function () { it('should distribute 50 completes between the suppliers evenly', function () { console.log('testei'); var allocation = allocation_1.AllocationFactory.allocation(allocationMocks_1.suppliersMock, 200, allocation_1.Blend.empty(), false, 50); expect(allocation.quantity(1)).toEqual(13); expect(allocation.quantity(2)).toEqual(13); expect(allocation.quantity(3)).toEqual(12); expect(allocation.quantity(4)).toEqual(12); }); it('should distribute 50 completes between the suppliers that already have completes evenly', function () { console.log('testei'); var allocation = allocation_1.AllocationFactory.allocation(allocationMocks_1.suppliersWithQuantityMock, 200, allocation_1.Blend.empty(), false, 50); expect(allocation.quantity(1)).toEqual(18); expect(allocation.quantity(2)).toEqual(16); expect(allocation.quantity(3)).toEqual(14); expect(allocation.quantity(4)).toEqual(13); }); it('should select a blend from an API response', function () { var blend = allocation_1.Blend.getBlendFromGetSupplierBlendInterface('sb5ac91a8bbc', allocationMocks_1.blendsListResponseMock); expect(blend.id).toEqual('sb5ac91a8bbc'); }); }); //# sourceMappingURL=allocation.spec.js.map