@@ -34,7 +34,7 @@ describe("transaction", () => {
3434
3535 expect ( data . httpStatusCode ) . to . equal ( 401 ) ;
3636 const castedData : ApiErrorResponse = data ;
37- expect ( castedData . errors [ 0 ] ) . to . equal ( "An error occurred" ) ;
37+ expect ( castedData . errors ?. [ 0 ] ) . to . equal ( "An error occurred" ) ;
3838 } ) ;
3939
4040 it ( "post maps the company field data items correctly" , async ( ) => {
@@ -69,11 +69,12 @@ describe("transaction", () => {
6969
7070 expect ( data . httpStatusCode ) . to . equal ( 200 ) ;
7171 const castedData : Resource < Transaction > = data as Resource < Transaction > ;
72- expect ( castedData . resource . companyName ) . to . equal ( mockResponseBody . company_name ) ;
73- expect ( castedData . resource . companyNumber ) . to . equal ( mockResponseBody . company_number ) ;
74- expect ( castedData . resource . links . self ) . to . equal ( mockResponseBody . links . self ) ;
75- expect ( castedData . resource . reference ) . to . equal ( mockResponseBody . reference ) ;
76- expect ( castedData . resource . description ) . to . equal ( mockResponseBody . description ) ;
72+ const resource = castedData . resource ;
73+ expect ( resource ?. companyName ) . to . equal ( mockResponseBody . company_name ) ;
74+ expect ( resource ?. companyNumber ) . to . equal ( mockResponseBody . company_number ) ;
75+ expect ( resource ?. links ?. self ) . to . equal ( mockResponseBody . links ?. self ) ;
76+ expect ( resource ?. reference ) . to . equal ( mockResponseBody . reference ) ;
77+ expect ( resource ?. description ) . to . equal ( mockResponseBody . description ) ;
7778 } ) ;
7879
7980 it ( "get returns an error response on failure" , async ( ) => {
@@ -88,14 +89,15 @@ describe("transaction", () => {
8889
8990 expect ( data . httpStatusCode ) . to . equal ( 401 ) ;
9091 const castedData : ApiErrorResponse = data ;
91- expect ( castedData . errors [ 0 ] ) . to . equal ( "An error occurred" ) ;
92+ expect ( castedData . errors ?. [ 0 ] ) . to . equal ( "An error occurred" ) ;
9293 } ) ;
9394
9495 it ( "get maps the company field data items correctly" , async ( ) => {
9596 const mockResponseBody : TransactionResource = ( {
9697 id : "12345678" ,
9798 company_name : "HELLO LTD" ,
9899 company_number : "88" ,
100+ filing_mode : "default" ,
99101 links : {
100102 self : "/self"
101103 } ,
@@ -114,11 +116,13 @@ describe("transaction", () => {
114116
115117 expect ( data . httpStatusCode ) . to . equal ( 200 ) ;
116118 const castedData : Resource < Transaction > = data as Resource < Transaction > ;
117- expect ( castedData . resource . companyName ) . to . equal ( mockResponseBody . company_name ) ;
118- expect ( castedData . resource . companyNumber ) . to . equal ( mockResponseBody . company_number ) ;
119- expect ( castedData . resource . links . self ) . to . equal ( mockResponseBody . links . self ) ;
120- expect ( castedData . resource . reference ) . to . equal ( mockResponseBody . reference ) ;
121- expect ( castedData . resource . description ) . to . equal ( mockResponseBody . description ) ;
119+ const resource = castedData . resource ;
120+ expect ( resource ?. companyName ) . to . equal ( mockResponseBody . company_name ) ;
121+ expect ( resource ?. companyNumber ) . to . equal ( mockResponseBody . company_number ) ;
122+ expect ( resource ?. filingMode ) . to . equal ( mockResponseBody . filing_mode ) ;
123+ expect ( resource ?. links ?. self ) . to . equal ( mockResponseBody . links ?. self ) ;
124+ expect ( resource ?. reference ) . to . equal ( mockResponseBody . reference ) ;
125+ expect ( resource ?. description ) . to . equal ( mockResponseBody . description ) ;
122126 } ) ;
123127
124128 it ( "put returns successful response" , async ( ) => {
@@ -135,7 +139,7 @@ describe("transaction", () => {
135139
136140 expect ( data . httpStatusCode ) . to . equal ( 202 ) ;
137141 const castedData : ApiResponse < Transaction > = data as ApiResponse < Transaction > ;
138- expect ( castedData . headers [ "X-Payment-Required" ] ) . to . equal ( "http://link-to-payment" ) ;
142+ expect ( castedData . headers ?. [ "X-Payment-Required" ] ) . to . equal ( "http://link-to-payment" ) ;
139143 } ) ;
140144
141145 it ( "put returns an error response on failure" , async ( ) => {
@@ -150,7 +154,7 @@ describe("transaction", () => {
150154
151155 expect ( data . httpStatusCode ) . to . equal ( 422 ) ;
152156 const castedData : ApiErrorResponse = data ;
153- expect ( castedData . errors [ 0 ] ) . to . equal ( "Unprocessable Entity" ) ;
157+ expect ( castedData . errors ?. [ 0 ] ) . to . equal ( "Unprocessable Entity" ) ;
154158 } ) ;
155159
156160 it ( "get transaction list for resource kind returns success response " , async ( ) => {
0 commit comments