Requested changes
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-10-05 14:45:39 +02:00
parent 86025b88e3
commit 71e29e747a
8 changed files with 66 additions and 41 deletions

View File

@ -2,17 +2,33 @@ const app = require('vn-loopback/server/server');
describe('campaign latest()', () => { describe('campaign latest()', () => {
it('should return the campaigns from the last year', async() => { it('should return the campaigns from the last year', async() => {
let response = await app.models.Campaign.latest(); let result = await app.models.Campaign.latest();
const lastYearDate = new Date(); const lastYearDate = new Date();
lastYearDate.setFullYear(lastYearDate.getFullYear() - 1); lastYearDate.setFullYear(lastYearDate.getFullYear() - 1);
const lastYear = lastYearDate.getFullYear(); const lastYear = lastYearDate.getFullYear();
const randomIndex = Math.floor(Math.random() * 3); const randomIndex = Math.floor(Math.random() * result.length);
const campaignDated = response[randomIndex].dated; const campaignDated = result[randomIndex].dated;
const campaignYear = campaignDated.getFullYear(); const campaignYear = campaignDated.getFullYear();
expect(response.length).toEqual(3); expect(result.length).toEqual(3);
expect(campaignYear).toEqual(lastYear); 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);
});
}); });

View File

@ -15,16 +15,15 @@ module.exports = Self => {
Self.upcoming = async() => { Self.upcoming = async() => {
const minDate = new Date(); const minDate = new Date();
minDate.setMonth(0); minDate.setFullYear(minDate.getFullYear() - 1);
minDate.setDate(1);
return Self.findOne({ return Self.findOne({
where: { where: {
dated: { dated: {
lt: minDate gte: minDate
} }
}, },
order: 'dated DESC' order: 'dated ASC'
}); });
}; };
}; };

View File

@ -208,9 +208,6 @@ export default class Autocomplete extends Field {
} }
this.input.value = display; this.input.value = display;
/* if (this.translateFields.indexOf(this.showField) > -1)
this.input.value = this.$t(display); */
} }
} }

View File

@ -59,7 +59,7 @@
ng-model="filter.campaign" ng-model="filter.campaign"
order="dated DESC" order="dated DESC"
selection="$ctrl.campaignSelection" selection="$ctrl.campaignSelection"
search-function="{or: [{dated: {like: '%'+ $search +'%'}}]}"> search-function="{dated: {like: '%'+ $search +'%'}}">
<tpl-item> <tpl-item>
{{code}} {{dated | date: 'yyyy'}} {{code}} {{dated | date: 'yyyy'}}
</tpl-item> </tpl-item>

View File

