|
| 1 | +import { |
| 2 | + RequestSandBoxHeaders, |
| 3 | + sandBoxHeader, |
| 4 | +} from "../../constants/request-headers"; |
| 5 | +import { ErrorMessageBody } from "../../helpers/common-types"; |
| 6 | +import { |
| 7 | + NoRequestIdHeaders, |
| 8 | + SandboxErrorResponse, |
| 9 | +} from "./get-list-of-letters-test-cases"; |
| 10 | + |
| 11 | +type ApiSandboxMiRequestTestCase = { |
| 12 | + testCase: string; |
| 13 | + header?: RequestSandBoxHeaders | NoRequestIdHeaders; |
| 14 | + body: MiRequestBody; |
| 15 | + expectedResponse: MiRequestBody | ErrorMessageBody | SandboxErrorResponse; |
| 16 | + expectedStatus: number; |
| 17 | +}; |
| 18 | + |
| 19 | +export type MiRequestBody = { |
| 20 | + data: { |
| 21 | + type: string; |
| 22 | + attributes: { |
| 23 | + groupId: string; |
| 24 | + lineItem: string; |
| 25 | + quantity: number; |
| 26 | + specificationId: string; |
| 27 | + stockRemaining: number; |
| 28 | + timestamp: string; |
| 29 | + }; |
| 30 | + }; |
| 31 | +}; |
| 32 | + |
| 33 | +export const apiSandboxCreateMiTestData: ApiSandboxMiRequestTestCase[] = [ |
| 34 | + { |
| 35 | + testCase: "200 when a valid request is passed", |
| 36 | + header: sandBoxHeader, |
| 37 | + body: miValidSandboxRequest(), |
| 38 | + expectedStatus: 200, |
| 39 | + expectedResponse: { |
| 40 | + data: { |
| 41 | + attributes: { |
| 42 | + groupId: "abc123", |
| 43 | + lineItem: "envelope-business-standard", |
| 44 | + quantity: 22, |
| 45 | + specificationId: "2WL5eYSWGzCHlGmzNxuqVusPxDg", |
| 46 | + stockRemaining: 2000, |
| 47 | + timestamp: "2023-11-17T14:27:51.413Z", |
| 48 | + }, |
| 49 | + type: "ManagementInformation", |
| 50 | + }, |
| 51 | + }, |
| 52 | + }, |
| 53 | + { |
| 54 | + testCase: "400 when a invalid timestamp is passed", |
| 55 | + header: sandBoxHeader, |
| 56 | + body: miInvalidDateSandboxRequest(), |
| 57 | + expectedStatus: 400, |
| 58 | + expectedResponse: { |
| 59 | + message: |
| 60 | + 'request.body.data.attributes.timestamp should match format "date-time"', |
| 61 | + errors: [ |
| 62 | + { |
| 63 | + path: ".body.data.attributes.timestamp", |
| 64 | + message: 'should match format "date-time"', |
| 65 | + errorCode: "format.openapi.validation", |
| 66 | + }, |
| 67 | + ], |
| 68 | + }, |
| 69 | + }, |
| 70 | + { |
| 71 | + testCase: "404 when a invalid id is passed", |
| 72 | + header: sandBoxHeader, |
| 73 | + body: miInvalidSandboxRequest(), |
| 74 | + expectedStatus: 404, |
| 75 | + expectedResponse: { |
| 76 | + errors: [ |
| 77 | + { |
| 78 | + id: "rrt-1931948104716186917-c-geu2-10664-3111479-3.0", |
| 79 | + code: "NOTIFY_RESOURCE_NOT_FOUND", |
| 80 | + links: { |
| 81 | + about: |
| 82 | + "https://digital.nhs.uk/developer/api-catalogue/nhs-notify-supplier", |
| 83 | + }, |
| 84 | + status: "404", |
| 85 | + title: "Resource not found", |
| 86 | + detail: "No resource found with that ID", |
| 87 | + }, |
| 88 | + ], |
| 89 | + }, |
| 90 | + }, |
| 91 | +]; |
| 92 | + |
| 93 | +export function miValidSandboxRequest(): MiRequestBody { |
| 94 | + return { |
| 95 | + data: { |
| 96 | + attributes: { |
| 97 | + groupId: "abc123", |
| 98 | + lineItem: "envelope-business-standard", |
| 99 | + quantity: 22, |
| 100 | + specificationId: "2WL5eYSWGzCHlGmzNxuqVusPxDg", |
| 101 | + stockRemaining: 2000, |
| 102 | + timestamp: "2023-11-17T14:27:51.413Z", |
| 103 | + }, |
| 104 | + type: "ManagementInformation", |
| 105 | + }, |
| 106 | + }; |
| 107 | +} |
| 108 | + |
| 109 | +export function miInvalidSandboxRequest(): MiRequestBody { |
| 110 | + return { |
| 111 | + data: { |
| 112 | + attributes: { |
| 113 | + groupId: "abc123", |
| 114 | + lineItem: "envelope-business-standard", |
| 115 | + quantity: 22, |
| 116 | + specificationId: "", |
| 117 | + stockRemaining: 2000, |
| 118 | + timestamp: "2023-11-17T14:27:51.413Z", |
| 119 | + }, |
| 120 | + type: "ManagementInformation", |
| 121 | + }, |
| 122 | + }; |
| 123 | +} |
| 124 | + |
| 125 | +export function miInvalidDateSandboxRequest(): MiRequestBody { |
| 126 | + return { |
| 127 | + data: { |
| 128 | + attributes: { |
| 129 | + groupId: "abc123", |
| 130 | + lineItem: "envelope-business-standard", |
| 131 | + quantity: 22, |
| 132 | + specificationId: "2WL5eYSWGzCHlGmzNxuqVusPxDg", |
| 133 | + stockRemaining: 2000, |
| 134 | + timestamp: "yesterday", |
| 135 | + }, |
| 136 | + type: "ManagementInformation", |
| 137 | + }, |
| 138 | + }; |
| 139 | +} |
0 commit comments