From 003c2030f7f1404312c1e0452fd1cbbf715e5880 Mon Sep 17 00:00:00 2001 From: simonlabarere Date: Mon, 9 Dec 2024 14:10:40 +0000 Subject: [PATCH 1/5] CCM-6434: Restore PR# 759 --- .../development/generic/content_types.md | 3 ++ .../post_v1_message-batches/happy_path.md | 30 +++++++------ .../post_v1_message-batches/performance.md | 3 ++ .../post_v1_message-batches/happy_path.md | 30 +++++++------ .../post_v1_message-batches/performance.md | 3 ++ .../post_v1_message-batches/performance.md | 3 ++ .../post_v1_message-batches/happy_path.md | 35 +++++++++------- .../post_v1_message-batches/performance.md | 6 +++ ...Message.MessageBatches.Create.Response.xml | 15 +++---- ...riables.MessageBatches.Create.Response.xml | 3 ++ sandbox/__test__/batch_send.spec.js | 8 ++++ sandbox/handlers/batch_send.js | 4 ++ .../2xx/201_MessageBatchCreated.yaml | 3 +- .../schemas/responses/MessageBatch.yaml | 12 ++++++ .../test_missing_accept_header.py | 5 +-- .../create_message_batches/test_success.py | 36 +++------------- .../test_missing_accept_header.rst | 5 ++- ...201_message_batch_valid_accept_headers.rst | 5 ++- ...01_message_batch_valid_contact_details.rst | 5 ++- ...ssage_batch_valid_content_type_headers.rst | 5 ++- .../test_201_message_batch_valid_dob.rst | 5 ++- ...est_201_message_batch_valid_nhs_number.rst | 5 ++- ...01_message_batch_valid_routing_plan_id.rst | 5 ++- .../test_201_message_batch_without_dob.rst | 5 ++- ...st_create_messages_large_valid_payload.rst | 3 ++ .../create_message_batches/test_success.py | 36 +++------------- tests/lib/assertions.py | 15 ++++++- tests/lib/constants/message_batches_paths.py | 2 +- tests/lib/generators.py | 24 ++++++++++- .../test_performance.py | 6 +-- .../create_message_batches/test_success.py | 42 ++++--------------- 31 files changed, 199 insertions(+), 168 deletions(-) diff --git a/docs/tests/development/generic/content_types.md b/docs/tests/development/generic/content_types.md index fd1ad46ab..1e00d5f2c 100644 --- a/docs/tests/development/generic/content_types.md +++ b/docs/tests/development/generic/content_types.md @@ -85,6 +85,9 @@ This test uses the ‘X-Correlation-Id’ header, when provided in a request it **Asserts** - Response returns a 201 status code +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids ## 415 - Unsupported Media diff --git a/docs/tests/development/post_v1_message-batches/happy_path.md b/docs/tests/development/post_v1_message-batches/happy_path.md index eeb0671cb..8841483ec 100644 --- a/docs/tests/development/post_v1_message-batches/happy_path.md +++ b/docs/tests/development/post_v1_message-batches/happy_path.md @@ -14,8 +14,9 @@ **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains correctly formatted link to new message URI +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids ### Scenario: An API consumer creating a batch of messages with valid contact details receives a 201 response @@ -29,8 +30,9 @@ **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains request ID +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids ### Scenario: An API consumer creating a batch of messages with a valid content type header receives a 201 response @@ -44,8 +46,9 @@ **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains correctly formatted link to new message URI +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids ### Scenario: An API consumer creating a batch of messages with a valid date of birth receives a 201 response @@ -59,8 +62,9 @@ **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains correctly formatted link to new message URI +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids ### Scenario: An API consumer creating a batch of messages with a valid NHS number receives a 201 response @@ -74,8 +78,9 @@ **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains correctly formatted link to new message URI +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids ### Scenario: An API consumer creating a batch of messages with a date of birth receives a 201 response @@ -89,5 +94,6 @@ **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains correctly formatted link to new message URI +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids diff --git a/docs/tests/development/post_v1_message-batches/performance.md b/docs/tests/development/post_v1_message-batches/performance.md index ae4459828..621572fb4 100644 --- a/docs/tests/development/post_v1_message-batches/performance.md +++ b/docs/tests/development/post_v1_message-batches/performance.md @@ -14,6 +14,9 @@ **Asserts** - Response returns a 201 status code +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids ## Scenario: An API consumer submitting a request with a large request body containing 40,000 duplicate messages receives a 400 response diff --git a/docs/tests/integration/post_v1_message-batches/happy_path.md b/docs/tests/integration/post_v1_message-batches/happy_path.md index 2cc361f53..34826f66e 100644 --- a/docs/tests/integration/post_v1_message-batches/happy_path.md +++ b/docs/tests/integration/post_v1_message-batches/happy_path.md @@ -14,8 +14,9 @@ **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains correctly formatted link to new message URI +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids ### Scenario: An API consumer creating a batch of messages with valid contact details receives a 201 response @@ -29,8 +30,9 @@ **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains request ID +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids ### Scenario: An API consumer creating a batch of messages with a valid content type header receives a 201 response @@ -44,8 +46,9 @@ **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains correctly formatted link to new message URI +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids ### Scenario: An API consumer creating a batch of messages with a valid date of birth receives a 201 response @@ -59,8 +62,9 @@ **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains correctly formatted link to new message URI +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids ### Scenario: An API consumer creating a batch of messages with a valid NHS number receives a 201 response @@ -74,8 +78,9 @@ **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains correctly formatted link to new message URI +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids @@ -90,5 +95,6 @@ **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains correctly formatted link to new message URI +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids diff --git a/docs/tests/integration/post_v1_message-batches/performance.md b/docs/tests/integration/post_v1_message-batches/performance.md index ae4459828..621572fb4 100644 --- a/docs/tests/integration/post_v1_message-batches/performance.md +++ b/docs/tests/integration/post_v1_message-batches/performance.md @@ -14,6 +14,9 @@ **Asserts** - Response returns a 201 status code +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids ## Scenario: An API consumer submitting a request with a large request body containing 40,000 duplicate messages receives a 400 response diff --git a/docs/tests/production/post_v1_message-batches/performance.md b/docs/tests/production/post_v1_message-batches/performance.md index ae4459828..621572fb4 100644 --- a/docs/tests/production/post_v1_message-batches/performance.md +++ b/docs/tests/production/post_v1_message-batches/performance.md @@ -14,6 +14,9 @@ **Asserts** - Response returns a 201 status code +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids ## Scenario: An API consumer submitting a request with a large request body containing 40,000 duplicate messages receives a 400 response diff --git a/docs/tests/sandbox/post_v1_message-batches/happy_path.md b/docs/tests/sandbox/post_v1_message-batches/happy_path.md index 2f3d17678..1631dcbd5 100644 --- a/docs/tests/sandbox/post_v1_message-batches/happy_path.md +++ b/docs/tests/sandbox/post_v1_message-batches/happy_path.md @@ -16,8 +16,9 @@ These tests target the API endpoint v1/message-batches testing successful respon **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains correctly formatted link to new message URI +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids ### Scenario: An API consumer creating a batch of messages with valid contact details receives a 201 response @@ -31,8 +32,9 @@ These tests target the API endpoint v1/message-batches testing successful respon **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains request ID +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids ### Scenario: An API consumer creating a batch of messages with a valid content type header receives a 201 response @@ -46,8 +48,9 @@ These tests target the API endpoint v1/message-batches testing successful respon **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains correctly formatted link to new message URI +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids ### Scenario: An API consumer creating a batch of messages with a valid date of birth receives a 201 response @@ -61,8 +64,9 @@ These tests target the API endpoint v1/message-batches testing successful respon **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains correctly formatted link to new message URI +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids ### Scenario: An API consumer creating a batch of messages with a valid NHS number receives a 201 response @@ -76,8 +80,9 @@ These tests target the API endpoint v1/message-batches testing successful respon **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains correctly formatted link to new message URI +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids ### Scenario: An API consumer creating a batch of messages with a valid routing plan header receives a 201 response @@ -91,8 +96,9 @@ These tests target the API endpoint v1/message-batches testing successful respon **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains correctly formatted link to new message URI +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids ### Scenario: An API consumer creating a batch of messages with a date of birth receives a 201 response @@ -106,5 +112,6 @@ These tests target the API endpoint v1/message-batches testing successful respon **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains correctly formatted link to new message URI +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids diff --git a/docs/tests/sandbox/post_v1_message-batches/performance.md b/docs/tests/sandbox/post_v1_message-batches/performance.md index df99ad0f9..a7f21104e 100644 --- a/docs/tests/sandbox/post_v1_message-batches/performance.md +++ b/docs/tests/sandbox/post_v1_message-batches/performance.md @@ -14,6 +14,9 @@ **Asserts** - Response returns a 201 status code +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids ## Scenario: An API consumer submitting a request with a large request body containing 40,000 duplicate messages receives a 400 response @@ -47,3 +50,6 @@ **Asserts** - Response returns a 201 status code +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids diff --git a/proxies/shared/policies/AssignMessage.MessageBatches.Create.Response.xml b/proxies/shared/policies/AssignMessage.MessageBatches.Create.Response.xml index 57f044f14..21cb2bb25 100644 --- a/proxies/shared/policies/AssignMessage.MessageBatches.Create.Response.xml +++ b/proxies/shared/policies/AssignMessage.MessageBatches.Create.Response.xml @@ -16,17 +16,18 @@ { "data" : { - "type" : "MessageBatch", - "id" : "%data.requestId#", - "attributes" : { - "messageBatchReference" : "%data.messageBatchReference#", + "type": "MessageBatch", + "id": "%data.requestId#", + "attributes": { + "messageBatchReference": "%data.messageBatchReference#", "routingPlan": { - "id" : "%data.routingPlanId#", - "version" : "%data.routingPlanVersion#", + "id": "%data.routingPlanId#", + "version": "%data.routingPlanVersion#", "name": "%data.routingPlanName#", "createdDate": "%data.routingPlanCreatedDate#" } - } + }, + "messages": %data.messages# } } diff --git a/proxies/shared/policies/ExtractVariables.MessageBatches.Create.Response.xml b/proxies/shared/policies/ExtractVariables.MessageBatches.Create.Response.xml index 0efe52aa9..002726405 100644 --- a/proxies/shared/policies/ExtractVariables.MessageBatches.Create.Response.xml +++ b/proxies/shared/policies/ExtractVariables.MessageBatches.Create.Response.xml @@ -27,6 +27,9 @@ $.routingPlan.createdDate + + $.messages + true diff --git a/sandbox/__test__/batch_send.spec.js b/sandbox/__test__/batch_send.spec.js index f0eee2b6f..bcc7d7fd1 100644 --- a/sandbox/__test__/batch_send.spec.js +++ b/sandbox/__test__/batch_send.spec.js @@ -461,6 +461,14 @@ describe("/api/v1/send", () => { assert.notEqual(res.body.routingPlan.name, null); assert.notEqual(res.body.routingPlan.createdDate, undefined); assert.notEqual(res.body.routingPlan.createdDate, null); + assert.notEqual(res.body.messages, undefined); + assert.notEqual(res.body.messages, null); + assert.equal(res.body.messages[0].messageReference, "1"); + assert.notEqual(res.body.messages[0].id, undefined); + assert.notEqual(res.body.messages[0].id, null); + assert.equal(res.body.messages[1].messageReference, "2"); + assert.notEqual(res.body.messages[1].id, undefined); + assert.notEqual(res.body.messages[1].id, null); }) .expect("Content-Type", /json/, done); }); diff --git a/sandbox/handlers/batch_send.js b/sandbox/handlers/batch_send.js index 2e60e9497..ea85738d0 100644 --- a/sandbox/handlers/batch_send.js +++ b/sandbox/handlers/batch_send.js @@ -104,6 +104,10 @@ export async function batchSend(req, res, next) { name: 'routing-plan-name', createdDate: '2022-01-01T00:00:00.000Z' }, + messages: messages.map(message => ({ + messageReference: message.messageReference, + id: KSUID.randomSync(new Date()).string + })) }); res.end(); next(); diff --git a/specification/responses/2xx/201_MessageBatchCreated.yaml b/specification/responses/2xx/201_MessageBatchCreated.yaml index 396ebcd84..0c24c6014 100644 --- a/specification/responses/2xx/201_MessageBatchCreated.yaml +++ b/specification/responses/2xx/201_MessageBatchCreated.yaml @@ -1,7 +1,8 @@ description: |+ Your message batch has been created. The backend service will process the messages contained within it according to the routing plan identified in the request. - The response includes both your `messageBatchReference` and our message batch `id`. You should store this `id` in your database. + The response includes an array with your `messageReference` and our message `id` for each message in your request. + You should store these IDs so that you can later query the message status using the [Get the status of a message](#get-/v1/messages/-messageId-) endpoint. content: application/vnd.api+json: schema: diff --git a/specification/schemas/responses/MessageBatch.yaml b/specification/schemas/responses/MessageBatch.yaml index c01fffbfc..af2c05b14 100644 --- a/specification/schemas/responses/MessageBatch.yaml +++ b/specification/schemas/responses/MessageBatch.yaml @@ -24,3 +24,15 @@ properties: routingPlan: description: The routing plan that you requested the messages be sent with. $ref: ../types/RoutingPlan.yaml + messages: + type: array + items: + type: object + title: Message + additionalProperties: false + properties: + messageReference: + $ref: ../../snippets/MessageReferenceSnippet.yaml + example: 703b8008-545d-4a04-bb90-1f2946ce1575 + id: + $ref: ../types/KSUID.yaml diff --git a/tests/development/content_types/test_missing_accept_header.py b/tests/development/content_types/test_missing_accept_header.py index 2eb300abb..c80f86318 100644 --- a/tests/development/content_types/test_missing_accept_header.py +++ b/tests/development/content_types/test_missing_accept_header.py @@ -33,7 +33,4 @@ def test_missing_accept_header( ) error_handler.handle_retry(resp) - - Assertions.assert_201_response( - resp, data["data"]["attributes"]["messageBatchReference"], data["data"]["attributes"]["routingPlanId"] - ) + Assertions.assert_201_response(resp, data) diff --git a/tests/development/message_batches/create_message_batches/test_success.py b/tests/development/message_batches/create_message_batches/test_success.py index a96f7c046..9b3f42d90 100644 --- a/tests/development/message_batches/create_message_batches/test_success.py +++ b/tests/development/message_batches/create_message_batches/test_success.py @@ -25,11 +25,7 @@ def test_201_message_batch_valid_accept_headers( }, json=data, ) - Assertions.assert_201_response( - resp, - data["data"]["attributes"]["messageBatchReference"], - data["data"]["attributes"]["routingPlanId"], - ) + Assertions.assert_201_response(resp, data) @pytest.mark.devtest @@ -50,11 +46,7 @@ def test_201_message_batch_valid_content_type_headers( }, json=data, ) - Assertions.assert_201_response( - resp, - data["data"]["attributes"]["messageBatchReference"], - data["data"]["attributes"]["routingPlanId"], - ) + Assertions.assert_201_response(resp, data) @pytest.mark.devtest @@ -79,11 +71,7 @@ def test_201_message_batch_valid_nhs_number( }, json=data, ) - Assertions.assert_201_response( - resp, - data["data"]["attributes"]["messageBatchReference"], - data["data"]["attributes"]["routingPlanId"], - ) + Assertions.assert_201_response(resp, data) @pytest.mark.devtest @@ -118,11 +106,7 @@ def test_201_message_batch_valid_contact_details( }, json=data, ) - Assertions.assert_201_response( - resp, - data["data"]["attributes"]["messageBatchReference"], - data["data"]["attributes"]["routingPlanId"], - ) + Assertions.assert_201_response(resp, data) @pytest.mark.devtest @@ -143,11 +127,7 @@ def test_201_message_batch_valid_dob(nhsd_apim_proxy_url, bearer_token_internal_ }, json=data, ) - Assertions.assert_201_response( - resp, - data["data"]["attributes"]["messageBatchReference"], - data["data"]["attributes"]["routingPlanId"], - ) + Assertions.assert_201_response(resp, data) @pytest.mark.devtest @@ -167,8 +147,4 @@ def test_request_without_dob(nhsd_apim_proxy_url, bearer_token_internal_dev): }, json=data, ) - Assertions.assert_201_response( - resp, - data["data"]["attributes"]["messageBatchReference"], - data["data"]["attributes"]["routingPlanId"], - ) + Assertions.assert_201_response(resp, data) diff --git a/tests/docs/partials/content_types/test_missing_accept_header.rst b/tests/docs/partials/content_types/test_missing_accept_header.rst index 9860b1816..89993e420 100644 --- a/tests/docs/partials/content_types/test_missing_accept_header.rst +++ b/tests/docs/partials/content_types/test_missing_accept_header.rst @@ -6,4 +6,7 @@ Scenario: An API consumer submitting a request with a missing accept header rece | **Then** the response is a 201 success **Asserts** -- Response returns a 201 status code \ No newline at end of file +- Response returns a 201 status code +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids \ No newline at end of file diff --git a/tests/docs/partials/happy_path/test_201_message_batch_valid_accept_headers.rst b/tests/docs/partials/happy_path/test_201_message_batch_valid_accept_headers.rst index 7a4dc0ffb..2f1863abf 100644 --- a/tests/docs/partials/happy_path/test_201_message_batch_valid_accept_headers.rst +++ b/tests/docs/partials/happy_path/test_201_message_batch_valid_accept_headers.rst @@ -7,5 +7,6 @@ Scenario: An API consumer creating a batch of messages with a valid accept heade **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains correctly formatted link to new message URI \ No newline at end of file +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids \ No newline at end of file diff --git a/tests/docs/partials/happy_path/test_201_message_batch_valid_contact_details.rst b/tests/docs/partials/happy_path/test_201_message_batch_valid_contact_details.rst index be4be4237..fed323638 100644 --- a/tests/docs/partials/happy_path/test_201_message_batch_valid_contact_details.rst +++ b/tests/docs/partials/happy_path/test_201_message_batch_valid_contact_details.rst @@ -7,5 +7,6 @@ Scenario: An API consumer creating a batch of messages with valid contact detail **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains request ID +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids diff --git a/tests/docs/partials/happy_path/test_201_message_batch_valid_content_type_headers.rst b/tests/docs/partials/happy_path/test_201_message_batch_valid_content_type_headers.rst index 7fee8814a..68f5afd6a 100644 --- a/tests/docs/partials/happy_path/test_201_message_batch_valid_content_type_headers.rst +++ b/tests/docs/partials/happy_path/test_201_message_batch_valid_content_type_headers.rst @@ -7,5 +7,6 @@ Scenario: An API consumer creating a batch of messages with a valid content type **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains correctly formatted link to new message URI \ No newline at end of file +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids \ No newline at end of file diff --git a/tests/docs/partials/happy_path/test_201_message_batch_valid_dob.rst b/tests/docs/partials/happy_path/test_201_message_batch_valid_dob.rst index 075a1545a..5e128e6f2 100644 --- a/tests/docs/partials/happy_path/test_201_message_batch_valid_dob.rst +++ b/tests/docs/partials/happy_path/test_201_message_batch_valid_dob.rst @@ -7,5 +7,6 @@ Scenario: An API consumer creating a batch of messages with a valid date of birt **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains correctly formatted link to new message URI \ No newline at end of file +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids \ No newline at end of file diff --git a/tests/docs/partials/happy_path/test_201_message_batch_valid_nhs_number.rst b/tests/docs/partials/happy_path/test_201_message_batch_valid_nhs_number.rst index 2f9b132d6..d0294970e 100644 --- a/tests/docs/partials/happy_path/test_201_message_batch_valid_nhs_number.rst +++ b/tests/docs/partials/happy_path/test_201_message_batch_valid_nhs_number.rst @@ -7,5 +7,6 @@ Scenario: An API consumer creating a batch of messages with a valid NHS number r **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains correctly formatted link to new message URI \ No newline at end of file +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids \ No newline at end of file diff --git a/tests/docs/partials/happy_path/test_201_message_batch_valid_routing_plan_id.rst b/tests/docs/partials/happy_path/test_201_message_batch_valid_routing_plan_id.rst index 1d29bb4e6..755662fe5 100644 --- a/tests/docs/partials/happy_path/test_201_message_batch_valid_routing_plan_id.rst +++ b/tests/docs/partials/happy_path/test_201_message_batch_valid_routing_plan_id.rst @@ -7,5 +7,6 @@ Scenario: An API consumer creating a batch of messages with a valid routing plan **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains correctly formatted link to new message URI \ No newline at end of file +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids \ No newline at end of file diff --git a/tests/docs/partials/happy_path/test_201_message_batch_without_dob.rst b/tests/docs/partials/happy_path/test_201_message_batch_without_dob.rst index 974504f04..6d891b207 100644 --- a/tests/docs/partials/happy_path/test_201_message_batch_without_dob.rst +++ b/tests/docs/partials/happy_path/test_201_message_batch_without_dob.rst @@ -7,5 +7,6 @@ Scenario: An API consumer creating a batch of messages with a date of birth rece **Asserts** - Response returns a 201 status code -- Response body matches expected result -- Response contains correctly formatted link to new message URI \ No newline at end of file +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids \ No newline at end of file diff --git a/tests/docs/partials/performance/test_create_messages_large_valid_payload.rst b/tests/docs/partials/performance/test_create_messages_large_valid_payload.rst index 7ab99adf1..c1f080be8 100644 --- a/tests/docs/partials/performance/test_create_messages_large_valid_payload.rst +++ b/tests/docs/partials/performance/test_create_messages_large_valid_payload.rst @@ -8,3 +8,6 @@ Scenario: An API consumer submitting a request with a request body containing 40 **Asserts** - Response returns a 201 status code +- Response contains routingPlanId +- Response contains messageBatchReference +- Response contains a messages array with expected message references and ids \ No newline at end of file diff --git a/tests/integration/message_batches/create_message_batches/test_success.py b/tests/integration/message_batches/create_message_batches/test_success.py index 8cd16b4b9..82b4f88ec 100644 --- a/tests/integration/message_batches/create_message_batches/test_success.py +++ b/tests/integration/message_batches/create_message_batches/test_success.py @@ -24,11 +24,7 @@ def test_201_message_batch_valid_accept_headers(bearer_token_int, accept_headers }, json=data, ) - Assertions.assert_201_response( - resp, - data["data"]["attributes"]["messageBatchReference"], - data["data"]["attributes"]["routingPlanId"], - ) + Assertions.assert_201_response(resp, data) @pytest.mark.inttest @@ -48,11 +44,7 @@ def test_201_message_batch_valid_content_type_headers(bearer_token_int, content_ }, json=data, ) - Assertions.assert_201_response( - resp, - data["data"]["attributes"]["messageBatchReference"], - data["data"]["attributes"]["routingPlanId"], - ) + Assertions.assert_201_response(resp, data) @pytest.mark.inttest @@ -71,11 +63,7 @@ def test_201_message_batch_valid_nhs_number(bearer_token_int): }, json=data, ) - Assertions.assert_201_response( - resp, - data["data"]["attributes"]["messageBatchReference"], - data["data"]["attributes"]["routingPlanId"], - ) + Assertions.assert_201_response(resp, data) @pytest.mark.inttest @@ -109,11 +97,7 @@ def test_201_message_batch_valid_contact_details( }, json=data, ) - Assertions.assert_201_response( - resp, - data["data"]["attributes"]["messageBatchReference"], - data["data"]["attributes"]["routingPlanId"], - ) + Assertions.assert_201_response(resp, data) @pytest.mark.inttest @@ -134,11 +118,7 @@ def test_201_message_batch_valid_dob(bearer_token_int, dob): }, json=data, ) - Assertions.assert_201_response( - resp, - data["data"]["attributes"]["messageBatchReference"], - data["data"]["attributes"]["routingPlanId"], - ) + Assertions.assert_201_response(resp, data) @pytest.mark.inttest @@ -158,11 +138,7 @@ def test_request_without_dob(bearer_token_int): }, json=data, ) - Assertions.assert_201_response( - resp, - data["data"]["attributes"]["messageBatchReference"], - data["data"]["attributes"]["routingPlanId"], - ) + Assertions.assert_201_response(resp, data) @pytest.mark.inttest diff --git a/tests/lib/assertions.py b/tests/lib/assertions.py index 20b331a35..5a36ef5aa 100644 --- a/tests/lib/assertions.py +++ b/tests/lib/assertions.py @@ -6,11 +6,15 @@ class Assertions(): @staticmethod - def assert_201_response(resp, message_batch_reference, routing_plan_id): + def assert_201_response(resp, data): error_handler.handle_retry(resp) assert resp.status_code == 201, f"Response: {resp.status_code}: {resp.text}" + message_batch_reference = data["data"]["attributes"]["messageBatchReference"] + routing_plan_id = data["data"]["attributes"]["routingPlanId"] + messages = data["data"]["attributes"]["messages"] + response = resp.json().get("data") assert response.get("type") == "MessageBatch" assert response.get("id") is not None @@ -22,6 +26,15 @@ def assert_201_response(resp, message_batch_reference, routing_plan_id): assert response.get("attributes").get("routingPlan").get("version") is not None assert response.get("attributes").get("routingPlan").get("name") is not None assert response.get("attributes").get("routingPlan").get("createdDate") is not None + assert response.get("attributes").get("messages") is not None + assert len(response.get("attributes").get("messages")) > 0 + expected_messages = sorted(messages, key=lambda x: x["messageReference"]) + actual_messages = sorted(response.get("attributes").get("messages"), key=lambda x: x["messageReference"]) + for i in range(len(actual_messages)): + assert actual_messages[i].get("messageReference") is not None + assert actual_messages[i].get("messageReference") == expected_messages[i].get("messageReference") + assert actual_messages[i].get("id") is not None + assert actual_messages[i].get("id") != "" # ensure we have our x-content-type-options set correctly assert resp.headers.get("X-Content-Type-Options") == "nosniff" diff --git a/tests/lib/constants/message_batches_paths.py b/tests/lib/constants/message_batches_paths.py index f5b6f1ad4..faa47303f 100644 --- a/tests/lib/constants/message_batches_paths.py +++ b/tests/lib/constants/message_batches_paths.py @@ -34,7 +34,7 @@ ("personalisation", "/data/attributes/messages/0/personalisation"), ] DUPLICATE_PROPERTIES_PATHS = [ - ("messageReference", "/data/attributes/messages/1/messageReference"), + ("messageReference", "/data/attributes/messages/3/messageReference"), ] TOO_FEW_PROPERTIES_PATHS = [ ("messages", MESSAGES_PATH), diff --git a/tests/lib/generators.py b/tests/lib/generators.py index ca7b35541..419c1b277 100644 --- a/tests/lib/generators.py +++ b/tests/lib/generators.py @@ -23,7 +23,29 @@ def generate_valid_create_message_batch_body(environment="sandbox"): "messageBatchReference": str(uuid.uuid1()), "messages": [ { - "messageReference": "703b8008-545d-4a04-bb90-1f2946ce1575", + "messageReference": str(uuid.uuid1()), + "recipient": { + "nhsNumber": "9990548609", + "dateOfBirth": "2023-01-01" + }, + "originator": { + "odsCode": "X26" + }, + "personalisation": {} + }, + { + "messageReference": str(uuid.uuid1()), + "recipient": { + "nhsNumber": "9990548609", + "dateOfBirth": "2023-01-01" + }, + "originator": { + "odsCode": "X26" + }, + "personalisation": {} + }, + { + "messageReference": str(uuid.uuid1()), "recipient": { "nhsNumber": "9990548609", "dateOfBirth": "2023-01-01" diff --git a/tests/sandbox/message_batches/create_message_batches/test_performance.py b/tests/sandbox/message_batches/create_message_batches/test_performance.py index 70ef1b60f..e6214e76f 100644 --- a/tests/sandbox/message_batches/create_message_batches/test_performance.py +++ b/tests/sandbox/message_batches/create_message_batches/test_performance.py @@ -31,11 +31,7 @@ def test_create_messages_large_valid_payload(nhsd_apim_proxy_url): headers={"Accept": "application/json", "Content-Type": "application/json"}, json=data, ) - Assertions.assert_201_response( - resp, - data["data"]["attributes"]["messageBatchReference"], - data["data"]["attributes"]["routingPlanId"], - ) + Assertions.assert_201_response(resp, data) @pytest.mark.sandboxtest diff --git a/tests/sandbox/message_batches/create_message_batches/test_success.py b/tests/sandbox/message_batches/create_message_batches/test_success.py index 4a13d719b..f2685b862 100644 --- a/tests/sandbox/message_batches/create_message_batches/test_success.py +++ b/tests/sandbox/message_batches/create_message_batches/test_success.py @@ -25,11 +25,7 @@ def test_201_message_batch_valid_accept_headers(nhsd_apim_proxy_url, accept_head headers={"Accept": accept_headers, "Content-Type": "application/json"}, json=data, ) - Assertions.assert_201_response( - resp, - data["data"]["attributes"]["messageBatchReference"], - data["data"]["attributes"]["routingPlanId"], - ) + Assertions.assert_201_response(resp, data) @pytest.mark.sandboxtest @@ -46,11 +42,7 @@ def test_201_message_batch_valid_content_type_headers( headers={"Accept": "application/json", "Content-Type": content_type}, json=data, ) - Assertions.assert_201_response( - resp, - data["data"]["attributes"]["messageBatchReference"], - data["data"]["attributes"]["routingPlanId"], - ) + Assertions.assert_201_response(resp, data) @pytest.mark.sandboxtest @@ -67,11 +59,7 @@ def test_201_message_batch_valid_routing_plan_id(nhsd_apim_proxy_url, routing_pl headers={"Accept": "application/json", "Content-Type": "application/json"}, json=data, ) - Assertions.assert_201_response( - resp, - data["data"]["attributes"]["messageBatchReference"], - data["data"]["attributes"]["routingPlanId"], - ) + Assertions.assert_201_response(resp, data) @pytest.mark.sandboxtest @@ -89,11 +77,7 @@ def test_201_message_batch_valid_nhs_number(nhsd_apim_proxy_url): headers={"Accept": "application/json", "Content-Type": "application/json"}, json=data, ) - Assertions.assert_201_response( - resp, - data["data"]["attributes"]["messageBatchReference"], - data["data"]["attributes"]["routingPlanId"], - ) + Assertions.assert_201_response(resp, data) @pytest.mark.sandboxtest @@ -121,11 +105,7 @@ def test_201_message_batch_valid_contact_details(nhsd_apim_proxy_url): headers={"Accept": "application/json", "Content-Type": "application/json"}, json=data, ) - Assertions.assert_201_response( - resp, - data["data"]["attributes"]["messageBatchReference"], - data["data"]["attributes"]["routingPlanId"], - ) + Assertions.assert_201_response(resp, data) @pytest.mark.sandboxtest @@ -142,11 +122,7 @@ def test_201_message_batch_valid_dob(nhsd_apim_proxy_url, dob): headers={"Accept": "application/json", "Content-Type": "application/json"}, json=data, ) - Assertions.assert_201_response( - resp, - data["data"]["attributes"]["messageBatchReference"], - data["data"]["attributes"]["routingPlanId"], - ) + Assertions.assert_201_response(resp, data) @pytest.mark.sandboxtest @@ -162,8 +138,4 @@ def test_request_without_dob(nhsd_apim_proxy_url): headers={"Accept": "application/json", "Content-Type": "application/json"}, json=data, ) - Assertions.assert_201_response( - resp, - data["data"]["attributes"]["messageBatchReference"], - data["data"]["attributes"]["routingPlanId"], - ) + Assertions.assert_201_response(resp, data) From 8576ff55541a96fd6d5091186f12cb4cb4e29744 Mon Sep 17 00:00:00 2001 From: simonlabarere Date: Mon, 9 Dec 2024 15:36:22 +0000 Subject: [PATCH 2/5] CCM-6434: Restore PR# 759 --- proxies/sandbox/apiproxy/targets/sandbox.xml | 2 +- tests/sandbox/test_504_errors.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/proxies/sandbox/apiproxy/targets/sandbox.xml b/proxies/sandbox/apiproxy/targets/sandbox.xml index 6ab5596a9..4543da831 100644 --- a/proxies/sandbox/apiproxy/targets/sandbox.xml +++ b/proxies/sandbox/apiproxy/targets/sandbox.xml @@ -17,7 +17,7 @@ {{ HOSTED_TARGET_CONNECTION }} - 2000 + 10000 diff --git a/tests/sandbox/test_504_errors.py b/tests/sandbox/test_504_errors.py index 977d195dd..30a3a7a03 100644 --- a/tests/sandbox/test_504_errors.py +++ b/tests/sandbox/test_504_errors.py @@ -29,7 +29,7 @@ def test_504_timeout_simulate(nhsd_apim_proxy_url, correlation_id): """ .. include:: ../../partials/timeouts/test_504_timeout_simulate.rst """ - resp = requests.get(f"{nhsd_apim_proxy_url}/_timeout?sleep=3000", headers={ + resp = requests.get(f"{nhsd_apim_proxy_url}/_timeout?sleep=13000", headers={ "X-Correlation-Id": correlation_id }) From 2f39f1c8194a00f46c89044173c6fb6de723b467 Mon Sep 17 00:00:00 2001 From: simonlabarere Date: Mon, 9 Dec 2024 15:59:53 +0000 Subject: [PATCH 3/5] CCM-6434: Restore PR# 759 --- .../policies/AssignMessage.MessageBatches.Create.Response.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proxies/shared/policies/AssignMessage.MessageBatches.Create.Response.xml b/proxies/shared/policies/AssignMessage.MessageBatches.Create.Response.xml index 21cb2bb25..9f9dbacda 100644 --- a/proxies/shared/policies/AssignMessage.MessageBatches.Create.Response.xml +++ b/proxies/shared/policies/AssignMessage.MessageBatches.Create.Response.xml @@ -25,9 +25,9 @@ "version": "%data.routingPlanVersion#", "name": "%data.routingPlanName#", "createdDate": "%data.routingPlanCreatedDate#" - } + }, + "messages": %data.messages# }, - "messages": %data.messages# } } From 050ec2d9a9e698b41a5f60c7c3e2414be69a587a Mon Sep 17 00:00:00 2001 From: simonlabarere Date: Mon, 9 Dec 2024 16:14:04 +0000 Subject: [PATCH 4/5] CCM-6434: Restore PR# 759 --- .../policies/AssignMessage.MessageBatches.Create.Response.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxies/shared/policies/AssignMessage.MessageBatches.Create.Response.xml b/proxies/shared/policies/AssignMessage.MessageBatches.Create.Response.xml index 9f9dbacda..744d2c2d1 100644 --- a/proxies/shared/policies/AssignMessage.MessageBatches.Create.Response.xml +++ b/proxies/shared/policies/AssignMessage.MessageBatches.Create.Response.xml @@ -27,7 +27,7 @@ "createdDate": "%data.routingPlanCreatedDate#" }, "messages": %data.messages# - }, + } } } From 0b7cac750ef9fb0f63b155de71cb1fcab57b6d77 Mon Sep 17 00:00:00 2001 From: simonlabarere Date: Wed, 27 Nov 2024 10:01:42 +0000 Subject: [PATCH 5/5] CCM-7385: Point at de-sila7 --- proxies/live/apiproxy/targets/target.xml | 5 +---- .../AssignMessage.MessageBatches.Create.Request.xml | 6 ++++++ .../policies/AssignMessage.Messages.Create.Request.xml | 7 +++++++ .../policies/AssignMessage.Messages.GetSingle.Request.xml | 7 +++++++ .../policies/AssignMessage.NhsAppAccounts.Get.Request.xml | 6 ++++++ 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/proxies/live/apiproxy/targets/target.xml b/proxies/live/apiproxy/targets/target.xml index c9c0bfdd3..80f98658b 100644 --- a/proxies/live/apiproxy/targets/target.xml +++ b/proxies/live/apiproxy/targets/target.xml @@ -18,10 +18,7 @@ true - - - - {requestpath} + https://comms-apim.de-sila7.communications.national.nhs.uk 29000 diff --git a/proxies/shared/policies/AssignMessage.MessageBatches.Create.Request.xml b/proxies/shared/policies/AssignMessage.MessageBatches.Create.Request.xml index 3dfbc673b..ab016b850 100644 --- a/proxies/shared/policies/AssignMessage.MessageBatches.Create.Request.xml +++ b/proxies/shared/policies/AssignMessage.MessageBatches.Create.Request.xml @@ -20,6 +20,12 @@ requestpath /api/v1/send + {% if ENVIRONMENT_TYPE != 'sandbox' %} + + target.url + https://comms-apim.de-sila7.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..47884212a 100644 --- a/proxies/shared/policies/AssignMessage.Messages.Create.Request.xml +++ b/proxies/shared/policies/AssignMessage.Messages.Create.Request.xml @@ -20,6 +20,13 @@ requestpath /api/v1/messages + +{% if ENVIRONMENT_TYPE != 'sandbox' %} + + target.url + https://comms-apim.de-sila7.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..37bd4e3c4 100644 --- a/proxies/shared/policies/AssignMessage.Messages.GetSingle.Request.xml +++ b/proxies/shared/policies/AssignMessage.Messages.GetSingle.Request.xml @@ -20,6 +20,13 @@ requestpath + +{% if ENVIRONMENT_TYPE != 'sandbox' %} + + target.url + https://comms-apim.de-sila7.communications.national.nhs.uk/api/v1/messages/{data.messageId} + +{% endif %}
{backendCorrelationId}
diff --git a/proxies/shared/policies/AssignMessage.NhsAppAccounts.Get.Request.xml b/proxies/shared/policies/AssignMessage.NhsAppAccounts.Get.Request.xml index 6d71f721a..032f91e53 100644 --- a/proxies/shared/policies/AssignMessage.NhsAppAccounts.Get.Request.xml +++ b/proxies/shared/policies/AssignMessage.NhsAppAccounts.Get.Request.xml @@ -20,6 +20,12 @@ requestpath /api/channels/nhsapp/accounts + {% if ENVIRONMENT_TYPE != 'sandbox' %} + + target.url + https://comms-apim.de-sila7.communications.national.nhs.uk/api/channels/nhsapp/accounts + + {% endif %}
{backendCorrelationId}