5918-worker.time-control_resend #1685

Merged
alexm merged 14 commits from 5918-worker.time-control_resend into dev 2023-10-18 09:10:19 +00:00
2 changed files with 106 additions and 3 deletions
Showing only changes of commit d1cb2a1d9a - Show all commits

View File

@ -0,0 +1,103 @@
const models = require('vn-loopback/server/server').models;
describe('workerTimeControl getMailStates()', () => {
it('should update WorkerTimeControlMail if exist record', async() => {
const tx = await models.WorkerTimeControlMail.beginTransaction({});
const args = {
workerId: 9,
week: 50,
year: 2000,
state: 'CONFIRMED'
};
const ctx = {args};
try {
const options = {transaction: tx};
const beforeMail = await models.WorkerTimeControlMail.findOne({
where: {
workerFk: args.workerId,
year: args.year,
week: args.week,
}
}, options);
await models.WorkerTimeControl.updateWorkerTimeControlMail(ctx, options);
const afterMail = await models.WorkerTimeControlMail.findOne({
where: {
workerFk: args.workerId,
year: args.year,
week: args.week,
}
}, options);
expect(beforeMail.state).toEqual('SENDED');
expect(afterMail.state).toEqual(args.state);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should insert WorkerTimeControlMail if exist record', async() => {
const tx = await models.WorkerTimeControlMail.beginTransaction({});
const args = {
workerId: 1,
week: 51,
year: 2000,
state: 'SENDED'
};
const ctx = {args};
try {
const options = {transaction: tx};
const beforeMail = await models.WorkerTimeControlMail.find({
where: {
workerFk: args.workerId,
year: args.year,
week: args.week,
}
}, options);
await models.WorkerTimeControl.updateWorkerTimeControlMail(ctx, options);
const afterMail = await models.WorkerTimeControlMail.find({
where: {
workerFk: args.workerId,
year: args.year,
week: args.week,
}
}, options);
expect(beforeMail).toEqual([]);
expect(afterMail.length).toEqual(1);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should throw error if not exist any record in this week', async() => {
const tx = await models.WorkerTimeControlMail.beginTransaction({});
const ctx = {args: {
workerId: 1,
week: 1,
year: 0,
state: 'SENDED'
}};
let error;
try {
const options = {transaction: tx};
await models.WorkerTimeControl.updateWorkerTimeControlMail(ctx, options);
await tx.rollback();
} catch (e) {
await tx.rollback();
error = e;
}
expect(error.message).toEqual(`There aren't records for this week`);
});
});

View File

@ -98,11 +98,11 @@
ng-click="reason.show()"> ng-click="reason.show()">
</vn-button> </vn-button>
<vn-button <vn-button
label="Resend" label="{{$ctrl.state ? 'Resend' : 'Send'}}"
ng-click="sendEmailConfirmation.show()" ng-click="sendEmailConfirmation.show()"
class="right" class="right"
vn-tooltip="Resend email of this week to the user" vn-tooltip="{{$ctrl.state ? 'Resend' : 'Send'}} email of this week to the user"
ng-show="$ctrl.isHr && $ctrl.state != 'CONFIRMED' && $ctrl.canResend"> ng-if="$ctrl.isHr && $ctrl.state != 'CONFIRMED' && $ctrl.canResend">
</vn-button> </vn-button>
</vn-button-bar> </vn-button-bar>
</div> </div>