Added unit tests
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
cdde4d95d7
commit
e3b14405b7
|
@ -0,0 +1,18 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('campaign latest()', () => {
|
||||
it('should return the campaigns from the last year', async() => {
|
||||
let response = await app.models.Campaign.latest();
|
||||
|
||||
const lastYearDate = new Date();
|
||||
lastYearDate.setFullYear(lastYearDate.getFullYear() - 1);
|
||||
const lastYear = lastYearDate.getFullYear();
|
||||
|
||||
const randomIndex = Math.floor(Math.random() * 3);
|
||||
const campaignDated = response[randomIndex].dated;
|
||||
const campaignYear = campaignDated.getFullYear();
|
||||
|
||||
expect(response.length).toEqual(3);
|
||||
expect(campaignYear).toEqual(lastYear);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,16 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('campaign upcoming()', () => {
|
||||
it('should return the upcoming campaign but from the last year', async() => {
|
||||
let response = await app.models.Campaign.upcoming();
|
||||
|
||||
const lastYearDate = new Date();
|
||||
lastYearDate.setFullYear(lastYearDate.getFullYear() - 1);
|
||||
const lastYear = lastYearDate.getFullYear();
|
||||
|
||||
const campaignDated = response.dated;
|
||||
const campaignYear = campaignDated.getFullYear();
|
||||
|
||||
expect(campaignYear).toEqual(lastYear);
|
||||
});
|
||||
});
|
|
@ -5,10 +5,13 @@ class Controller extends SearchPanel {
|
|||
constructor($, $element) {
|
||||
super($, $element);
|
||||
|
||||
this.getUpcomingCampaing();
|
||||
}
|
||||
|
||||
getUpcomingCampaing() {
|
||||
this.$http.get('Campaigns/upcoming').then(res => {
|
||||
const filter = this.$.filter;
|
||||
filter.campaign = res.data.id;
|
||||
console.log(res.data);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
import './index.js';
|
||||
|
||||
describe('Client', () => {
|
||||
describe('Component vnConsumptionSearchPanel', () => {
|
||||
let $httpBackend;
|
||||
let $element;
|
||||
let controller;
|
||||
|
||||
beforeEach(ngModule('client'));
|
||||
|
||||
beforeEach(inject(($componentController, _$httpBackend_) => {
|
||||
$httpBackend = _$httpBackend_;
|
||||
$element = angular.element(`<div></div>`);
|
||||
controller = $componentController('vnConsumptionSearchPanel', {$element});
|
||||
controller.$.filter = {};
|
||||
$httpBackend.expect('GET', 'Campaigns/upcoming').respond(200, {id: 1});
|
||||
}));
|
||||
|
||||
describe('getUpcomingCampaing()', () => {
|
||||
it(`should make an HTTP GET query`, () => {
|
||||
$httpBackend.expect('GET', 'Campaigns/upcoming').respond(200, {id: 2, code: 'allSaints'});
|
||||
controller.getUpcomingCampaing();
|
||||
$httpBackend.flush();
|
||||
|
||||
const filter = controller.$.filter;
|
||||
|
||||
expect(filter.campaign).toEqual(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue