diff --git a/back/methods/campaign/spec/latest.spec.js b/back/methods/campaign/spec/latest.spec.js index c76231ab2..b76e4fd0a 100644 --- a/back/methods/campaign/spec/latest.spec.js +++ b/back/methods/campaign/spec/latest.spec.js @@ -2,17 +2,33 @@ 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(); + 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() * 3); - const campaignDated = response[randomIndex].dated; + const randomIndex = Math.floor(Math.random() * result.length); + const campaignDated = result[randomIndex].dated; const campaignYear = campaignDated.getFullYear(); - expect(response.length).toEqual(3); + 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); + }); }); diff --git a/back/methods/campaign/upcoming.js b/back/methods/campaign/upcoming.js index cc9f7f910..cabb66705 100644 --- a/back/methods/campaign/upcoming.js +++ b/back/methods/campaign/upcoming.js @@ -15,16 +15,15 @@ module.exports = Self => { Self.upcoming = async() => { const minDate = new Date(); - minDate.setMonth(0); - minDate.setDate(1); + minDate.setFullYear(minDate.getFullYear() - 1); return Self.findOne({ where: { dated: { - lt: minDate + gte: minDate } }, - order: 'dated DESC' + order: 'dated ASC' }); }; }; diff --git a/front/core/components/autocomplete/index.js b/front/core/components/autocomplete/index.js index 742ad6f2a..18c277f06 100755 --- a/front/core/components/autocomplete/index.js +++ b/front/core/components/autocomplete/index.js @@ -208,9 +208,6 @@ export default class Autocomplete extends Field { } this.input.value = display; - - /* if (this.translateFields.indexOf(this.showField) > -1) - this.input.value = this.$t(display); */ } } diff --git a/modules/client/front/consumption-search-panel/index.html b/modules/client/front/consumption-search-panel/index.html index 0edb0b34a..f8d633c71 100644 --- a/modules/client/front/consumption-search-panel/index.html +++ b/modules/client/front/consumption-search-panel/index.html @@ -59,7 +59,7 @@ ng-model="filter.campaign" order="dated DESC" selection="$ctrl.campaignSelection" - search-function="{or: [{dated: {like: '%'+ $search +'%'}}]}"> + search-function="{dated: {like: '%'+ $search +'%'}}"> {{code}} {{dated | date: 'yyyy'}} diff --git a/modules/client/front/consumption-search-panel/index.spec.js b/modules/client/front/consumption-search-panel/index.spec.js index dfab07086..7209fe3c3 100644 --- a/modules/client/front/consumption-search-panel/index.spec.js +++ b/modules/client/front/consumption-search-panel/index.spec.js @@ -17,7 +17,7 @@ describe('Client', () => { })); 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'}); controller.getUpcomingCampaing(); $httpBackend.flush(); diff --git a/modules/worker/back/methods/worker/specs/createAbsence.spec.js b/modules/worker/back/methods/worker/specs/createAbsence.spec.js index 324dab99d..ace412890 100644 --- a/modules/worker/back/methods/worker/specs/createAbsence.spec.js +++ b/modules/worker/back/methods/worker/specs/createAbsence.spec.js @@ -3,12 +3,6 @@ const LoopBackContext = require('loopback-context'); describe('Worker createAbsence()', () => { 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() => { const ctx = {req: {accessToken: {userId: 18}}}; @@ -40,12 +34,15 @@ describe('Worker createAbsence()', () => { const absenceTypeId = 1; 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 expectedAbsenceTypeId = 1; expect(createdAbsence.businessFk).toEqual(expectedBusinessId); expect(createdAbsence.dayOffTypeFk).toEqual(expectedAbsenceTypeId); + + // Restores + await app.models.Calendar.destroyById(createdAbsence.id); }); }); diff --git a/modules/worker/back/methods/worker/specs/deleteAbsence.spec.js b/modules/worker/back/methods/worker/specs/deleteAbsence.spec.js index 2f72a8435..15bd854ed 100644 --- a/modules/worker/back/methods/worker/specs/deleteAbsence.spec.js +++ b/modules/worker/back/methods/worker/specs/deleteAbsence.spec.js @@ -2,29 +2,35 @@ const app = require('vn-loopback/server/server'); const LoopBackContext = require('loopback-context'); describe('Worker deleteAbsence()', () => { + const businessId = 18; const workerId = 18; - let createdAbsence; const activeCtx = { - accessToken: {userId: 19}, + accessToken: {userId: 106}, headers: {origin: 'http://localhost'} }; const ctx = {req: activeCtx}; ctx.req.__ = value => { return value; }; + let createdAbsence; - it('should return an error for a user without enough privileges', async() => { + beforeEach(async() => { spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ active: activeCtx }); - - activeCtx.accessToken.userId = 106; - const businessId = 18; createdAbsence = await app.models.Calendar.create({ businessFk: businessId, dayOffTypeFk: 1, 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; 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() => { - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); - activeCtx.accessToken.userId = 19; - const businessId = 18; expect(createdAbsence.businessFk).toEqual(businessId); diff --git a/modules/worker/back/methods/worker/specs/updateAbsence.spec.js b/modules/worker/back/methods/worker/specs/updateAbsence.spec.js index 1b34cf2e0..2ff8e64e1 100644 --- a/modules/worker/back/methods/worker/specs/updateAbsence.spec.js +++ b/modules/worker/back/methods/worker/specs/updateAbsence.spec.js @@ -1,22 +1,37 @@ const app = require('vn-loopback/server/server'); +const LoopBackContext = require('loopback-context'); describe('Worker updateAbsence()', () => { 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; - 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() => { - const ctx = {req: {accessToken: {userId: 106}}}; - const expectedAbsenceTypeId = 2; + beforeEach(async() => { + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx + }); createdAbsence = await app.models.Calendar.create({ - businessFk: 106, + businessFk: businessId, dayOffTypeFk: 1, 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; 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() => { - const ctx = {req: {accessToken: {userId: 37}}}; + activeCtx.accessToken.userId = 37; const expectedAbsenceTypeId = 2; const updatedAbsence = await app.models.Worker.updateAbsence(ctx, workerId, createdAbsence.id, expectedAbsenceTypeId);