@@ -157,37 +157,73 @@ describe("transaction", () => {
157157 expect ( castedData . errors ?. [ 0 ] ) . to . equal ( "Unprocessable Entity" ) ;
158158 } ) ;
159159
160- it ( "get transaction list for resource kind returns success response " , async ( ) => {
161- const itemsArray : TransactionData [ ] = ( [
162- {
163- id : "123" ,
164- status : "closed" ,
165- filings : {
166- testFiling : {
167- status : "accepted" ,
168- companyNumber : "AP000042" ,
169- type : "acsp"
170- } as Filing
160+ it ( "getTransactionsForResourceKind returns a transaction list with mapped filings object" , async ( ) => {
161+ const mockResponseBody = {
162+ items : [
163+ {
164+ id : "txn1" ,
165+ updated_at : "2024-06-25T12:00:00Z" ,
166+ status : "closed" ,
167+ filings : {
168+ testFiling : {
169+ status : "accepted" ,
170+ company_number : "AP000042" ,
171+ type : "acsp"
172+ } ,
173+ anotherFiling : {
174+ status : "pending" ,
175+ company_number : "AP000043" ,
176+ type : "bcsp"
177+ }
178+ } ,
179+ resume_journey_uri : "/resume/txn1"
171180 }
172- }
173- ] ) ;
174-
175- const transactionList : TransactionList = ( {
176- items : itemsArray
177- } ) ;
181+ ]
182+ } ;
178183
179184 const mockGetResponse = {
180185 status : 200 ,
181- body : transactionList
186+ body : mockResponseBody
182187 } ;
183188
184- const mockRequest = sinon . stub ( requestClient , "httpGet" ) . resolves ( mockGetResponse ) ;
185- const transaction : TransactionService = new TransactionService ( requestClient ) ;
186- const data = await transaction . getTransactionsForResourceKind ( { } as string ) ;
189+ sinon . stub ( requestClient , "httpGet" ) . resolves ( mockGetResponse ) ;
190+ const transaction : TransactionService = new TransactionService ( requestClient ) ;
191+ const data = await transaction . getTransactionsForResourceKind ( "req-123" , "some-kind" ) ;
192+
187193 expect ( data . httpStatusCode ) . to . equal ( 200 ) ;
188194 const castedData : Resource < TransactionList > = data as Resource < TransactionList > ;
189- expect ( castedData . resource ?. items [ 0 ] . id ) . to . equal ( transactionList . items [ 0 ] . id ) ;
190- expect ( castedData . resource ?. items [ 0 ] . status ) . to . equal ( transactionList . items [ 0 ] . status ) ;
191- expect ( castedData . resource ?. items [ 0 ] . filings ) . to . equal ( transactionList . items [ 0 ] . filings ) ;
195+ expect ( castedData . resource ?. items ) . to . have . lengthOf ( 1 ) ;
196+ const item = castedData . resource ?. items [ 0 ] ;
197+ expect ( item ?. id ) . to . equal ( "txn1" ) ;
198+ expect ( item ?. updatedAt ) . to . equal ( "2024-06-25T12:00:00Z" ) ;
199+ expect ( item ?. status ) . to . equal ( "closed" ) ;
200+ expect ( item ?. resumeJourneyUri ) . to . equal ( "/resume/txn1" ) ;
201+ expect ( item ?. filings ) . to . have . property ( "testFiling" ) ;
202+ expect ( item ?. filings ) . to . have . property ( "anotherFiling" ) ;
203+ expect ( item ?. filings . testFiling ) . to . deep . equal ( {
204+ status : "accepted" ,
205+ companyNumber : "AP000042" ,
206+ type : "acsp"
207+ } ) ;
208+ expect ( item ?. filings . anotherFiling ) . to . deep . equal ( {
209+ status : "pending" ,
210+ companyNumber : "AP000043" ,
211+ type : "bcsp"
212+ } ) ;
213+ } ) ;
214+
215+ it ( "getTransactionsForResourceKind returns error response on failure" , async ( ) => {
216+ const mockGetResponse = {
217+ status : 500 ,
218+ error : "Internal Server Error"
219+ } ;
220+
221+ sinon . stub ( requestClient , "httpGet" ) . resolves ( mockGetResponse ) ;
222+ const transaction : TransactionService = new TransactionService ( requestClient ) ;
223+ const data = await transaction . getTransactionsForResourceKind ( "req-123" , "some-kind" ) ;
224+
225+ expect ( data . httpStatusCode ) . to . equal ( 500 ) ;
226+ const castedData : ApiErrorResponse = data as ApiErrorResponse ;
227+ expect ( castedData . errors [ 0 ] ) . to . equal ( "Internal Server Error" ) ;
192228 } ) ;
193229} ) ;
0 commit comments