Updated unit tests
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-03-03 15:03:54 +01:00
parent f16553ecba
commit 15bedc5f12
9 changed files with 194 additions and 24 deletions

View File

@ -64,5 +64,6 @@
"Sent units from ticket": "I sent *{{quantity}}* units of [{{concept}} (#{{itemId}})]({{{itemUrl}}}) to *\"{{nickname}}\"* coming from ticket id [#{{ticketId}}]({{{ticketUrl}}})", "Sent units from ticket": "I sent *{{quantity}}* units of [{{concept}} (#{{itemId}})]({{{itemUrl}}}) to *\"{{nickname}}\"* coming from ticket id [#{{ticketId}}]({{{ticketUrl}}})",
"Customs agent is required for a non UEE member": "Customs agent is required for a non UEE member", "Customs agent is required for a non UEE member": "Customs agent is required for a non UEE member",
"Incoterms is required for a non UEE member": "Incoterms is required for a non UEE member", "Incoterms is required for a non UEE member": "Incoterms is required for a non UEE member",
"Client checked as validated despite of duplication": "Client checked as validated despite of duplication from client id {{clientId}}" "Client checked as validated despite of duplication": "Client checked as validated despite of duplication from client id {{clientId}}",
"Landing cannot be lesser than shipment": "Landing cannot be lesser than shipment"
} }

View File

@ -53,9 +53,48 @@ describe('Client', () => {
}); });
}); });
describe('postcodeSelection() setter', () => { describe('town() setter', () => {
it(`should set the town, province and contry properties`, () => { it(`should set provinceId property`, () => {
controller.postcodeSelection = { controller.town = {
provinceFk: 1,
code: 46001,
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
},
postcodes: []
};
expect(controller.address.provinceId).toEqual(1);
});
it(`should set provinceId property and fill the postalCode if there's just one`, () => {
controller.town = {
provinceFk: 1,
code: 46001,
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
},
postcodes: [{code: '46001'}]
};
expect(controller.address.provinceId).toEqual(1);
expect(controller.address.postalCode).toEqual('46001');
});
});
describe('postcode() setter', () => {
it(`should set the town and province properties`, () => {
controller.postcode = {
townFk: 1, townFk: 1,
code: 46001, code: 46001,
town: { town: {
@ -73,7 +112,7 @@ describe('Client', () => {
}; };
expect(controller.address.city).toEqual('New York'); expect(controller.address.city).toEqual('New York');
expect(controller.address.provinceFk).toEqual(1); expect(controller.address.provinceId).toEqual(1);
}); });
}); });

View File

@ -45,8 +45,7 @@ export default class Controller extends Component {
const oldValue = this._town; const oldValue = this._town;
this._town = selection; this._town = selection;
if (!selection || oldValue === null || oldValue === undefined) if (!oldValue) return;
return;
const province = selection.province; const province = selection.province;
const postcodes = selection.postcodes; const postcodes = selection.postcodes;
@ -66,8 +65,7 @@ export default class Controller extends Component {
const oldValue = this._postcode; const oldValue = this._postcode;
this._postcode = selection; this._postcode = selection;
if (!selection || oldValue === null || oldValue === undefined) if (!oldValue) return;
return;
const town = selection.town; const town = selection.town;
const province = town.province; const province = town.province;

View File

@ -40,9 +40,63 @@ describe('Client', () => {
}); });
}); });
describe('postcodeSelection() setter', () => { describe('province() setter', () => {
it(`should set the town, province and contry properties`, () => { it(`should set countryFk property`, () => {
controller.postcodeSelection = { controller.province = {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
};
expect(controller.client.countryFk).toEqual(2);
});
});
describe('town() setter', () => {
it(`should set provinceFk property`, () => {
controller.town = {
provinceFk: 1,
code: 46001,
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
},
postcodes: []
};
expect(controller.client.provinceFk).toEqual(1);
});
it(`should set provinceFk property and fill the postalCode if there's just one`, () => {
controller.town = {
provinceFk: 1,
code: 46001,
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
},
postcodes: [{code: '46001'}]
};
expect(controller.client.provinceFk).toEqual(1);
expect(controller.client.postcode).toEqual('46001');
});
});
describe('postcode() setter', () => {
it(`should set the town, provinceFk and contryFk properties`, () => {
controller.postcode = {
townFk: 1, townFk: 1,
code: 46001, code: 46001,
town: { town: {

View File

@ -87,8 +87,7 @@ export default class Controller extends Component {
const oldValue = this._province; const oldValue = this._province;
this._province = selection; this._province = selection;
if (!selection || oldValue === undefined) if (!oldValue) return;
return;
const country = selection.country; const country = selection.country;
@ -104,8 +103,7 @@ export default class Controller extends Component {
const oldValue = this._town; const oldValue = this._town;
this._town = selection; this._town = selection;
if (!selection || oldValue === undefined) if (!oldValue) return;
return;
const province = selection.province; const province = selection.province;
const country = province.country; const country = province.country;
@ -126,11 +124,8 @@ export default class Controller extends Component {
set postcode(selection) { set postcode(selection) {
const oldValue = this._postcode; const oldValue = this._postcode;
this._postcode = selection; this._postcode = selection;
console.log(oldValue);
if (!selection || oldValue === undefined)
return;
console.log('setter'); if (!oldValue) return;
const town = selection.town; const town = selection.town;
const province = town.province; const province = town.province;

View File

@ -25,6 +25,10 @@ describe('Client', () => {
isEqualizated: false, isEqualizated: false,
isTaxDataChecked: false isTaxDataChecked: false
}; };
controller.province = {};
controller.town = {};
controller.postcode = {};
})); }));
describe('onSubmit()', () => { describe('onSubmit()', () => {
@ -107,5 +111,84 @@ describe('Client', () => {
$httpBackend.flush(); $httpBackend.flush();
}); });
}); });
describe('province() setter', () => {
it(`should set countryFk property`, () => {
controller.province = {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
};
expect(controller.client.countryFk).toEqual(2);
});
});
describe('town() setter', () => {
it(`should set provinceFk property`, () => {
controller.town = {
provinceFk: 1,
code: 46001,
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
},
postcodes: []
};
expect(controller.client.provinceFk).toEqual(1);
});
it(`should set provinceFk property and fill the postalCode if there's just one`, () => {
controller.town = {
provinceFk: 1,
code: 46001,
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
},
postcodes: [{code: '46001'}]
};
expect(controller.client.provinceFk).toEqual(1);
expect(controller.client.postcode).toEqual('46001');
});
});
describe('postcode() setter', () => {
it(`should set the town, provinceFk and contryFk properties`, () => {
controller.postcode = {
townFk: 1,
code: 46001,
town: {
id: 1,
name: 'New York',
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
}
}
};
expect(controller.client.city).toEqual('New York');
expect(controller.client.provinceFk).toEqual(1);
expect(controller.client.countryFk).toEqual(2);
});
});
}); });
}); });

