salix/back/methods/campaign/spec/latest.spec.js

29 lines
1.0 KiB
JavaScript
Raw Normal View History

2023-01-24 08:04:43 +00:00
const models = require('vn-loopback/server/server').models;
2020-10-05 06:50:07 +00:00
describe('campaign latest()', () => {
it('should return the campaigns from the last year', async() => {
2023-01-16 14:18:24 +00:00
const now = Date.vnNew();
2023-01-24 08:04:43 +00:00
const result = await 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() => {
2023-01-16 14:18:24 +00:00
const now = Date.vnNew();
2020-11-11 13:32:53 +00:00
const currentYear = now.getFullYear();
2023-01-24 08:04:43 +00:00
const result = await models.Campaign.latest({
2020-10-05 12:45:39 +00:00
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
});