front and back test

This commit is contained in:
Bernat Exposito Domenech 2020-09-09 08:20:27 +02:00
parent d79cffb2c3
commit f99fb69d48
4 changed files with 94 additions and 31 deletions

View File

@ -1,7 +1,7 @@
import selectors from '../../helpers/selectors.js';
import getBrowser from '../../helpers/puppeteer';
describe('Zone descriptor path', () => {
fdescribe('Zone descriptor path', () => {
let browser;
let page;

View File

@ -0,0 +1,17 @@
const app = require('vn-loopback/server/server');
describe('ticket freightPorts()', () => {
it('should return the freight cost of a given ticket', async() => {
let ticketId = 7;
let freightCost = await app.models.Ticket.freightPorts(ticketId);
expect(freightCost).toBe(4);
});
it('should return null if the ticket does not exist', async() => {
let ticketId = 99;
let freightCost = await app.models.Ticket.freightPorts(ticketId);
expect(freightCost).toBeNull();
});
});

View File

@ -1,18 +1,18 @@
const app = require('vn-loopback/server/server');
fdescribe('ticket getComponentsSum()', () => {
it('should get the list of component of their sales of a given ticket', async() => {
describe('ticket getComponentsSum()', () => {
it('should get the list of component for the ticket sales', async() => {
let ticketId = 7;
let mana = await app.models.Ticket.getComponentsSum(ticketId);
let components = await app.models.Ticket.getComponentsSum(ticketId);
expect(mana.length).toBeGreaterThan(0);
expect(mana[0].componentFk).toBe(22);
expect(components.length).toBeGreaterThan(0);
expect(components[0].componentFk).toBe(22);
});
it('should return 0 if the given ticket does not have sales', async() => {
let ticketWithoutSales = 21;
let mana = await app.models.Ticket.getComponentsSum(ticketWithoutSales);
let components = await app.models.Ticket.getComponentsSum(ticketWithoutSales);
expect(mana.length).toEqual(0);
expect(components.length).toEqual(0);
});
});

View File

@ -4,76 +4,72 @@ import crudModel from 'core/mocks/crud-model';
describe('ticket', () => {
describe('Component vnTicketComponents', () => {
let controller;
let $httpBackend;
beforeEach(ngModule('ticket'));
beforeEach(inject(($componentController, $rootScope, $state) => {
beforeEach(inject(($componentController, $rootScope, $state, _$httpBackend_) => {
$state.params.id = '1';
let $scope = $rootScope.$new();
$httpBackend = _$httpBackend_;
$scope.model = crudModel;
$scope.model.data = [{
quantity: 1,
components: [
{
value: 5,
component: {
name: 'valor de compra',
componentType: {
isBase: 1
}
},
value: 5
}
},
{
value: 5,
component: {
name: 'reparto',
componentType: {
isBase: 0
}
},
value: 5
}
},
{
value: 5,
component: {
name: 'recobro',
componentType: {
isBase: 0
}
},
value: 5
}
}
],
quantity: 1
]
},
{
quantity: 5,
components: [
{
value: 1,
component: {
name: 'valor de compra',
componentType: {
isBase: 1
}
},
value: 1
}
},
{
value: 1,
component: {
name: 'reparto',
componentType: {
isBase: 0
}
},
value: 1
}
},
{
value: 1,
component: {
name: 'recobro',
componentType: {
isBase: 0
}
},
value: 1
}
},
],
quantity: 5
]
}];
const $element = angular.element('<vn-ticket-components></vn-ticket-components>');
controller = $componentController('vnTicketComponents', {$element, $scope});
@ -86,5 +82,55 @@ describe('ticket', () => {
expect(result).toEqual(10);
});
});
describe('ticket setter', () => {
it('should set the ticket data and then call getTheoricalPorts() and getComponentsSum()', () => {
jest.spyOn(controller, 'getTheoricalPorts');
jest.spyOn(controller, 'getComponentsSum');
controller._ticket = undefined;
controller.ticket = {
id: 7
};
expect(controller.ticket).toBeDefined();
expect(controller.getTheoricalPorts).toHaveBeenCalledWith();
expect(controller.getComponentsSum).toHaveBeenCalledWith();
});
});
describe('getTotal()', () => {
it('should return the total sum of a ticket', () => {
let result = controller.getTotal();
expect(result).toEqual(30);
});
});
describe('getTheoricalPorts()', () => {
it('should make a request to get the theorical port of a ticket', () => {
controller._ticket = {
id: 7
};
$httpBackend.expect('GET', `Tickets/${controller._ticket.id}/freightPorts`).respond('My freight port');
controller.getTheoricalPorts();
$httpBackend.flush();
expect(controller.theoricalPorts).toBe('My freight port');
});
});
describe('getComponentsSum()', () => {
it('should make a request to get the component list', () => {
controller._ticket = {
id: 7
};
$httpBackend.expect('GET', `Tickets/${controller._ticket.id}/getComponentsSum`).respond('My component list');
controller.getComponentsSum();
$httpBackend.flush();
expect(controller.componentsList).toBe('My component list');
});
});
});
});