Skip to content

Commit

Permalink
case schema enhancements (#82)
Browse files Browse the repository at this point in the history
* case schema enhancements
  • Loading branch information
varney authored Aug 8, 2023
1 parent e91831a commit 291a39c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/validation-helpers/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,17 @@ const caseSchema = joi.object().keys({
namespace: requiredString.valid(...salesforceCaseNamespaces),
businessType: joi.string().valid("BN_B2C", "BN_B2B"),
category: joi.string(),
contact: joi.object().keys({
contact: joi.alternatives(joi.object().keys({
firstName: joi.string(),
lastName: joi.string(),
email: requiredString,
phone: joi.string().regex(/^[+\d][0-9]{7,14}$/),
customerNumber: joi.string(),
}).optional(),
}), joi.object().keys({ id: requiredString })).optional(),
deploymentName: joi.string(),
description: requiredString,
externalReference: joi.string().optional(),
eTaskId: joi.string().optional(),
origin: requiredString,
owner: requiredString,
priority: joi.string().optional().valid("High", "Medium", "Low"),
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lu-common",
"version": "3.8.0",
"version": "3.8.1",
"description": "",
"main": "index.js",
"engines": {
Expand Down
22 changes: 21 additions & 1 deletion test/unit/utils/case-body-helper-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,32 @@ describe("create back office case body", () => {
});
});

describe("when calling the create body with a contact with email", () => {
it("should create the expected body with sent in parameters", () => {
const contact = { firstName: "Joe", lastName: "Bloggs", email: "some@example.com" };
createBackOfficeCaseBody(subject, description, namespace, { contact }).should.eql({
...backOfficeCaseBody,
contact,
});
});
});

describe("when calling the create body with a contact id", () => {
it("should create the expected body with sent in parameters", () => {
const contact = { id: "some-id" };
createBackOfficeCaseBody(subject, description, namespace, { contact }).should.eql({
...backOfficeCaseBody,
contact,
});
});
});

describe("when calling the create body with a badly formed contact", () => {
it("should fail the joi validation", () => {
try {
createBackOfficeCaseBody(subject, description, namespace, { contact: { firstName: "Joe", lastName: "Bloggs" } });
} catch (error) {
error.message.should.eql('"contact.email" is required');
error.message.should.eql('"contact" does not match any of the allowed types');
}
});
});
Expand Down

0 comments on commit 291a39c

Please sign in to comment.