2020-10-05 06:50:07 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
|
|
|
|
|
|
|
describe('campaign latest()', () => {
|
|
|
|
it('should return the campaigns from the last year', async() => {
|
2020-11-11 13:32:53 +00:00
|
|
|
const now = new Date();
|
|
|
|
const result = await app.models.Campaign.latest();
|
2020-10-05 12:45:39 +00:00
|
|
|
const randomIndex = Math.floor(Math.random() * result.length);
|
|
|
|
const campaignDated = result[randomIndex].dated;
|
2020-10-05 06:50:07 +00:00
|
|
|
|
2020-10-05 12:45:39 +00:00
|
|
|
expect(result.length).toEqual(3);
|
2020-11-11 13:32:53 +00:00
|
|
|
expect(campaignDated).toBeLessThanOrEqual(now);
|
2020-10-05 06:50:07 +00:00
|
|
|
});
|
2020-10-05 12:45:39 +00:00
|
|
|
|
|
|
|
it('should return the campaigns from the current year', async() => {
|
2020-11-11 13:32:53 +00:00
|
|
|
const now = new Date();
|
|
|
|
const currentYear = now.getFullYear();
|
2020-10-05 12:45:39 +00:00
|
|
|
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);
|
|
|
|
});
|
2020-10-05 06:50:07 +00:00
|
|
|
});
|