Skip to content

Commit 06a7a1f

Browse files
committed
IDVA5-2197 Register an ACSP - Allow Previously Closed/ Ceased ACSPs to Access Registration Service -mapping the filing details to camel case from snake case
1 parent e11db3f commit 06a7a1f

File tree

2 files changed

+77
-25
lines changed

2 files changed

+77
-25
lines changed

src/services/transaction/service.ts

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

test/services/transaction/service.spec.ts

Lines changed: 61 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -153,37 +153,74 @@ describe("transaction", () => {
153153
expect(castedData.errors[0]).to.equal("Unprocessable Entity");
154154
});
155155

156-
it("get transaction list for resource kind returns success response ", async () => {
157-
const itemsArray: TransactionData[] = ([
158-
{
159-
id: "123",
160-
status: "closed",
161-
filings: {
162-
testFiling: {
163-
status: "accepted",
164-
companyNumber: "AP000042",
165-
type: "acsp"
166-
} as Filing
156+
it("getTransactionsForResourceKind returns a transaction list with mapped filings object", async () => {
157+
const mockResponseBody = {
158+
items: [
159+
{
160+
id: "txn1",
161+
updated_at: "2024-06-25T12:00:00Z",
162+
status: "closed",
163+
filings: {
164+
testFiling: {
165+
status: "accepted",
166+
company_number: "AP000042",
167+
type: "acsp"
168+
},
169+
anotherFiling: {
170+
status: "pending",
171+
company_number: "AP000043",
172+
type: "bcsp"
173+
}
174+
},
175+
resume_journey_uri: "/resume/txn1"
167176
}
168-
}
169-
]);
170-
171-
const transactionList: TransactionList = ({
172-
items: itemsArray
173-
});
177+
]
178+
};
174179

175180
const mockGetResponse = {
176181
status: 200,
177-
body: transactionList
182+
body: mockResponseBody
178183
};
179184

180-
const mockRequest = sinon.stub(requestClient, "httpGet").resolves(mockGetResponse);
181-
const transaction : TransactionService = new TransactionService(requestClient);
182-
const data = await transaction.getTransactionsForResourceKind({} as string);
185+
sinon.stub(requestClient, "httpGet").resolves(mockGetResponse);
186+
const transaction: TransactionService = new TransactionService(requestClient);
187+
const data = await transaction.getTransactionsForResourceKind("req-123", "some-kind");
188+
183189
expect(data.httpStatusCode).to.equal(200);
184190
const castedData: Resource<TransactionList> = data as Resource<TransactionList>;
185-
expect(castedData.resource?.items[0].id).to.equal(transactionList.items[0].id);
186-
expect(castedData.resource?.items[0].status).to.equal(transactionList.items[0].status);
187-
expect(castedData.resource?.items[0].filings).to.equal(transactionList.items[0].filings);
191+
expect(castedData.resource?.items).to.have.lengthOf(1);
192+
const item = castedData.resource?.items[0];
193+
expect(item?.id).to.equal("txn1");
194+
expect(item?.updatedAt).to.equal("2024-06-25T12:00:00Z");
195+
expect(item?.status).to.equal("closed");
196+
expect(item?.resumeJourneyUri).to.equal("/resume/txn1");
197+
expect(item?.filings).to.have.property("testFiling");
198+
expect(item?.filings).to.have.property("anotherFiling");
199+
expect(item?.filings["testFiling"]).to.deep.equal({
200+
status: "accepted",
201+
companyNumber: "AP000042",
202+
type: "acsp"
203+
});
204+
expect(item?.filings["anotherFiling"]).to.deep.equal({
205+
status: "pending",
206+
companyNumber: "AP000043",
207+
type: "bcsp"
208+
});
209+
});
210+
211+
it("getTransactionsForResourceKind returns error response on failure", async () => {
212+
const mockGetResponse = {
213+
status: 500,
214+
error: "Internal Server Error"
215+
};
216+
217+
sinon.stub(requestClient, "httpGet").resolves(mockGetResponse);
218+
const transaction: TransactionService = new TransactionService(requestClient);
219+
const data = await transaction.getTransactionsForResourceKind("req-123", "some-kind");
220+
221+
expect(data.httpStatusCode).to.equal(500);
222+
const castedData: ApiErrorResponse = data as ApiErrorResponse;
223+
expect(castedData.errors[0]).to.equal("Internal Server Error");
188224
});
225+
189226
});

0 commit comments

Comments
 (0)