@ -17,7 +17,7 @@ describe('Client', () => {
})); }));
describe('getUpcomingCampaing()', () => { describe('getUpcomingCampaing()', () => {
it(`should make an HTTP GET query`, () => { it(`should make an HTTP query and then set the campaign property`, () => {
$httpBackend.expect('GET', 'Campaigns/upcoming').respond(200, {id: 2, code: 'allSaints'}); $httpBackend.expect('GET', 'Campaigns/upcoming').respond(200, {id: 2, code: 'allSaints'});
controller.getUpcomingCampaing(); controller.getUpcomingCampaing();
$httpBackend.flush(); $httpBackend.flush();

View File

@ -3,12 +3,6 @@ const LoopBackContext = require('loopback-context');
describe('Worker createAbsence()', () => { describe('Worker createAbsence()', () => {
const workerId = 18; const workerId = 18;
let createdAbsence;
afterAll(async() => {
const absence = await app.models.Calendar.findById(createdAbsence.id);
await absence.destroy();
});
it('should return an error for a user without enough privileges', async() => { it('should return an error for a user without enough privileges', async() => {
const ctx = {req: {accessToken: {userId: 18}}}; const ctx = {req: {accessToken: {userId: 18}}};
@ -40,12 +34,15 @@ describe('Worker createAbsence()', () => {
const absenceTypeId = 1; const absenceTypeId = 1;
const dated = new Date(); const dated = new Date();
createdAbsence = await app.models.Worker.createAbsence(ctx, workerId, absenceTypeId, dated); const createdAbsence = await app.models.Worker.createAbsence(ctx, workerId, absenceTypeId, dated);
const expectedBusinessId = 18; const expectedBusinessId = 18;
const expectedAbsenceTypeId = 1; const expectedAbsenceTypeId = 1;
expect(createdAbsence.businessFk).toEqual(expectedBusinessId); expect(createdAbsence.businessFk).toEqual(expectedBusinessId);
expect(createdAbsence.dayOffTypeFk).toEqual(expectedAbsenceTypeId); expect(createdAbsence.dayOffTypeFk).toEqual(expectedAbsenceTypeId);
// Restores
await app.models.Calendar.destroyById(createdAbsence.id);
}); });
}); });

View File

@ -2,29 +2,35 @@ const app = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context'); const LoopBackContext = require('loopback-context');
describe('Worker deleteAbsence()', () => { describe('Worker deleteAbsence()', () => {
const businessId = 18;
const workerId = 18; const workerId = 18;
let createdAbsence;
const activeCtx = { const activeCtx = {
accessToken: {userId: 19}, accessToken: {userId: 106},
headers: {origin: 'http://localhost'} headers: {origin: 'http://localhost'}
}; };
const ctx = {req: activeCtx}; const ctx = {req: activeCtx};
ctx.req.__ = value => { ctx.req.__ = value => {
return value; return value;
}; };
let createdAbsence;
it('should return an error for a user without enough privileges', async() => { beforeEach(async() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx active: activeCtx
}); });
activeCtx.accessToken.userId = 106;
const businessId = 18;
createdAbsence = await app.models.Calendar.create({ createdAbsence = await app.models.Calendar.create({
businessFk: businessId, businessFk: businessId,
dayOffTypeFk: 1, dayOffTypeFk: 1,
dated: new Date() dated: new Date()
}); });
});
afterEach(async() => {
await app.models.Calendar.destroyById(createdAbsence.id);
});
it('should return an error for a user without enough privileges', async() => {
activeCtx.accessToken.userId = 106;
let error; let error;
await app.models.Worker.deleteAbsence(ctx, 18, createdAbsence.id).catch(e => { await app.models.Worker.deleteAbsence(ctx, 18, createdAbsence.id).catch(e => {
@ -37,12 +43,7 @@ describe('Worker deleteAbsence()', () => {
}); });
it('should create a new absence', async() => { it('should create a new absence', async() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
activeCtx.accessToken.userId = 19; activeCtx.accessToken.userId = 19;
const businessId = 18;
expect(createdAbsence.businessFk).toEqual(businessId); expect(createdAbsence.businessFk).toEqual(businessId);

View File

@ -1,22 +1,37 @@
const app = require('vn-loopback/server/server'); const app = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context');
describe('Worker updateAbsence()', () => { describe('Worker updateAbsence()', () => {
const workerId = 106; const workerId = 106;
const businessId = 106;
const activeCtx = {
accessToken: {userId: 106},
headers: {origin: 'http://localhost'}
};
const ctx = {req: activeCtx};
ctx.req.__ = value => {
return value;
};
let createdAbsence; let createdAbsence;
afterAll(async() => { beforeEach(async() => {
const absence = await app.models.Calendar.findById(createdAbsence.id); spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
await absence.destroy(); active: activeCtx
}); });
it('should return an error for a user without enough privileges', async() => {
const ctx = {req: {accessToken: {userId: 106}}};
const expectedAbsenceTypeId = 2;
createdAbsence = await app.models.Calendar.create({ createdAbsence = await app.models.Calendar.create({
businessFk: 106, businessFk: businessId,
dayOffTypeFk: 1, dayOffTypeFk: 1,
dated: new Date() dated: new Date()
}); });
});
afterEach(async() => {
await app.models.Calendar.destroyById(createdAbsence.id);
});
it('should return an error for a user without enough privileges', async() => {
activeCtx.accessToken.userId = 106;
const expectedAbsenceTypeId = 2;
let error; let error;
await app.models.Worker.updateAbsence(ctx, workerId, createdAbsence.id, expectedAbsenceTypeId).catch(e => { await app.models.Worker.updateAbsence(ctx, workerId, createdAbsence.id, expectedAbsenceTypeId).catch(e => {
@ -29,7 +44,7 @@ describe('Worker updateAbsence()', () => {
}); });
it('should create a new absence', async() => { it('should create a new absence', async() => {
const ctx = {req: {accessToken: {userId: 37}}}; activeCtx.accessToken.userId = 37;
const expectedAbsenceTypeId = 2; const expectedAbsenceTypeId = 2;
const updatedAbsence = await app.models.Worker.updateAbsence(ctx, workerId, createdAbsence.id, expectedAbsenceTypeId); const updatedAbsence = await app.models.Worker.updateAbsence(ctx, workerId, createdAbsence.id, expectedAbsenceTypeId);