2021-03-09 09:01:40 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('Entry', () => {
|
|
|
|
describe('Component vnEntryBuyImport', () => {
|
|
|
|
let controller;
|
|
|
|
let $httpParamSerializer;
|
|
|
|
let $httpBackend;
|
|
|
|
|
|
|
|
beforeEach(ngModule('entry'));
|
|
|
|
|
|
|
|
beforeEach(angular.mock.inject(($componentController, $compile, $rootScope, _$httpParamSerializer_, _$httpBackend_) => {
|
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$httpParamSerializer = _$httpParamSerializer_;
|
|
|
|
let $element = $compile('<vn-entry-buy-import-buys></vn-entry-latest-buys')($rootScope);
|
|
|
|
controller = $componentController('vnEntryBuyImport', {$element});
|
|
|
|
controller.entry = {
|
|
|
|
id: 1
|
|
|
|
};
|
2021-04-28 20:56:02 +00:00
|
|
|
controller.$params = {id: 1};
|
2021-03-09 09:01:40 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('fillData()', () => {
|
|
|
|
it(`should call to the fillData() method`, () => {
|
|
|
|
controller.fetchBuys = jest.fn();
|
|
|
|
|
|
|
|
const rawData = `{
|
|
|
|
"invoices": [
|
|
|
|
{
|
|
|
|
"tx_awb": "123456",
|
|
|
|
"boxes": [
|
|
|
|
{
|
|
|
|
"id_box": 1,
|
|
|
|
"nu_length": 1,
|
|
|
|
"nu_width": 15,
|
|
|
|
"nu_height": 80,
|
|
|
|
"products": [
|
|
|
|
{
|
|
|
|
"nm_product": "Bow",
|
|
|
|
"nu_length": 1,
|
|
|
|
"nu_stems_bunch": 1,
|
|
|
|
"nu_bunches": 1,
|
|
|
|
"mny_rate_stem": 5.77
|
|
|
|
}
|
|
|
|
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id_box": 2,
|
|
|
|
"nu_length": 25,
|
|
|
|
"nu_width": 1,
|
|
|
|
"nu_height": 45,
|
|
|
|
"products": [
|
|
|
|
{
|
|
|
|
"nm_product": "Arrow",
|
|
|
|
"nu_length": 25,
|
|
|
|
"nu_stems_bunch": 1,
|
|
|
|
"nu_bunches": 1,
|
|
|
|
"mny_rate_stem": 2.16
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]}`;
|
|
|
|
const expectedBuys = [
|
2021-11-11 16:18:19 +00:00
|
|
|
{
|
|
|
|
'buyingValue': 5.77,
|
|
|
|
'description': 'Bow',
|
|
|
|
'grouping': 1,
|
|
|
|
'packing': 1,
|
|
|
|
'size': 1,
|
|
|
|
'volume': 1200},
|
|
|
|
|
|
|
|
{
|
|
|
|
'buyingValue': 2.16,
|
|
|
|
'description': 'Arrow',
|
|
|
|
'grouping': 1,
|
|
|
|
'packing': 1,
|
|
|
|
'size': 25,
|
|
|
|
'volume': 1125}
|
2021-03-09 09:01:40 +00:00
|
|
|
];
|
|
|
|
controller.fillData(rawData);
|
|
|
|
controller.$.$apply();
|
|
|
|
|
|
|
|
const importData = controller.import;
|
|
|
|
|
|
|
|
expect(importData.observation).toEqual('123456');
|
|
|
|
expect(importData.ref).toEqual('1, 2');
|
|
|
|
|
|
|
|
expect(controller.fetchBuys).toHaveBeenCalledWith(expectedBuys);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fetchBuys()', () => {
|
|
|
|
it(`should perform a query to fetch the buys data`, () => {
|
|
|
|
const buys = [
|
2021-11-11 16:18:19 +00:00
|
|
|
{
|
|
|
|
'buyingValue': 5.77,
|
|
|
|
'description': 'Bow',
|
|
|
|
'grouping': 1,
|
|
|
|
'packing': 1,
|
|
|
|
'size': 1,
|
|
|
|
'volume': 1200},
|
|
|
|
|
|
|
|
{
|
|
|
|
'buyingValue': 2.16,
|
|
|
|
'description': 'Arrow',
|
|
|
|
'grouping': 1,
|
|
|
|
'packing': 1,
|
|
|
|
'size': 25,
|
|
|
|
'volume': 1125}
|
2021-03-09 09:01:40 +00:00
|
|
|
];
|
|
|
|
|
2022-09-13 08:27:17 +00:00
|
|
|
const query = `Entries/1/importBuysPreview`;
|
|
|
|
$httpBackend.expectPOST(query).respond(200, buys);
|
2021-03-09 09:01:40 +00:00
|
|
|
controller.fetchBuys(buys);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
const importData = controller.import;
|
|
|
|
|
|
|
|
expect(importData.buys.length).toEqual(2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onSubmit()', () => {
|
2021-03-12 07:45:41 +00:00
|
|
|
it(`should throw an error when some of the rows doesn't have an item`, () => {
|
|
|
|
jest.spyOn(controller.vnApp, 'showError');
|
|
|
|
|
|
|
|
controller.import = {
|
|
|
|
observation: '123456',
|
|
|
|
ref: '1, 2',
|
|
|
|
buys: [
|
2021-11-11 16:18:19 +00:00
|
|
|
{
|
|
|
|
'buyingValue': 5.77,
|
|
|
|
'description': 'Bow',
|
|
|
|
'grouping': 1,
|
|
|
|
'packing': 1,
|
|
|
|
'size': 1,
|
|
|
|
'volume': 1200},
|
|
|
|
{
|
|
|
|
'buyingValue': 2.16,
|
|
|
|
'description': 'Arrow',
|
|
|
|
'grouping': 1,
|
|
|
|
'packing': 1,
|
|
|
|
'size': 25,
|
|
|
|
'volume': 1125}
|
2021-03-12 07:45:41 +00:00
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
controller.onSubmit();
|
|
|
|
|
2021-11-11 16:18:19 +00:00
|
|
|
const message = `Some of the imported buys doesn't have an item`;
|
|
|
|
|
|
|
|
expect(controller.vnApp.showError).toHaveBeenCalledWith(message);
|
2021-03-12 07:45:41 +00:00
|
|
|
});
|
|
|
|
|
2021-11-11 16:18:19 +00:00
|
|
|
it(`should now perform a query to update columns`, () => {
|
2021-03-09 09:01:40 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
2021-03-09 12:39:22 +00:00
|
|
|
controller.$state.go = jest.fn();
|
2021-03-09 09:01:40 +00:00
|
|
|
|
|
|
|
controller.import = {
|
|
|
|
observation: '123456',
|
|
|
|
ref: '1, 2',
|
|
|
|
buys: [
|
2021-11-11 16:18:19 +00:00
|
|
|
{
|
|
|
|
'itemFk': 10,
|
|
|
|
'buyingValue': 5.77,
|
|
|
|
'description': 'Bow',
|
|
|
|
'grouping': 1,
|
|
|
|
'packing': 1,
|
|
|
|
'size': 1,
|
|
|
|
'volume': 1200},
|
|
|
|
{
|
|
|
|
'itemFk': 11,
|
|
|
|
'buyingValue': 2.16,
|
|
|
|
'description': 'Arrow',
|
|
|
|
'grouping': 1,
|
|
|
|
'packing': 1,
|
|
|
|
'size': 25,
|
|
|
|
'volume': 1125}
|
2021-03-09 09:01:40 +00:00
|
|
|
]
|
|
|
|
};
|
|
|
|
const params = controller.import;
|
|
|
|
|
2021-03-10 09:53:22 +00:00
|
|
|
const query = `Entries/1/importBuys`;
|
2021-03-09 09:01:40 +00:00
|
|
|
$httpBackend.expectPOST(query, params).respond(200, params.buys);
|
|
|
|
controller.onSubmit();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
const importData = controller.import;
|
|
|
|
|
|
|
|
expect(importData.buys.length).toEqual(2);
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
|
2021-03-09 12:39:22 +00:00
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('entry.card.buy.index');
|
2021-03-09 09:01:40 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|