Skip to content

Commit

Permalink
Added tests to verify the wrong behavior does not occur anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
Naapperas committed Aug 9, 2021
1 parent 48415ac commit ed26472
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions test/end-to-end/offer.js
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,42 @@ describe("Offer endpoint tests", () => {
});
});

describe("Same 'publishDate' and 'publishEndDate'", () => {
test("should fail if 'publishDate' and 'publishEndDate' have the same value", async () => {

const date = (new Date(Date.now() + (DAY_TO_MS))).toISOString();

const offer = {
title: "Test Offer",
publishDate: date,
publishEndDate: date,
description: "For Testing Purposes",
contacts: ["[email protected]", "229417766"],
jobType: "SUMMER INTERNSHIP",
fields: ["DEVOPS", "MACHINE LEARNING", "OTHER"],
technologies: ["React", "CSS"],
owner: test_company._id,
ownerName: test_company.name,
ownerLogo: test_company.logo,
location: "Testing Street, Test City, 123",
requirements: ["The candidate must be tested", "Fluent in testJS"],
};

const res = await request()
.post("/offers/new")
.send(withGodToken(offer));

// console.info(res.body);

expect(res.status).toBe(HTTPStatus.UNPROCESSABLE_ENTITY);
expect(res.body).toHaveProperty("error_code", ErrorTypes.VALIDATION_ERROR);
expect(res.body.errors[0]).toHaveProperty("msg", ValidationReasons.MUST_BE_AFTER("publishDate"));
expect(res.body.errors[0]).toHaveProperty("param", "publishEndDate");
expect(res.body.errors[0]).toHaveProperty("location", "body");

});
});

describe("Incomplete registration of the offer's company", () => {
let incomplete_test_company;
beforeAll(async () => {
Expand Down Expand Up @@ -2004,6 +2040,58 @@ describe("Offer endpoint tests", () => {
});
});

describe("Same 'publishDate' and 'publishEndDate'", () => {

const dateNow = (new Date(Date.now() + (DAY_TO_MS * 5))).toISOString();
const dateAfter = (new Date(Date.now() + (DAY_TO_MS * 10))).toISOString();
let offer;

beforeAll(async () => {

offer = await Offer.create({
title: "Test Offer",
publishDate: dateNow,
publishEndDate: dateNow,
description: "For Testing Purposes",
contacts: ["[email protected]", "229417766"],
jobType: "SUMMER INTERNSHIP",
fields: ["DEVOPS", "MACHINE LEARNING", "OTHER"],
technologies: ["React", "CSS"],
owner: test_company._id,
ownerName: test_company.name,
ownerLogo: test_company.logo,
location: "Testing Street, Test City, 123",
requirements: ["The candidate must be tested", "Fluent in testJS"],
});
});

afterAll(async () => {

await Offer.deleteMany({ offer });

});

test("should fail if 'publishDate' and 'publishEndDate' have the same value", async () => {

const edits = {
publishDate: dateAfter,
publishEndDate: dateAfter,
};

const res = await request()
.post(`/offers/edit/${offer._id}`)
.send(withGodToken(edits));

// console.info(res.body);

expect(res.status).toBe(HTTPStatus.UNPROCESSABLE_ENTITY);
expect(res.body).toHaveProperty("error_code", ErrorTypes.VALIDATION_ERROR);
expect(res.body.errors[0]).toHaveProperty("msg", ValidationReasons.MUST_BE_AFTER("publishDate"));
expect(res.body.errors[0]).toHaveProperty("param", "publishEndDate");
expect(res.body.errors[0]).toHaveProperty("location", "body");

});
});

describe("testing as a company", () => {

Expand Down

0 comments on commit ed26472

Please sign in to comment.