Skip to content

Commit

Permalink
Merge pull request #712 from companieshouse/IDVA5-1169-GetTransaction…
Browse files Browse the repository at this point in the history
…ListForResourceKind

update transaction service to get transaction list for resource kind
  • Loading branch information
sardhani-ch authored Sep 18, 2024
2 parents 216f9d7 + b4ee76b commit ac31652
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/services/transaction/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ export interface TransactionData {
id?: String;
updatedAt?: Date;
status?: String;
filings?: Map<String, Filing>;
filings?: {
[key: string]: Filing;
};
}

export interface Filing {
Expand Down
28 changes: 27 additions & 1 deletion test/services/transaction/service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import sinon from "sinon";

import TransactionService from "../../../src/services/transaction/service";
import { RequestClient } from "../../../src/http";
import { Transaction, TransactionResource } from "../../../src/services/transaction";
import { Transaction, TransactionData, TransactionList, TransactionResource } from "../../../src/services/transaction";
import { ApiErrorResponse, ApiResponse } from "../../../src/services/resource";
import { Resource } from "../../../src";
const expect = chai.expect;
Expand Down Expand Up @@ -152,4 +152,30 @@ describe("transaction", () => {
const castedData: ApiErrorResponse = data;
expect(castedData.errors[0]).to.equal("Unprocessable Entity");
});

it("get transaction list for resource kind returns success response ", async () => {
const itemsArray: TransactionData[] = ([
{
id: "123",
status: "closed"
}
]);

const transactionList: TransactionList = ({
items: itemsArray
});

const mockGetResponse = {
status: 200,
body: transactionList
};

const mockRequest = sinon.stub(requestClient, "httpGet").resolves(mockGetResponse);
const transaction : TransactionService = new TransactionService(requestClient);
const data = await transaction.getTransactionsForResourceKind({} as string);
expect(data.httpStatusCode).to.equal(200);
const castedData: Resource<TransactionList> = data as Resource<TransactionList>;
expect(castedData.resource?.items[0].id).to.equal(transactionList.items[0].id);
expect(castedData.resource?.items[0].status).to.equal(transactionList.items[0].status);
});
});

0 comments on commit ac31652

Please sign in to comment.