|
1 | 1 | const Sinon = require("sinon");
|
2 |
| -const { getTasksValidator, createTask, getUsersValidator } = require("../../../middlewares/validators/tasks"); |
| 2 | +const { |
| 3 | + getTasksValidator, |
| 4 | + createTask, |
| 5 | + getUsersValidator, |
| 6 | + updateTask: updateTaskValidator, |
| 7 | +} = require("../../../middlewares/validators/tasks"); |
3 | 8 | const { expect } = require("chai");
|
4 | 9 | const { TASK_STATUS, tasksUsersStatus } = require("../../../constants/tasks");
|
5 | 10 |
|
@@ -521,6 +526,97 @@ describe("getTasks validator", function () {
|
521 | 526 | expect(nextMiddlewareSpy.callCount).to.be.equal(0);
|
522 | 527 | });
|
523 | 528 |
|
| 529 | + it("should call nextMiddlewareSpy for updateTaskValidator if startedOn is null", async function () { |
| 530 | + const req = { |
| 531 | + body: { |
| 532 | + startedOn: null, |
| 533 | + endsOn: new Date().getTime(), |
| 534 | + }, |
| 535 | + }; |
| 536 | + const res = { boom: { badRequest: Sinon.spy() } }; |
| 537 | + const nextMiddlewareSpy = Sinon.spy(); |
| 538 | + await updateTaskValidator(req, res, nextMiddlewareSpy); |
| 539 | + expect(nextMiddlewareSpy.callCount).to.be.equal(1); |
| 540 | + }); |
| 541 | + |
| 542 | + it("should call nextMiddlewareSpy for updateTaskValidator if endsOn is null", async function () { |
| 543 | + const req = { |
| 544 | + body: { |
| 545 | + startedOn: new Date().getTime(), |
| 546 | + endsOn: null, |
| 547 | + }, |
| 548 | + }; |
| 549 | + const res = { boom: { badRequest: Sinon.spy() } }; |
| 550 | + const nextMiddlewareSpy = Sinon.spy(); |
| 551 | + await updateTaskValidator(req, res, nextMiddlewareSpy); |
| 552 | + expect(nextMiddlewareSpy.callCount).to.be.equal(1); |
| 553 | + }); |
| 554 | + |
| 555 | + it("should call nextMiddlewareSpy for updateTaskValidator if both startedOn and endsOn are null", async function () { |
| 556 | + const req = { |
| 557 | + body: { |
| 558 | + startedOn: null, |
| 559 | + endsOn: null, |
| 560 | + }, |
| 561 | + }; |
| 562 | + const res = { boom: { badRequest: Sinon.spy() } }; |
| 563 | + const nextMiddlewareSpy = Sinon.spy(); |
| 564 | + await updateTaskValidator(req, res, nextMiddlewareSpy); |
| 565 | + expect(nextMiddlewareSpy.callCount).to.be.equal(1); |
| 566 | + }); |
| 567 | + |
| 568 | + it("should call nextMiddlewareSpy for updateTaskValidator if both startedOn and endsOn are valid number", async function () { |
| 569 | + const req = { |
| 570 | + body: { |
| 571 | + startedOn: new Date("2023-11-15").getTime(), |
| 572 | + endsOn: new Date("2023-11-18").getTime(), |
| 573 | + }, |
| 574 | + }; |
| 575 | + const res = { boom: { badRequest: Sinon.spy() } }; |
| 576 | + const nextMiddlewareSpy = Sinon.spy(); |
| 577 | + await updateTaskValidator(req, res, nextMiddlewareSpy); |
| 578 | + expect(nextMiddlewareSpy.callCount).to.be.equal(1); |
| 579 | + }); |
| 580 | + |
| 581 | + it("should not call nextMiddlewareSpy for updateTaskValidator if startedOn is not null or a number", async function () { |
| 582 | + const req = { |
| 583 | + body: { |
| 584 | + startedOn: "December 6 2023", |
| 585 | + endsOn: new Date().getTime(), |
| 586 | + }, |
| 587 | + }; |
| 588 | + const res = { boom: { badRequest: Sinon.spy() } }; |
| 589 | + const nextMiddlewareSpy = Sinon.spy(); |
| 590 | + await updateTaskValidator(req, res, nextMiddlewareSpy); |
| 591 | + expect(nextMiddlewareSpy.callCount).to.be.equal(0); |
| 592 | + }); |
| 593 | + |
| 594 | + it("should not call nextMiddlewareSpy for updateTaskValidator if endsOn is not null or a number", async function () { |
| 595 | + const req = { |
| 596 | + body: { |
| 597 | + startedOn: new Date().getTime(), |
| 598 | + endsOn: true, |
| 599 | + }, |
| 600 | + }; |
| 601 | + const res = { boom: { badRequest: Sinon.spy() } }; |
| 602 | + const nextMiddlewareSpy = Sinon.spy(); |
| 603 | + await updateTaskValidator(req, res, nextMiddlewareSpy); |
| 604 | + expect(nextMiddlewareSpy.callCount).to.be.equal(0); |
| 605 | + }); |
| 606 | + |
| 607 | + it("should not call nextMiddlewareSpy for updateTaskValidator if both startedOn and endsOn is not null or a number", async function () { |
| 608 | + const req = { |
| 609 | + body: { |
| 610 | + startedOn: "December 6 2023", |
| 611 | + endsOn: true, |
| 612 | + }, |
| 613 | + }; |
| 614 | + const res = { boom: { badRequest: Sinon.spy() } }; |
| 615 | + const nextMiddlewareSpy = Sinon.spy(); |
| 616 | + await updateTaskValidator(req, res, nextMiddlewareSpy); |
| 617 | + expect(nextMiddlewareSpy.callCount).to.be.equal(0); |
| 618 | + }); |
| 619 | + |
524 | 620 | describe("getUsersValidator | Validator", function () {
|
525 | 621 | it("should pass the request when valid query parameters are provided", async function () {
|
526 | 622 | const req = {
|
|
0 commit comments