Skip to content

Commit

Permalink
added optional field and description
Browse files Browse the repository at this point in the history
  • Loading branch information
jose-carlos-sousa committed May 22, 2024
1 parent 2318899 commit 9d26b6e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
23 changes: 18 additions & 5 deletions src/models/CV.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ const CVSchema = new Schema({
type: Schema.Types.ObjectId,
required: true
},
description: {
type: String,
maxlength: CVconstants.description.max_length,
minlength: CVconstants.description.min_length,
},
projects: [{
type: {
name: {
Expand Down Expand Up @@ -44,26 +49,34 @@ const CVSchema = new Schema({
type: String,
maxlength: CVconstants.achievements.max_length,
minlength: CVconstants.achievements.min_length,
default: null // Make it optional, set default to null
},
events: {
type: String,
maxlength: CVconstants.events.max_length,
minlength: CVconstants.events.min_length,
default: null // Make it optional, set default to null
},
cvFileUrl: {
type: String,
maxlength: CVconstants.cvFileUrl.max_length,
minlength: CVconstants.cvFileUrl.min_length,
default: null // Make it optional, set default to null
},
personalWebsite: {
type: String,
maxlength: CVconstants.personalWebsite.max_length,
minlength: CVconstants.personalWebsite.min_length,
default: null // Make it optional, set default to null
}
},
personalizedFields: [{
fieldName: {
type: String,
required: true,
maxlength: CVconstants.personalizedFields.fieldName.max_length,
},
value: {
type: String,
required: true,
maxlength: CVconstants.personalizedFields.value.max_length,
},
}],
});

function arrayLengthValidator(arr) {
Expand Down
12 changes: 8 additions & 4 deletions src/models/constants/CV.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ export default Object.freeze({
min_length: 2,
max_length: 50,
},
description: {
min_length: 2,
max_length: 200,
},
language: {
min_length: 2,
max_length: 50,
Expand All @@ -27,15 +31,15 @@ export default Object.freeze({
min_length: 2,
max_length: 200,
},
personalizedFields: [{
personalizedFields: {
fieldName: {
type: String,
required: true,
maxlength: 100, // Adjust the max length as needed
maxlength: 100,
},
value: {
type: String,
maxlength: 255, // Adjust the max length as needed
maxlength: 300,
},
}],
},
});
34 changes: 34 additions & 0 deletions test/cv_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,40 @@ describe("# CV Schema tests", () => {
expect(err.errors.personalWebsite).toBeUndefined();
}
});
test("'personalizedFields' field", async () => {
const cv = new CV({});
try {
await cv.validate();
} catch (err) {
expect(err.errors.personalizedFields).toBeUndefined();
}
});
test("'personalizedFields' array item must have fieldName", async () => {
const cv = new CV({ personalizedFields: [{ value: "value" }] });
try {
await cv.validate();
} catch (err) {
expect(err.errors["personalizedFields.0.fieldName"]).toBeDefined();
expect(err.errors["personalizedFields.0.fieldName"].kind).toBe("required");
}
});
test("'personalizedFields' array item must have value", async () => {
const cv = new CV({ personalizedFields: [{ fieldName: "fieldName" }] });
try {
await cv.validate();
} catch (err) {
expect(err.errors["personalizedFields.0.value"]).toBeDefined();
expect(err.errors["personalizedFields.0.value"].kind).toBe("required");
}
});
test("'description' ", async () => {
const cv = new CV({});
try {
await cv.validate();
} catch (err) {
expect(err.errors.description).toBeUndefined();
}
});
});


Expand Down

0 comments on commit 9d26b6e

Please sign in to comment.