Skip to content

Commit 384d1c4

Browse files
authored
Merge pull request #793 from companieshouse/IDVA52197
IDVA5-2197 Register an ACSP - Allow Previously Closed/ Ceased ACSPs to Access Registration Service -mapping the filing details to camel case from snake case
2 parents e68553d + 457f079 commit 384d1c4

File tree

2 files changed

+76
-25
lines changed

2 files changed

+76
-25
lines changed

src/services/transaction/service.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,22 @@ export default class TransactionService {
201201
id: i.id,
202202
updatedAt: i.updated_at,
203203
status: i.status,
204-
filings: i.filings,
204+
filings: i.filings
205+
? (() => {
206+
const result = {};
207+
for (const key in i.filings) {
208+
if (Object.prototype.hasOwnProperty.call(i.filings, key)) {
209+
const filing = i.filings[key];
210+
result[key] = {
211+
status: filing.status,
212+
companyNumber: filing.company_number,
213+
type: filing.type
214+
};
215+
}
216+
}
217+
return result;
218+
})()
219+
: undefined,
205220
resumeJourneyUri: i.resume_journey_uri
206221
})) : []
207222
};

test/services/transaction/service.spec.ts

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)