Requested changes
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
86025b88e3
commit
71e29e747a
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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'
|
||||
});
|
||||
};
|
||||
};
|
||||
|
|
|
@ -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); */
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 +'%'}}">
|
||||
<tpl-item>
|
||||
{{code}} {{dated | date: 'yyyy'}}
|
||||
</tpl-item>
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
beforeEach(async() => {
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||
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({
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue