-
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 test to check if offers reflect company changes
- Loading branch information
marco-vb
committed
Feb 28, 2023
1 parent
d18ea7e
commit 16629f3
Showing
1 changed file
with
46 additions
and
9 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 |
---|---|---|
|
@@ -1935,7 +1935,7 @@ describe("Company endpoint", () => { | |
}); | ||
|
||
describe("PUT /company/edit", () => { | ||
let test_company, test_random; | ||
let test_company, test_random, test_offer; | ||
|
||
const test_user_admin = { | ||
email: "[email protected]", | ||
|
@@ -1954,7 +1954,7 @@ describe("Company endpoint", () => { | |
|
||
const test_agent = agent(); | ||
|
||
beforeAll(async () => { | ||
beforeEach(async () => { | ||
await test_agent | ||
.delete("/auth/login") | ||
.expect(HTTPStatus.OK); | ||
|
@@ -1978,6 +1978,14 @@ describe("Company endpoint", () => { | |
hasFinishedRegistration: true | ||
}); | ||
|
||
const test_offer_data = generateTestOffer({ | ||
owner: test_company._id, | ||
ownerName: test_company.name, | ||
ownerLogo: test_company.logo, | ||
}); | ||
|
||
test_offer = await Offer.create(test_offer_data); | ||
|
||
await Account.deleteMany({}); | ||
|
||
await Account.create({ | ||
|
@@ -2012,22 +2020,32 @@ describe("Company endpoint", () => { | |
|
||
describe("ID Validation", () => { | ||
test("Should fail if id is not a valid ObjectID", async () => { | ||
await test_agent | ||
.post("/auth/login") | ||
.send(test_user_company) | ||
.expect(HTTPStatus.OK); | ||
|
||
const res = await test_agent | ||
.put("/company/123/edit") | ||
.send() | ||
.expect(HTTPStatus.UNAUTHORIZED); | ||
.expect(HTTPStatus.UNPROCESSABLE_ENTITY); | ||
|
||
expect(res.body.errors[0]).toHaveProperty("msg", ValidationReasons.INSUFFICIENT_PERMISSIONS); | ||
expect(res.body.errors[0]).toHaveProperty("msg", ValidationReasons.OBJECT_ID); | ||
}); | ||
|
||
test("Should fail if id is not a valid company", async () => { | ||
const id = "111111111111111111111111"; | ||
await test_agent | ||
.post("/auth/login") | ||
.send(test_user_company) | ||
.expect(HTTPStatus.OK); | ||
|
||
const res = await test_agent | ||
.put(`/company/${id}/edit`) | ||
.send() | ||
.expect(HTTPStatus.UNAUTHORIZED); | ||
.expect(HTTPStatus.UNPROCESSABLE_ENTITY); | ||
|
||
expect(res.body.errors[0]).toHaveProperty("msg", ValidationReasons.INSUFFICIENT_PERMISSIONS); | ||
expect(res.body.errors[0]).toHaveProperty("msg", ValidationReasons.COMPANY_NOT_FOUND(id)); | ||
}); | ||
}); | ||
|
||
|
@@ -2096,11 +2114,30 @@ describe("Company endpoint", () => { | |
|
||
expect(res.body).toHaveProperty("name", "Changing Company"); | ||
expect(res.body).toHaveProperty("bio", "As company itself"); | ||
expect(res.body).toHaveProperty("contacts", ["1"]); | ||
expect(res.body).toHaveProperty("logo", "http://awebsite.com/otherlogo.jpg"); | ||
}); | ||
}); | ||
|
||
test("Offer should be updated", async () => { | ||
await test_agent | ||
.post("/auth/login") | ||
.send(test_user_company) | ||
.expect(HTTPStatus.OK); | ||
|
||
const res = await test_agent | ||
.put(`/company/${test_company._id}/edit`) | ||
.send({ | ||
name: "Changing Company", | ||
contacts: ["122"], | ||
}) | ||
.expect(HTTPStatus.OK); | ||
|
||
test_offer = await Offer.findById(test_offer._id); | ||
expect(res.body).toHaveProperty("contacts", ["122"]); | ||
expect(test_offer.ownerName).toEqual("Changing Company"); | ||
expect(test_offer.contacts).toEqual(["122"]); | ||
}); | ||
|
||
describe("Should fail if company is blocked or disabled", () => { | ||
test("Should fail if company is blocked (admin)", async () => { | ||
await test_agent | ||
|
@@ -2140,7 +2177,7 @@ describe("Company endpoint", () => { | |
logo: "http://awebsite.com/otherlogo.jpg", | ||
}) | ||
.expect(HTTPStatus.FORBIDDEN); | ||
expect(res.body.errors[0]).toHaveProperty("msg", ValidationReasons.COMPANY_BLOCKED); | ||
expect(res.body.errors[0]).toHaveProperty("msg", ValidationReasons.COMPANY_DISABLED); | ||
}); | ||
|
||
test("Should fail if company is blocked (user)", async () => { | ||
|
@@ -2182,7 +2219,7 @@ describe("Company endpoint", () => { | |
}) | ||
.expect(HTTPStatus.FORBIDDEN); | ||
|
||
expect(res.body.errors[0]).toHaveProperty("msg", ValidationReasons.COMPANY_BLOCKED); | ||
expect(res.body.errors[0]).toHaveProperty("msg", ValidationReasons.COMPANY_DISABLED); | ||
}); | ||
}); | ||
}); | ||
|