-
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.
Finished input validation tests for /company/:id/edit
- Loading branch information
Showing
3 changed files
with
72 additions
and
11 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
coverage: | ||
status: | ||
project: | ||
default: | ||
target: 80% | ||
threshold: 5% |
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
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 |
---|---|---|
|
@@ -3,8 +3,10 @@ import ValidationReasons from "../../../../src/api/middleware/validators/validat | |
import hash from "../../../../src/lib/passwordHashing"; | ||
import Account from "../../../../src/models/Account"; | ||
import Company from "../../../../src/models/Company"; | ||
import CompanyConstants from "../../../../src/models/constants/Company"; | ||
import Offer from "../../../../src/models/Offer"; | ||
import withGodToken from "../../../utils/GodToken"; | ||
import ValidatorTester from "../../../utils/ValidatorTester"; | ||
import { DAY_TO_MS } from "../../../utils/TimeConstants"; | ||
|
||
describe("PUT /company/edit", () => { | ||
|
@@ -27,10 +29,21 @@ describe("PUT /company/edit", () => { | |
contacts: ["123", "456"], | ||
}; | ||
|
||
const test_user_admin = { | ||
email: "[email protected]", | ||
password: "password123", | ||
}; | ||
|
||
beforeAll(async () => { | ||
await Account.deleteMany({}); | ||
await Company.deleteMany({}); | ||
await Offer.deleteMany({}); | ||
|
||
await Account.create({ | ||
email: test_user_admin.email, | ||
password: await hash(test_user_admin.password), | ||
isAdmin: true, | ||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
|
@@ -76,6 +89,56 @@ describe("PUT /company/edit", () => { | |
}); | ||
}); | ||
|
||
describe("Field Validation", () => { | ||
|
||
const company_data = { | ||
name: "Test Company", | ||
logo: "http://awebsite.com/alogo.jpg", | ||
}; | ||
|
||
let company; | ||
|
||
beforeAll(async () => { | ||
company = await Company.create(company_data); | ||
}); | ||
|
||
afterAll(async () => { | ||
await Company.deleteMany({ name: company.name }); | ||
}); | ||
|
||
const EndpointValidatorTester = ValidatorTester( | ||
(params) => request().put(`/company/${company._id}/edit`).send(withGodToken(params)) | ||
); | ||
const BodyValidatorTester = EndpointValidatorTester("body"); | ||
|
||
describe("name", () => { | ||
const FieldValidatorTester = BodyValidatorTester("name"); | ||
|
||
FieldValidatorTester.mustBeString(); | ||
FieldValidatorTester.hasMaxLength(CompanyConstants.companyName.max_length); | ||
FieldValidatorTester.hasMinLength(CompanyConstants.companyName.min_length); | ||
}); | ||
|
||
describe("bio", () => { | ||
const FieldValidatorTester = BodyValidatorTester("bio"); | ||
|
||
FieldValidatorTester.mustBeString(); | ||
FieldValidatorTester.hasMaxLength(CompanyConstants.bio.max_length); | ||
}); | ||
|
||
describe("contacts", () => { | ||
const FieldValidatorTester = BodyValidatorTester("contacts"); | ||
|
||
FieldValidatorTester.mustBeArray(); | ||
// FieldValidatorTester.mustHaveAtLeast(CompanyConstants.contacts.min_length); | ||
FieldValidatorTester.mustBeArrayBetween(CompanyConstants.contacts.min_length, CompanyConstants.contacts.max_length); | ||
}); | ||
|
||
describe("logo", () => { | ||
// TODO: Add tests for logo when the route has multer middleware to handle file uploads | ||
}); | ||
}); | ||
|
||
describe("Without auth", () => { | ||
|
||
const company_data = generateTestCompany({ | ||
|
@@ -109,10 +172,6 @@ describe("PUT /company/edit", () => { | |
}); | ||
|
||
describe("With auth", () => { | ||
const test_user_admin = { | ||
email: "[email protected]", | ||
password: "password123", | ||
}; | ||
|
||
const test_user_company_1 = { | ||
email: "[email protected]", | ||
|
@@ -148,11 +207,6 @@ describe("PUT /company/edit", () => { | |
]); | ||
|
||
await Account.create([ | ||
{ | ||
email: test_user_admin.email, | ||
password: await hash(test_user_admin.password), | ||
isAdmin: true, | ||
}, | ||
{ | ||
email: test_user_company_1.email, | ||
password: await hash(test_user_company_1.password), | ||
|