diff --git a/proxies/live/apiproxy/targets/target.xml b/proxies/live/apiproxy/targets/target.xml
index c9c0bfdd3..2fe629d5a 100644
--- a/proxies/live/apiproxy/targets/target.xml
+++ b/proxies/live/apiproxy/targets/target.xml
@@ -18,10 +18,14 @@
true
-
-
-
- {requestpath}
+ {% if ENVIRONMENT_TYPE == 'sandbox' %}
+
+
+
+ {requestpath}
+ {% else %}
+ https://comms-apim.de-rake4.communications.national.nhs.uk
+ {% endif %}
29000
diff --git a/proxies/shared/policies/AssignMessage.MessageBatches.Create.Request.xml b/proxies/shared/policies/AssignMessage.MessageBatches.Create.Request.xml
index 3dfbc673b..a269ec338 100644
--- a/proxies/shared/policies/AssignMessage.MessageBatches.Create.Request.xml
+++ b/proxies/shared/policies/AssignMessage.MessageBatches.Create.Request.xml
@@ -16,10 +16,17 @@
target.copy.pathsuffix
false
-
- requestpath
- /api/v1/send
-
+ {% if ENVIRONMENT_TYPE == 'sandbox' %}
+
+ requestpath
+ /api/v1/send
+
+ {% else %}
+
+ target.url
+ https://comms-apim.de-rake4.communications.national.nhs.uk/api/v1/send
+
+ {% endif %}
%data.payload#
diff --git a/proxies/shared/policies/AssignMessage.Messages.Create.Request.xml b/proxies/shared/policies/AssignMessage.Messages.Create.Request.xml
index 2a8e9cd5c..8344269f8 100644
--- a/proxies/shared/policies/AssignMessage.Messages.Create.Request.xml
+++ b/proxies/shared/policies/AssignMessage.Messages.Create.Request.xml
@@ -16,10 +16,17 @@
target.copy.pathsuffix
false
-
- requestpath
- /api/v1/messages
-
+ {% if ENVIRONMENT_TYPE == 'sandbox' %}
+
+ requestpath
+ /api/v1/messages
+
+ {% else %}
+
+ target.url
+ https://comms-apim.de-rake4.communications.national.nhs.uk/api/v1/messages
+
+ {% endif %}
%data.payload#
diff --git a/proxies/shared/policies/AssignMessage.Messages.GetSingle.Request.xml b/proxies/shared/policies/AssignMessage.Messages.GetSingle.Request.xml
index ce54ec959..da2298f8c 100644
--- a/proxies/shared/policies/AssignMessage.Messages.GetSingle.Request.xml
+++ b/proxies/shared/policies/AssignMessage.Messages.GetSingle.Request.xml
@@ -16,10 +16,17 @@
target.copy.pathsuffix
false
-
- requestpath
- /api/v1/messages/{data.messageId}
-
+ {% if ENVIRONMENT_TYPE == 'sandbox' %}
+
+ requestpath
+ /api/v1/messages/{data.messageId}
+
+ {% else %}
+
+ target.url
+ https://comms-apim.de-rake4.communications.national.nhs.uk/api/v1/messages/{data.messageId}
+
+ {% endif %}
diff --git a/proxies/shared/policies/AssignMessage.NhsAppAccounts.Get.Request.xml b/proxies/shared/policies/AssignMessage.NhsAppAccounts.Get.Request.xml
index 6d71f721a..ee362d0b9 100644
--- a/proxies/shared/policies/AssignMessage.NhsAppAccounts.Get.Request.xml
+++ b/proxies/shared/policies/AssignMessage.NhsAppAccounts.Get.Request.xml
@@ -16,10 +16,17 @@
target.copy.pathsuffix
false
-
- requestpath
- /api/channels/nhsapp/accounts
-
+ {% if ENVIRONMENT_TYPE == 'sandbox' %}
+
+ requestpath
+ /api/channels/nhsapp/accounts
+
+ {% else %}
+
+ target.url
+ https://comms-apim.de-rake4.communications.national.nhs.uk/api/channels/nhsapp/accounts
+
+ {% endif %}
diff --git a/sandbox/__test__/batch_send.spec.js b/sandbox/__test__/batch_send.spec.js
index 25b04c6ce..d5a1c2941 100644
--- a/sandbox/__test__/batch_send.spec.js
+++ b/sandbox/__test__/batch_send.spec.js
@@ -1047,12 +1047,12 @@ describe("/api/v1/send", () => {
},
})
.expect(400, {
- message: "Invalid recipient contact details. Field 'sms': Invalid",
+ message: "Invalid recipient contact details. Field 'sms': Input is not a string",
errors: [
{
code: 'CM_INVALID_VALUE',
field: "/data/attributes/messages/0/recipient/contactDetails/sms",
- message: "Invalid",
+ message: "Input is not a string",
title: "Invalid value",
statusCode: 400,
},
@@ -1156,12 +1156,12 @@ describe("/api/v1/send", () => {
},
})
.expect(400, {
- message: "Invalid recipient contact details. Field 'email': Invalid",
+ message: "Invalid recipient contact details. Field 'email': Input is not a string",
errors: [
{
code: 'CM_INVALID_VALUE',
field: "/data/attributes/messages/0/recipient/contactDetails/email",
- message: "Invalid",
+ message: "Input is not a string",
title: "Invalid value",
statusCode: 400,
},
@@ -1308,7 +1308,7 @@ describe("/api/v1/send", () => {
})
.expect(400, {
message:
- "Invalid recipient contact details. Field 'lines': 'lines' is missing",
+ "Invalid recipient contact details. Field 'address': 'lines' is missing",
errors: [
{
code: 'CM_MISSING_VALUE',
@@ -1351,7 +1351,7 @@ describe("/api/v1/send", () => {
})
.expect(400, {
message:
- "Invalid recipient contact details. Field 'lines': Too few address lines were provided",
+ "Invalid recipient contact details. Field 'address': Too few address lines were provided",
errors: [
{
code: 'CM_TOO_FEW_ITEMS',
@@ -1393,7 +1393,7 @@ describe("/api/v1/send", () => {
},
})
.expect(400, {
- message: "Invalid recipient contact details. Field 'lines': Too many address lines were provided",
+ message: "Invalid recipient contact details. Field 'address': Too many address lines were provided",
errors: [
{
code: 'CM_INVALID_VALUE',
@@ -1435,12 +1435,12 @@ describe("/api/v1/send", () => {
},
})
.expect(400, {
- message: "Invalid recipient contact details. Field 'lines': Invalid",
+ message: "Invalid recipient contact details. Field 'address': Lines contain non-string or empty line",
errors: [
{
code: 'CM_INVALID_VALUE',
field: "/data/attributes/messages/0/recipient/contactDetails/address",
- message: "Invalid",
+ message: "Lines contain non-string or empty line",
title: "Invalid value",
statusCode: 400,
},
@@ -1477,7 +1477,7 @@ describe("/api/v1/send", () => {
})
.expect(400, {
message:
- "Invalid recipient contact details. Field 'postcode': 'postcode' is missing",
+ "Invalid recipient contact details. Field 'address': 'postcode' is missing",
errors: [
{
code: 'CM_MISSING_VALUE',
@@ -1519,11 +1519,84 @@ describe("/api/v1/send", () => {
},
})
.expect(400, {
- message: "Invalid recipient contact details. Field 'postcode': Invalid",
+ message: "Invalid recipient contact details. Field 'address': 'postcode' is not a string",
errors: [
{
code: 'CM_INVALID_VALUE',
- field: "/data/attributes/messages/0/recipient/contactDetails/address/postcode",
+ field: "/data/attributes/messages/0/recipient/contactDetails/address",
+ message: "'postcode' is not a string",
+ title: "Invalid value",
+ statusCode: 400,
+ },
+ ],
+ })
+ .expect("Content-Type", /json/, done);
+ });
+
+ it("returns a 200 when name alternate contact detail is provided", (done) => {
+ request(server)
+ .post("/api/v1/send")
+ .set({ Authorization: "allowedContactDetailOverride" })
+ .send({
+ data: {
+ type: "MessageBatch",
+ attributes: {
+ routingPlanId: "b838b13c-f98c-4def-93f0-515d4e4f4ee1",
+ messageBatchReference: "request-id",
+ messages: [
+ {
+ messageReference: "1",
+ recipient: {
+ nhsNumber: "1",
+ contactDetails: {
+ name: {
+ prefix: "Mr",
+ firstName: "John",
+ middleNames: "Little",
+ lastName: "Smith",
+ suffix: "Jr"
+ },
+ },
+ },
+ },
+ ],
+ },
+ },
+ })
+ .expect(200)
+ .expect("Content-Type", /json/, done);
+ });
+
+ it("returns a 400 when string for name alternate contact detail is provided", (done) => {
+ request(server)
+ .post("/api/v1/send")
+ .set({ Authorization: "allowedContactDetailOverride" })
+ .send({
+ data: {
+ type: "MessageBatch",
+ attributes: {
+ routingPlanId: "b838b13c-f98c-4def-93f0-515d4e4f4ee1",
+ messageBatchReference: "request-id",
+ messages: [
+ {
+ messageReference: "1",
+ recipient: {
+ nhsNumber: "1",
+ contactDetails: {
+ name: "hello",
+ },
+ },
+ },
+ ],
+ },
+ },
+ })
+ .expect(400, {
+ message: "Invalid recipient contact details. Field 'name': Invalid",
+ errors: [
+ {
+ code: 'CM_INVALID_VALUE',
+ field: "/data/attributes/messages/0/recipient/contactDetails/name",
message: "Invalid",
title: "Invalid value",
statusCode: 400,
@@ -1532,6 +1605,316 @@ describe("/api/v1/send", () => {
})
.expect("Content-Type", /json/, done);
});
+
+ it("returns a 400 when array for name alternate contact detail is provided", (done) => {
+ request(server)
+ .post("/api/v1/send")
+ .set({ Authorization: "allowedContactDetailOverride" })
+ .send({
+ data: {
+ type: "MessageBatch",
+ attributes: {
+ routingPlanId: "b838b13c-f98c-4def-93f0-515d4e4f4ee1",
+ messageBatchReference: "request-id",
+ messages: [
+ {
+ messageReference: "1",
+ recipient: {
+ nhsNumber: "1",
+ contactDetails: {
+ name: [],
+ },
+ },
+ },
+ ],
+ },
+ },
+ })
+ .expect(400, {
+ message: "Invalid recipient contact details. Field 'name': Invalid",
+ errors: [
+ {
+ code: 'CM_INVALID_VALUE',
+ field: "/data/attributes/messages/0/recipient/contactDetails/name",
+ message: "Invalid",
+ title: "Invalid value",
+ statusCode: 400,
+ },
+ ],
+ })
+ .expect("Content-Type", /json/, done);
+ });
+
+ it("returns a 400 when prefix contains non-string value in name alternate contact detail is provided", (done) => {
+ request(server)
+ .post("/api/v1/send")
+ .set({ Authorization: "allowedContactDetailOverride" })
+ .send({
+ data: {
+ type: "MessageBatch",
+ attributes: {
+ routingPlanId: "b838b13c-f98c-4def-93f0-515d4e4f4ee1",
+ messageBatchReference: "request-id",
+ messages: [
+ {
+ messageReference: "1",
+ recipient: {
+ nhsNumber: "1",
+ contactDetails: {
+ name: {
+ prefix: 0,
+ firstName: "John",
+ middleNames: "Little",
+ lastName: "Smith",
+ suffix: "Jr"
+ },
+ },
+ },
+ },
+ ],
+ },
+ },
+ })
+ .expect(400, {
+ message: "Invalid recipient contact details. Field 'name': 'prefix' is not a string",
+ errors: [
+ {
+ code: 'CM_INVALID_VALUE',
+ field: "/data/attributes/messages/0/recipient/contactDetails/name",
+ message: "'prefix' is not a string",
+ title: "Invalid value",
+ statusCode: 400,
+ },
+ ],
+ })
+ .expect("Content-Type", /json/, done);
+ });
+
+ it("returns a 400 when firstName contains non-string value in name alternate contact detail is provided", (done) => {
+ request(server)
+ .post("/api/v1/send")
+ .set({ Authorization: "allowedContactDetailOverride" })
+ .send({
+ data: {
+ type: "MessageBatch",
+ attributes: {
+ routingPlanId: "b838b13c-f98c-4def-93f0-515d4e4f4ee1",
+ messageBatchReference: "request-id",
+ messages: [
+ {
+ messageReference: "1",
+ recipient: {
+ nhsNumber: "1",
+ contactDetails: {
+ name: {
+ prefix: "Mr",
+ firstName: 0,
+ middleNames: "Little",
+ lastName: "Smith",
+ suffix: "Jr"
+ },
+ },
+ },
+ },
+ ],
+ },
+ },
+ })
+ .expect(400, {
+ message: "Invalid recipient contact details. Field 'name': 'firstName' is not a string",
+ errors: [
+ {
+ code: 'CM_INVALID_VALUE',
+ field: "/data/attributes/messages/0/recipient/contactDetails/name",
+ message: "'firstName' is not a string",
+ title: "Invalid value",
+ statusCode: 400,
+ },
+ ],
+ })
+ .expect("Content-Type", /json/, done);
+ });
+
+ it("returns a 400 when middleNames contains non-string value in name alternate contact detail is provided", (done) => {
+ request(server)
+ .post("/api/v1/send")
+ .set({ Authorization: "allowedContactDetailOverride" })
+ .send({
+ data: {
+ type: "MessageBatch",
+ attributes: {
+ routingPlanId: "b838b13c-f98c-4def-93f0-515d4e4f4ee1",
+ messageBatchReference: "request-id",
+ messages: [
+ {
+ messageReference: "1",
+ recipient: {
+ nhsNumber: "1",
+ contactDetails: {
+ name: {
+ prefix: "Mr",
+ firstName: "John",
+ middleNames: 0,
+ lastName: "Smith",
+ suffix: "Jr"
+ },
+ },
+ },
+ },
+ ],
+ },
+ },
+ })
+ .expect(400, {
+ message: "Invalid recipient contact details. Field 'name': 'middleNames' is not a string",
+ errors: [
+ {
+ code: 'CM_INVALID_VALUE',
+ field: "/data/attributes/messages/0/recipient/contactDetails/name",
+ message: "'middleNames' is not a string",
+ title: "Invalid value",
+ statusCode: 400,
+ },
+ ],
+ })
+ .expect("Content-Type", /json/, done);
+ });
+
+ it("returns a 400 when no lastName is provided in name alternate contact detail is provided", (done) => {
+ request(server)
+ .post("/api/v1/send")
+ .set({ Authorization: "allowedContactDetailOverride" })
+ .send({
+ data: {
+ type: "MessageBatch",
+ attributes: {
+ routingPlanId: "b838b13c-f98c-4def-93f0-515d4e4f4ee1",
+ messageBatchReference: "request-id",
+ messages: [
+ {
+ messageReference: "1",
+ recipient: {
+ nhsNumber: "1",
+ contactDetails: {
+ name: {
+ prefix: "Mr",
+ firstName: "John",
+ middleNames: "Little",
+ suffix: "Jr"
+ },
+ },
+ },
+ },
+ ],
+ },
+ },
+ })
+ .expect(400, {
+ message:
+ "Invalid recipient contact details. Field 'name': 'lastName' is missing",
+ errors: [
+ {
+ code: 'CM_MISSING_VALUE',
+ field: "/data/attributes/messages/0/recipient/contactDetails/name",
+ message: "`lastName` is missing",
+ title: "Missing value",
+ statusCode: 400,
+ },
+ ],
+ })
+ .expect("Content-Type", /json/, done);
+ });
+
+ it("returns a 400 when lastName contains non-string value in name alternate contact detail is provided", (done) => {
+ request(server)
+ .post("/api/v1/send")
+ .set({ Authorization: "allowedContactDetailOverride" })
+ .send({
+ data: {
+ type: "MessageBatch",
+ attributes: {
+ routingPlanId: "b838b13c-f98c-4def-93f0-515d4e4f4ee1",
+ messageBatchReference: "request-id",
+ messages: [
+ {
+ messageReference: "1",
+ recipient: {
+ nhsNumber: "1",
+ contactDetails: {
+ name: {
+ prefix: "Mr",
+ firstName: "John",
+ middleNames: "Little",
+ lastName: 0,
+ suffix: "Jr"
+ },
+ },
+ },
+ },
+ ],
+ },
+ },
+ })
+ .expect(400, {
+ message: "Invalid recipient contact details. Field 'name': 'lastName' must be a non-empty string",
+ errors: [
+ {
+ code: 'CM_INVALID_VALUE',
+ field: "/data/attributes/messages/0/recipient/contactDetails/name",
+ message: "'lastName' must be a non-empty string",
+ title: "Invalid value",
+ statusCode: 400,
+ },
+ ],
+ })
+ .expect("Content-Type", /json/, done);
+ });
+
+ it("returns a 400 when suffix contains non-string value in name alternate contact detail is provided", (done) => {
+ request(server)
+ .post("/api/v1/send")
+ .set({ Authorization: "allowedContactDetailOverride" })
+ .send({
+ data: {
+ type: "MessageBatch",
+ attributes: {
+ routingPlanId: "b838b13c-f98c-4def-93f0-515d4e4f4ee1",
+ messageBatchReference: "request-id",
+ messages: [
+ {
+ messageReference: "1",
+ recipient: {
+ nhsNumber: "1",
+ contactDetails: {
+ name: {
+ prefix: "Mr",
+ firstName: "John",
+ middleNames: "Little",
+ lastName: "Smith",
+ suffix: 0
+ },
+ },
+ },
+ },
+ ],
+ },
+ },
+ })
+ .expect(400, {
+ message: "Invalid recipient contact details. Field 'name': 'suffix' is not a string",
+ errors: [
+ {
+ code: 'CM_INVALID_VALUE',
+ field: "/data/attributes/messages/0/recipient/contactDetails/name",
+ message: "'suffix' is not a string",
+ title: "Invalid value",
+ statusCode: 400,
+ },
+ ],
+ })
+ .expect("Content-Type", /json/, done);
+ });
+
it("returns a 400 and multiple errors when there are multiple issues in contact details provided", (done) => {
request(server)
.post("/api/v1/send")
@@ -1562,7 +1945,7 @@ describe("/api/v1/send", () => {
})
.expect(400, {
message:
- "Invalid recipient contact details. Field 'email': Input failed format check. Field 'lines': Too few address lines were provided",
+ "Invalid recipient contact details. Field 'email': Input failed format check. Field 'address': Too few address lines were provided",
errors: [
{
code: 'CM_INVALID_VALUE',
@@ -1605,6 +1988,13 @@ describe("/api/v1/send", () => {
lines: ["1", "2"],
postcode: "hello",
},
+ name: {
+ prefix: "Mr",
+ firstName: "John",
+ middleNames: "Little",
+ lastName: "Smith",
+ suffix: "Jr"
+ },
},
},
},
diff --git a/sandbox/__test__/messages.spec.js b/sandbox/__test__/messages.spec.js
index a489569d3..d47d18d0e 100644
--- a/sandbox/__test__/messages.spec.js
+++ b/sandbox/__test__/messages.spec.js
@@ -740,12 +740,12 @@ describe("/api/v1/messages", () => {
},
})
.expect(400, {
- message: "Invalid recipient contact details. Field 'sms': Invalid",
+ message: "Invalid recipient contact details. Field 'sms': Input is not a string",
errors: [
{
code: 'CM_INVALID_VALUE',
field: "/data/attributes/recipient/contactDetails/sms",
- message: "Invalid",
+ message: "Input is not a string",
title: "Invalid value",
statusCode: 400,
},
@@ -837,12 +837,12 @@ describe("/api/v1/messages", () => {
},
})
.expect(400, {
- message: "Invalid recipient contact details. Field 'email': Invalid",
+ message: "Invalid recipient contact details. Field 'email': Input is not a string",
errors: [
{
code: 'CM_INVALID_VALUE',
field: "/data/attributes/recipient/contactDetails/email",
- message: "Invalid",
+ message: "Input is not a string",
title: "Invalid value",
statusCode: 400,
},
@@ -973,7 +973,7 @@ describe("/api/v1/messages", () => {
})
.expect(400, {
message:
- "Invalid recipient contact details. Field 'lines': 'lines' is missing",
+ "Invalid recipient contact details. Field 'address': 'lines' is missing",
errors: [
{
code: 'CM_MISSING_VALUE',
@@ -1012,7 +1012,7 @@ describe("/api/v1/messages", () => {
})
.expect(400, {
message:
- "Invalid recipient contact details. Field 'lines': Too few address lines were provided",
+ "Invalid recipient contact details. Field 'address': Too few address lines were provided",
errors: [
{
code: 'CM_TOO_FEW_ITEMS',
@@ -1050,7 +1050,7 @@ describe("/api/v1/messages", () => {
},
})
.expect(400, {
- message: "Invalid recipient contact details. Field 'lines': Too many address lines were provided",
+ message: "Invalid recipient contact details. Field 'address': Too many address lines were provided",
errors: [
{
code: 'CM_INVALID_VALUE',
@@ -1088,12 +1088,12 @@ describe("/api/v1/messages", () => {
},
})
.expect(400, {
- message: "Invalid recipient contact details. Field 'lines': Invalid",
+ message: "Invalid recipient contact details. Field 'address': Lines contain non-string or empty line",
errors: [
{
code: 'CM_INVALID_VALUE',
field: "/data/attributes/recipient/contactDetails/address",
- message: "Invalid",
+ message: "Lines contain non-string or empty line",
title: "Invalid value",
statusCode: 400,
},
@@ -1126,7 +1126,7 @@ describe("/api/v1/messages", () => {
})
.expect(400, {
message:
- "Invalid recipient contact details. Field 'postcode': 'postcode' is missing",
+ "Invalid recipient contact details. Field 'address': 'postcode' is missing",
errors: [
{
code: 'CM_MISSING_VALUE',
@@ -1164,11 +1164,137 @@ describe("/api/v1/messages", () => {
},
})
.expect(400, {
- message: "Invalid recipient contact details. Field 'postcode': Invalid",
+ message: "Invalid recipient contact details. Field 'address': 'postcode' is not a string",
+ errors: [
+ {
+ code: 'CM_INVALID_VALUE',
+ field: "/data/attributes/recipient/contactDetails/address",
+ message: "'postcode' is not a string",
+ title: "Invalid value",
+ statusCode: 400,
+ },
+ ],
+ })
+ .expect("Content-Type", /json/, done);
+ });
+
+ it("returns a 201 when valid value for name alternate contact detail is provided", (done) => {
+ request(server)
+ .post("/api/v1/messages")
+ .set({ Authorization: "allowedContactDetailOverride" })
+ .send({
+ data: {
+ type: "Message",
+ attributes: {
+ routingPlanId: "b838b13c-f98c-4def-93f0-515d4e4f4ee1",
+ messageReference: "b5bb84b9-a522-41e9-aa8b-ad1b6a454243",
+ recipient: {
+ nhsNumber: "1",
+ contactDetails: {
+ name: {
+ prefix: "Mr",
+ firstName: "John",
+ middleNames: "Little",
+ lastName: "Smith",
+ suffix: "Jr"
+ },
+ },
+ },
+ personalisation: {},
+ },
+ },
+ })
+ .expect(201)
+ .expect("Content-Type", /json/, done);
+ });
+
+ it("returns a 201 when only lastName is provided for name alternate contact details", (done) => {
+ request(server)
+ .post("/api/v1/messages")
+ .set({ Authorization: "allowedContactDetailOverride" })
+ .send({
+ data: {
+ type: "Message",
+ attributes: {
+ routingPlanId: "b838b13c-f98c-4def-93f0-515d4e4f4ee1",
+ messageReference: "b5bb84b9-a522-41e9-aa8b-ad1b6a454243",
+ recipient: {
+ nhsNumber: "1",
+ contactDetails: {
+ name: {
+ lastName: "Smith"
+ },
+ },
+ },
+ personalisation: {},
+ },
+ },
+ })
+ .expect(201)
+ .expect("Content-Type", /json/, done);
+ });
+
+ it("returns a 400 when string for name alternate contact detail is provided", (done) => {
+ request(server)
+ .post("/api/v1/messages")
+ .set({ Authorization: "allowedContactDetailOverride" })
+ .send({
+ data: {
+ type: "Message",
+ attributes: {
+ routingPlanId: "b838b13c-f98c-4def-93f0-515d4e4f4ee1",
+ messageReference: "b5bb84b9-a522-41e9-aa8b-ad1b6a454243",
+ recipient: {
+ nhsNumber: "1",
+ contactDetails: {
+ name: "hello",
+ },
+ },
+ personalisation: {},
+ },
+ },
+ })
+ .expect(400, {
+ message: "Invalid recipient contact details. Field 'name': Invalid",
+ errors: [
+ {
+ code: 'CM_INVALID_VALUE',
+ field: "/data/attributes/recipient/contactDetails/name",
+ message: "Invalid",
+ title: "Invalid value",
+ statusCode: 400,
+ },
+ ],
+ })
+ .expect("Content-Type", /json/, done);
+ });
+
+ it("returns a 400 when array for name alternate contact detail is provided", (done) => {
+ request(server)
+ .post("/api/v1/messages")
+ .set({ Authorization: "allowedContactDetailOverride" })
+ .send({
+ data: {
+ type: "Message",
+ attributes: {
+ routingPlanId: "b838b13c-f98c-4def-93f0-515d4e4f4ee1",
+ messageReference: "b5bb84b9-a522-41e9-aa8b-ad1b6a454243",
+ recipient: {
+ nhsNumber: "1",
+ contactDetails: {
+ name: [],
+ },
+ },
+ personalisation: {},
+ },
+ },
+ })
+ .expect(400, {
+ message: "Invalid recipient contact details. Field 'name': Invalid",
errors: [
{
code: 'CM_INVALID_VALUE',
- field: "/data/attributes/recipient/contactDetails/address/postcode",
+ field: "/data/attributes/recipient/contactDetails/name",
message: "Invalid",
title: "Invalid value",
statusCode: 400,
@@ -1177,6 +1303,294 @@ describe("/api/v1/messages", () => {
})
.expect("Content-Type", /json/, done);
});
+
+ it("returns a 400 when prefix contains non-string value in name alternate contact detail is provided", (done) => {
+ request(server)
+ .post("/api/v1/messages")
+ .set({ Authorization: "allowedContactDetailOverride" })
+ .send({
+ data: {
+ type: "Message",
+ attributes: {
+ routingPlanId: "b838b13c-f98c-4def-93f0-515d4e4f4ee1",
+ messageReference: "b5bb84b9-a522-41e9-aa8b-ad1b6a454243",
+ recipient: {
+ nhsNumber: "1",
+ contactDetails: {
+ name: {
+ prefix: 0,
+ firstName: "John",
+ middleNames: "Little",
+ lastName: "Smith",
+ suffix: "Jr"
+ },
+ },
+ },
+ personalisation: {},
+ },
+ },
+ })
+ .expect(400, {
+ message: "Invalid recipient contact details. Field 'name': 'prefix' is not a string",
+ errors: [
+ {
+ code: 'CM_INVALID_VALUE',
+ field: "/data/attributes/recipient/contactDetails/name",
+ message: "'prefix' is not a string",
+ title: "Invalid value",
+ statusCode: 400,
+ },
+ ],
+ })
+ .expect("Content-Type", /json/, done);
+ });
+
+ it("returns a 400 when firstName contains non-string value in name alternate contact detail is provided", (done) => {
+ request(server)
+ .post("/api/v1/messages")
+ .set({ Authorization: "allowedContactDetailOverride" })
+ .send({
+ data: {
+ type: "Message",
+ attributes: {
+ routingPlanId: "b838b13c-f98c-4def-93f0-515d4e4f4ee1",
+ messageReference: "b5bb84b9-a522-41e9-aa8b-ad1b6a454243",
+ recipient: {
+ nhsNumber: "1",
+ contactDetails: {
+ name: {
+ prefix: "Mr",
+ firstName: 0,
+ middleNames: "Little",
+ lastName: "Smith",
+ suffix: "Jr"
+ },
+ },
+ },
+ personalisation: {},
+ },
+ },
+ })
+ .expect(400, {
+ message: "Invalid recipient contact details. Field 'name': 'firstName' is not a string",
+ errors: [
+ {
+ code: 'CM_INVALID_VALUE',
+ field: "/data/attributes/recipient/contactDetails/name",
+ message: "'firstName' is not a string",
+ title: "Invalid value",
+ statusCode: 400,
+ },
+ ],
+ })
+ .expect("Content-Type", /json/, done);
+ });
+
+ it("returns a 400 when middleNames contains non-string value in name alternate contact detail is provided", (done) => {
+ request(server)
+ .post("/api/v1/messages")
+ .set({ Authorization: "allowedContactDetailOverride" })
+ .send({
+ data: {
+ type: "Message",
+ attributes: {
+ routingPlanId: "b838b13c-f98c-4def-93f0-515d4e4f4ee1",
+ messageReference: "b5bb84b9-a522-41e9-aa8b-ad1b6a454243",
+ recipient: {
+ nhsNumber: "1",
+ contactDetails: {
+ name: {
+ prefix: "Mr",
+ firstName: "John",
+ middleNames: 0,
+ lastName: "Smith",
+ suffix: "Jr"
+ },
+ },
+ },
+ personalisation: {},
+ },
+ },
+ })
+ .expect(400, {
+ message: "Invalid recipient contact details. Field 'name': 'middleNames' is not a string",
+ errors: [
+ {
+ code: 'CM_INVALID_VALUE',
+ field: "/data/attributes/recipient/contactDetails/name",
+ message: "'middleNames' is not a string",
+ title: "Invalid value",
+ statusCode: 400,
+ },
+ ],
+ })
+ .expect("Content-Type", /json/, done);
+ });
+
+ it("returns a 400 when no lastName is provided in name alternate contact detail is provided", (done) => {
+ request(server)
+ .post("/api/v1/messages")
+ .set({ Authorization: "allowedContactDetailOverride" })
+ .send({
+ data: {
+ type: "Message",
+ attributes: {
+ routingPlanId: "b838b13c-f98c-4def-93f0-515d4e4f4ee1",
+ messageReference: "b5bb84b9-a522-41e9-aa8b-ad1b6a454243",
+ recipient: {
+ nhsNumber: "1",
+ contactDetails: {
+ name: {
+ prefix: "Mr",
+ firstName: "John",
+ middleNames: "Little",
+ suffix: "Jr"
+ },
+ },
+ },
+ personalisation: {},
+ },
+ },
+ })
+ .expect(400, {
+ message:
+ "Invalid recipient contact details. Field 'name': 'lastName' is missing",
+ errors: [
+ {
+ code: 'CM_MISSING_VALUE',
+ field: "/data/attributes/recipient/contactDetails/name",
+ message: "`lastName` is missing",
+ title: "Missing value",
+ statusCode: 400,
+ },
+ ],
+ })
+ .expect("Content-Type", /json/, done);
+ });
+
+ it("returns a 400 when lastName contains non-string value in name alternate contact detail is provided", (done) => {
+ request(server)
+ .post("/api/v1/messages")
+ .set({ Authorization: "allowedContactDetailOverride" })
+ .send({
+ data: {
+ type: "Message",
+ attributes: {
+ routingPlanId: "b838b13c-f98c-4def-93f0-515d4e4f4ee1",
+ messageReference: "b5bb84b9-a522-41e9-aa8b-ad1b6a454243",
+ recipient: {
+ nhsNumber: "1",
+ contactDetails: {
+ name: {
+ prefix: "Mr",
+ firstName: "John",
+ middleNames: "Little",
+ lastName: [],
+ suffix: "Jr"
+ },
+ },
+ },
+ personalisation: {},
+ },
+ },
+ })
+ .expect(400, {
+ message: "Invalid recipient contact details. Field 'name': 'lastName' must be a non-empty string",
+ errors: [
+ {
+ code: 'CM_INVALID_VALUE',
+ field: "/data/attributes/recipient/contactDetails/name",
+ message: "'lastName' must be a non-empty string",
+ title: "Invalid value",
+ statusCode: 400,
+ },
+ ],
+ })
+ .expect("Content-Type", /json/, done);
+ });
+
+ it("returns a 400 when lastName contains empty-string value in name alternate contact detail is provided", (done) => {
+ request(server)
+ .post("/api/v1/messages")
+ .set({ Authorization: "allowedContactDetailOverride" })
+ .send({
+ data: {
+ type: "Message",
+ attributes: {
+ routingPlanId: "b838b13c-f98c-4def-93f0-515d4e4f4ee1",
+ messageReference: "b5bb84b9-a522-41e9-aa8b-ad1b6a454243",
+ recipient: {
+ nhsNumber: "1",
+ contactDetails: {
+ name: {
+ prefix: "Mr",
+ firstName: "John",
+ middleNames: "Little",
+ lastName: "",
+ suffix: "Jr"
+ },
+ },
+ },
+ personalisation: {},
+ },
+ },
+ })
+ .expect(400, {
+ message: "Invalid recipient contact details. Field 'name': 'lastName' must be a non-empty string",
+ errors: [
+ {
+ code: 'CM_INVALID_VALUE',
+ field: "/data/attributes/recipient/contactDetails/name",
+ message: "'lastName' must be a non-empty string",
+ title: "Invalid value",
+ statusCode: 400,
+ },
+ ],
+ })
+ .expect("Content-Type", /json/, done);
+ });
+
+ it("returns a 400 when suffix contains non-string value in name alternate contact detail is provided", (done) => {
+ request(server)
+ .post("/api/v1/messages")
+ .set({ Authorization: "allowedContactDetailOverride" })
+ .send({
+ data: {
+ type: "Message",
+ attributes: {
+ routingPlanId: "b838b13c-f98c-4def-93f0-515d4e4f4ee1",
+ messageReference: "b5bb84b9-a522-41e9-aa8b-ad1b6a454243",
+ recipient: {
+ nhsNumber: "1",
+ contactDetails: {
+ name: {
+ prefix: "Mr",
+ firstName: "John",
+ middleNames: "Little",
+ lastName: "Smith",
+ suffix: 0
+ },
+ },
+ },
+ personalisation: {},
+ },
+ },
+ })
+ .expect(400, {
+ message: "Invalid recipient contact details. Field 'name': 'suffix' is not a string",
+ errors: [
+ {
+ code: 'CM_INVALID_VALUE',
+ field: "/data/attributes/recipient/contactDetails/name",
+ message: "'suffix' is not a string",
+ title: "Invalid value",
+ statusCode: 400,
+ },
+ ],
+ })
+ .expect("Content-Type", /json/, done);
+ });
+
it("returns a 400 and multiple errors when there are multiple issues in contact details provided", (done) => {
request(server)
.post("/api/v1/messages")
@@ -1203,7 +1617,7 @@ describe("/api/v1/messages", () => {
})
.expect(400, {
message:
- "Invalid recipient contact details. Field 'email': Input failed format check. Field 'lines': Too few address lines were provided",
+ "Invalid recipient contact details. Field 'email': Input failed format check. Field 'address': Too few address lines were provided",
errors: [
{
code: 'CM_INVALID_VALUE',
@@ -1244,6 +1658,13 @@ describe("/api/v1/messages", () => {
lines: ["1", "2"],
postcode: "hello",
},
+ name: {
+ prefix: "Mr",
+ firstName: "John",
+ middleNames: "Little",
+ lastName: "Smith",
+ suffix: "Jr"
+ },
},
},
},
diff --git a/sandbox/handlers/error_scenarios/override_contact_details.js b/sandbox/handlers/error_scenarios/override_contact_details.js
index 5fbf4b742..b9189dc5c 100644
--- a/sandbox/handlers/error_scenarios/override_contact_details.js
+++ b/sandbox/handlers/error_scenarios/override_contact_details.js
@@ -38,10 +38,10 @@ function smsValidation(sms, path) {
title: "Invalid value",
code: 'CM_INVALID_VALUE',
field: `${path}/recipient/contactDetails/sms`,
- message: "Invalid",
+ message: "Input is not a string",
statusCode: 400,
},
- `Field 'sms': Invalid`,
+ `Field 'sms': Input is not a string`,
]);
}
return validationSuccess();
@@ -69,10 +69,10 @@ function emailValidation(email, path) {
title: "Invalid value",
code: 'CM_INVALID_VALUE',
field: `${path}/recipient/contactDetails/email`,
- message: "Invalid",
+ message: "Input is not a string",
statusCode: 400,
},
- `Field 'email': Invalid`,
+ `Field 'email': Input is not a string`,
]);
}
return validationSuccess();
@@ -105,7 +105,7 @@ function addressValidation(address, path) {
message: "`lines` is missing",
statusCode: 400,
},
- `Field 'lines': 'lines' is missing`,
+ `Field 'address': 'lines' is missing`,
]);
}
if (!Array.isArray(address.lines)) {
@@ -117,7 +117,7 @@ function addressValidation(address, path) {
message: "`lines` is missing",
statusCode: 400,
},
- `Field 'lines': 'lines' is missing`,
+ `Field 'address': 'lines' is missing`,
]);
}
@@ -127,10 +127,10 @@ function addressValidation(address, path) {
title: "Invalid value",
code: 'CM_INVALID_VALUE',
field: `${path}/recipient/contactDetails/address`,
- message: "Invalid",
+ message: "Lines contain non-string or empty line",
statusCode: 400,
},
- `Field 'lines': Invalid`,
+ `Field 'address': Lines contain non-string or empty line`,
]);
}
@@ -143,7 +143,7 @@ function addressValidation(address, path) {
message: "Too few address lines were provided",
statusCode: 400,
},
- `Field 'lines': Too few address lines were provided`,
+ `Field 'address': Too few address lines were provided`,
]);
}
if (address.lines.length > 5) {
@@ -155,7 +155,7 @@ function addressValidation(address, path) {
message: "Too many address lines were provided",
statusCode: 400,
},
- `Field 'lines': Too many address lines were provided`,
+ `Field 'address': Too many address lines were provided`,
]);
}
@@ -168,7 +168,7 @@ function addressValidation(address, path) {
message: "`postcode` is missing",
statusCode: 400,
},
- `Field 'postcode': 'postcode' is missing`,
+ `Field 'address': 'postcode' is missing`,
]);
}
@@ -177,11 +177,110 @@ function addressValidation(address, path) {
{
title: "Invalid value",
code: 'CM_INVALID_VALUE',
- field: `${path}/recipient/contactDetails/address/postcode`,
+ field: `${path}/recipient/contactDetails/address`,
+ message: "'postcode' is not a string",
+ statusCode: 400,
+ },
+ `Field 'address': 'postcode' is not a string`,
+ ]);
+ }
+ return validationSuccess();
+}
+
+function nameValidation(name, path) {
+
+ if (!name) {
+ return validationSuccess();
+ }
+
+ if (typeof name !== "object" || Array.isArray(name)) {
+ return validationFailure([
+ {
+ title: "Invalid value",
+ code: 'CM_INVALID_VALUE',
+ field: `${path}/recipient/contactDetails/name`,
message: "Invalid",
statusCode: 400,
},
- `Field 'postcode': Invalid`,
+ `Field 'name': Invalid`,
+ ]);
+ }
+
+ if ("prefix" in name && typeof name.prefix !== "string") {
+ return validationFailure([
+ {
+ title: "Invalid value",
+ code: 'CM_INVALID_VALUE',
+ field: `${path}/recipient/contactDetails/name`,
+ message: "'prefix' is not a string",
+ statusCode: 400,
+ },
+ `Field 'name': 'prefix' is not a string`,
+ ]);
+ }
+
+ if ("firstName" in name && typeof name.firstName !== "string") {
+ return validationFailure([
+ {
+ title: "Invalid value",
+ code: 'CM_INVALID_VALUE',
+ field: `${path}/recipient/contactDetails/name`,
+ message: "'firstName' is not a string",
+ statusCode: 400,
+ },
+ `Field 'name': 'firstName' is not a string`,
+ ]);
+ }
+
+ if ("middleNames" in name && typeof name.middleNames !== "string") {
+ return validationFailure([
+ {
+ title: "Invalid value",
+ code: 'CM_INVALID_VALUE',
+ field: `${path}/recipient/contactDetails/name`,
+ message: "'middleNames' is not a string",
+ statusCode: 400,
+ },
+ `Field 'name': 'middleNames' is not a string`,
+ ]);
+ }
+
+ if (typeof name.lastName === "undefined") {
+ return validationFailure([
+ {
+ title: "Missing value",
+ code: 'CM_MISSING_VALUE',
+ field: `${path}/recipient/contactDetails/name`,
+ message: "`lastName` is missing",
+ statusCode: 400,
+ },
+ `Field 'name': 'lastName' is missing`,
+ ]);
+ }
+
+ if (typeof name.lastName !== "string" || name.lastName.trim() === "") {
+ return validationFailure([
+ {
+ title: "Invalid value",
+ code: 'CM_INVALID_VALUE',
+ field: `${path}/recipient/contactDetails/name`,
+ message: "'lastName' must be a non-empty string",
+ statusCode: 400,
+ },
+ `Field 'name': 'lastName' must be a non-empty string`,
+ ]);
+ }
+
+ if ("suffix" in name && typeof name.suffix !== "string") {
+ return validationFailure([
+ {
+ title: "Invalid value",
+ code: 'CM_INVALID_VALUE',
+ field: `${path}/recipient/contactDetails/name`,
+ message: "'suffix' is not a string",
+ statusCode: 400,
+ },
+ `Field 'name': 'suffix' is not a string`,
]);
}
return validationSuccess();
@@ -248,6 +347,17 @@ export function getAlternateContactDetailsError(
validationErrorMessages.push(errorMessage);
}
+ const { valid: nameValid, result: nameErrors } = nameValidation(
+ contactDetails.name,
+ path
+ );
+
+ if (!nameValid) {
+ const [errors, errorMessage] = nameErrors;
+ validationErrors.push(errors);
+ validationErrorMessages.push(errorMessage);
+ }
+
if (validationErrors.length) {
return [400, validationErrorMessages.join(". "), validationErrors];
}