@@ -129,6 +129,37 @@ describe("# Offer Schema tests", () => {
129129 } ) ;
130130 } ) ;
131131
132+ test ( "'jobMinDuration' is required if type offer different than freelance" , async ( ) => {
133+ const offer = new Offer ( { } ) ;
134+ try {
135+ await offer . validate ( ) ;
136+ } catch ( err ) {
137+ expect ( err . errors . jobMinDuration ) . toBeDefined ( ) ;
138+ expect ( err . errors . jobMinDuration ) . toHaveProperty ( "kind" , "required" ) ;
139+ expect ( err . errors . jobMinDuration ) . toHaveProperty ( "message" , "Path `jobMinDuration` is required." ) ;
140+ }
141+ } ) ;
142+
143+ test ( "'jobMinDuration' is not required for 'FREELANCE' job type" , async ( ) => {
144+ const offer = new Offer ( { jobType : "FREELANCE" } ) ;
145+ try {
146+ await offer . validate ( ) ;
147+ } catch ( err ) {
148+ expect ( err . errors . jobMinDuration ) . toBeFalsy ( ) ;
149+ }
150+ } ) ;
151+
152+ test ( "'jobMaxDuration' is required" , async ( ) => {
153+ const offer = new Offer ( { } ) ;
154+ try {
155+ await offer . validate ( ) ;
156+ } catch ( err ) {
157+ expect ( err . errors . jobMaxDuration ) . toBeDefined ( ) ;
158+ expect ( err . errors . jobMaxDuration ) . toHaveProperty ( "kind" , "required" ) ;
159+ expect ( err . errors . jobMaxDuration ) . toHaveProperty ( "message" , "Path `jobMaxDuration` is required." ) ;
160+ }
161+ } ) ;
162+
132163 describe ( "required using custom validators (checking for array lengths, etc)" , ( ) => {
133164 describe ( `'fields' must have between ${ MIN_FIELDS } and ${ MAX_FIELDS } values` , ( ) => {
134165 test ( "Below minimum should throw error" , async ( ) => {
0 commit comments