@@ -34,14 +34,15 @@ 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 ( ) => {
4141 const mockResponseBody : TransactionResource = ( {
4242 id : "12345678" ,
4343 company_name : "HELLO LTD" ,
4444 company_number : "88" ,
45+ filing_mode : "default" ,
4546 links : {
4647 self : "/self"
4748 } ,
@@ -69,11 +70,13 @@ describe("transaction", () => {
6970
7071 expect ( data . httpStatusCode ) . to . equal ( 200 ) ;
7172 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 ) ;
73+ const resource = castedData . resource ;
74+ expect ( resource ?. companyName ) . to . equal ( mockResponseBody . company_name ) ;
75+ expect ( resource ?. companyNumber ) . to . equal ( mockResponseBody . company_number ) ;
76+ expect ( resource ?. filingMode ) . to . equal ( mockResponseBody . filing_mode ) ;
77+ expect ( resource ?. links ?. self ) . to . equal ( mockResponseBody . links ?. self ) ;
78+ expect ( resource ?. reference ) . to . equal ( mockResponseBody . reference ) ;
79+ expect ( resource ?. description ) . to . equal ( mockResponseBody . description ) ;
7780 } ) ;
7881
7982 it ( "get returns an error response on failure" , async ( ) => {
@@ -88,14 +91,15 @@ describe("transaction", () => {
8891
8992 expect ( data . httpStatusCode ) . to . equal ( 401 ) ;
9093 const castedData : ApiErrorResponse = data ;
91- expect ( castedData . errors [ 0 ] ) . to . equal ( "An error occurred" ) ;
94+ expect ( castedData . errors ?. [ 0 ] ) . to . equal ( "An error occurred" ) ;
9295 } ) ;
9396
9497 it ( "get maps the company field data items correctly" , async ( ) => {
9598 const mockResponseBody : TransactionResource = ( {
9699 id : "12345678" ,
97100 company_name : "HELLO LTD" ,
98101 company_number : "88" ,
102+ filing_mode : "default" ,
99103 links : {
100104 self : "/self"
101105 } ,
@@ -114,11 +118,13 @@ describe("transaction", () => {
114118
115119 expect ( data . httpStatusCode ) . to . equal ( 200 ) ;
116120 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 ) ;
121+ const resource = castedData . resource ;
122+ expect ( resource ?. companyName ) . to . equal ( mockResponseBody . company_name ) ;
123+ expect ( resource ?. companyNumber ) . to . equal ( mockResponseBody . company_number ) ;
124+ expect ( resource ?. filingMode ) . to . equal ( mockResponseBody . filing_mode ) ;
125+ expect ( resource ?. links ?. self ) . to . equal ( mockResponseBody . links ?. self ) ;
126+ expect ( resource ?. reference ) . to . equal ( mockResponseBody . reference ) ;
127+ expect ( resource ?. description ) . to . equal ( mockResponseBody . description ) ;
122128 } ) ;
123129
124130 it ( "put returns successful response" , async ( ) => {
@@ -135,7 +141,7 @@ describe("transaction", () => {
135141
136142 expect ( data . httpStatusCode ) . to . equal ( 202 ) ;
137143 const castedData : ApiResponse < Transaction > = data as ApiResponse < Transaction > ;
138- expect ( castedData . headers [ "X-Payment-Required" ] ) . to . equal ( "http://link-to-payment" ) ;
144+ expect ( castedData . headers ?. [ "X-Payment-Required" ] ) . to . equal ( "http://link-to-payment" ) ;
139145 } ) ;
140146
141147 it ( "put returns an error response on failure" , async ( ) => {
@@ -150,7 +156,7 @@ describe("transaction", () => {
150156
151157 expect ( data . httpStatusCode ) . to . equal ( 422 ) ;
152158 const castedData : ApiErrorResponse = data ;
153- expect ( castedData . errors [ 0 ] ) . to . equal ( "Unprocessable Entity" ) ;
159+ expect ( castedData . errors ?. [ 0 ] ) . to . equal ( "Unprocessable Entity" ) ;
154160 } ) ;
155161
156162 it ( "get transaction list for resource kind returns success response " , async ( ) => {
0 commit comments