@@ -3,8 +3,10 @@ import ValidationReasons from "../../../../src/api/middleware/validators/validat
33import hash from "../../../../src/lib/passwordHashing" ;
44import Account from "../../../../src/models/Account" ;
55import Company from "../../../../src/models/Company" ;
6+ import CompanyConstants from "../../../../src/models/constants/Company" ;
67import Offer from "../../../../src/models/Offer" ;
78import withGodToken from "../../../utils/GodToken" ;
9+ import ValidatorTester from "../../../utils/ValidatorTester" ;
810import { DAY_TO_MS } from "../../../utils/TimeConstants" ;
911
1012describe ( "PUT /company/edit" , ( ) => {
@@ -27,10 +29,21 @@ describe("PUT /company/edit", () => {
2729 contacts : [ "123" , "456" ] ,
2830 } ;
2931
32+ const test_user_admin = {
33+ email : "admin@email.com" ,
34+ password : "password123" ,
35+ } ;
36+
3037 beforeAll ( async ( ) => {
3138 await Account . deleteMany ( { } ) ;
3239 await Company . deleteMany ( { } ) ;
3340 await Offer . deleteMany ( { } ) ;
41+
42+ await Account . create ( {
43+ email : test_user_admin . email ,
44+ password : await hash ( test_user_admin . password ) ,
45+ isAdmin : true ,
46+ } ) ;
3447 } ) ;
3548
3649 afterAll ( async ( ) => {
@@ -76,6 +89,56 @@ describe("PUT /company/edit", () => {
7689 } ) ;
7790 } ) ;
7891
92+ describe ( "Field Validation" , ( ) => {
93+
94+ const company_data = {
95+ name : "Test Company" ,
96+ logo : "http://awebsite.com/alogo.jpg" ,
97+ } ;
98+
99+ let company ;
100+
101+ beforeAll ( async ( ) => {
102+ company = await Company . create ( company_data ) ;
103+ } ) ;
104+
105+ afterAll ( async ( ) => {
106+ await Company . deleteMany ( { name : company . name } ) ;
107+ } ) ;
108+
109+ const EndpointValidatorTester = ValidatorTester (
110+ ( params ) => request ( ) . put ( `/company/${ company . _id } /edit` ) . send ( withGodToken ( params ) )
111+ ) ;
112+ const BodyValidatorTester = EndpointValidatorTester ( "body" ) ;
113+
114+ describe ( "name" , ( ) => {
115+ const FieldValidatorTester = BodyValidatorTester ( "name" ) ;
116+
117+ FieldValidatorTester . mustBeString ( ) ;
118+ FieldValidatorTester . hasMaxLength ( CompanyConstants . companyName . max_length ) ;
119+ FieldValidatorTester . hasMinLength ( CompanyConstants . companyName . min_length ) ;
120+ } ) ;
121+
122+ describe ( "bio" , ( ) => {
123+ const FieldValidatorTester = BodyValidatorTester ( "bio" ) ;
124+
125+ FieldValidatorTester . mustBeString ( ) ;
126+ FieldValidatorTester . hasMaxLength ( CompanyConstants . bio . max_length ) ;
127+ } ) ;
128+
129+ describe ( "contacts" , ( ) => {
130+ const FieldValidatorTester = BodyValidatorTester ( "contacts" ) ;
131+
132+ FieldValidatorTester . mustBeArray ( ) ;
133+ // FieldValidatorTester.mustHaveAtLeast(CompanyConstants.contacts.min_length);
134+ FieldValidatorTester . mustBeArrayBetween ( CompanyConstants . contacts . min_length , CompanyConstants . contacts . max_length ) ;
135+ } ) ;
136+
137+ describe ( "logo" , ( ) => {
138+ // TODO: Add tests for logo when the route has multer middleware to handle file uploads
139+ } ) ;
140+ } ) ;
141+
79142 describe ( "Without auth" , ( ) => {
80143
81144 const company_data = generateTestCompany ( {
@@ -109,10 +172,6 @@ describe("PUT /company/edit", () => {
109172 } ) ;
110173
111174 describe ( "With auth" , ( ) => {
112- const test_user_admin = {
113- email : "admin@email.com" ,
114- password : "password123" ,
115- } ;
116175
117176 const test_user_company_1 = {
118177 email : "company1@email.com" ,
@@ -148,11 +207,6 @@ describe("PUT /company/edit", () => {
148207 ] ) ;
149208
150209 await Account . create ( [
151- {
152- email : test_user_admin . email ,
153- password : await hash ( test_user_admin . password ) ,
154- isAdmin : true ,
155- } ,
156210 {
157211 email : test_user_company_1 . email ,
158212 password : await hash ( test_user_company_1 . password ) ,
0 commit comments