View File

@ -15,7 +15,7 @@ describe('Client', () => {
controller.client = {id: 101}; controller.client = {id: 101};
})); }));
describe('onResponse()', () => { describe('onAccept()', () => {
it('should perform a POST query and show a success snackbar', () => { it('should perform a POST query and show a success snackbar', () => {
let params = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'}; let params = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'};
controller.data = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'}; controller.data = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'};
@ -24,7 +24,7 @@ describe('Client', () => {
$httpBackend.when('PATCH', `postcodes`, params).respond(200, params); $httpBackend.when('PATCH', `postcodes`, params).respond(200, params);
$httpBackend.expect('PATCH', `postcodes`, params).respond(params); $httpBackend.expect('PATCH', `postcodes`, params).respond(params);
controller.onResponse('accept'); controller.onAccept();
$httpBackend.flush(); $httpBackend.flush();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The postcode has been saved'); expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The postcode has been saved');

View File

@ -2,7 +2,7 @@ const UserError = require('vn-loopback/util/user-error');
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('createThermograph', { Self.remoteMethodCtx('createThermograph', {
description: 'Upload and attach a document', description: 'Creates a new travel thermograph',
accessType: 'WRITE', accessType: 'WRITE',
accepts: [{ accepts: [{
arg: 'id', arg: 'id',

View File

@ -2,7 +2,7 @@ const UserError = require('vn-loopback/util/user-error');
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('updateThermograph', { Self.remoteMethodCtx('updateThermograph', {
description: 'updates a file properties or file', description: 'Updates a travel thermograph',
accessType: 'WRITE', accessType: 'WRITE',
accepts: [{ accepts: [{
arg: 'id', arg: 'id',