-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests to verify the wrong behavior does not occur anymore
- Loading branch information
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 () => { | ||
|
@@ -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", () => { | ||
|
||
|