35 lines
1.2 KiB
JavaScript
35 lines
1.2 KiB
JavaScript
const app = require('vn-loopback/server/server');
|
|
|
|
describe('campaign latest()', () => {
|
|
it('should return the campaigns from the last year', async() => {
|
|
let result = await app.models.Campaign.latest();
|
|
|
|
const lastYearDate = new Date();
|
|
lastYearDate.setFullYear(lastYearDate.getFullYear() - 1);
|
|
const lastYear = lastYearDate.getFullYear();
|
|
|
|
const randomIndex = Math.floor(Math.random() * result.length);
|
|
const campaignDated = result[randomIndex].dated;
|
|
const campaignYear = campaignDated.getFullYear();
|
|
|
|
expect(result.length).toEqual(3);
|
|
expect(campaignYear).toEqual(lastYear);
|
|
});
|
|
|
|
it('should return the campaigns from the current year', async() => {
|
|
const currentDate = new Date();
|
|
const currentYear = currentDate.getFullYear();
|
|
|
|
const result = await app.models.Campaign.latest({
|
|
where: {dated: {like: `%${currentYear}%`}}
|
|
});
|
|
|
|
const randomIndex = Math.floor(Math.random() * result.length);
|
|
const campaignDated = result[randomIndex].dated;
|
|
const campaignYear = campaignDated.getFullYear();
|
|
|
|
expect(result.length).toEqual(3);
|
|
expect(campaignYear).toEqual(currentYear);
|
|
});
|
|
});
|