Skip to content

Commit

Permalink
Merge pull request #209 from kontist/KRP-1242-get-business-account
Browse files Browse the repository at this point in the history
KRP-1242 Get Business Account
  • Loading branch information
jablonskipj authored Nov 15, 2024
2 parents 0f343e3 + ac759d8 commit 7e4c6b1
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,12 @@ router.get(
safeRequestHandler(businessesAPI.retrieveBusinessIdentification)
);

router.get(
"businesses/:business_id/accounts/:account_id",
middlewares.withBusiness,
safeRequestHandler(businessesAPI.getBusinessAccount)
);

// COMPLIANCE QUESTIONS

router.get(
Expand Down
25 changes: 25 additions & 0 deletions src/routes/business/businesses.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import _ from "lodash";
import moment from "moment";
import uuid from "node-uuid";
import type { Response, Request } from "express";

import {
saveBusiness,
Expand Down Expand Up @@ -261,3 +262,27 @@ export const updateBusiness = async (req, res) => {

return res.status(200).send(business);
};

export const getBusinessAccount = async (req: any, res: any) => {
const { account_id } = req.params;
const {
business: { account },
} = req;

if (!account) {
res.status(404).send({
errors: [
{
id: generateID(),
status: 404,
code: "model_not_found",
title: "Model Not Found",
detail: `Couldn't find 'Account' for id '${account_id}'.`,
},
],
});
return;
}

res.status(200).send(account);
};
51 changes: 51 additions & 0 deletions tests/routes/business/business.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,55 @@ describe("Businesses", () => {
expect(business.name).to.equal("Kontist AG");
});
});

describe("Get Business Account", () => {
let res: sinon.SinonSpy;

it("should return error when no account", async () => {
await db.flushDb();

res = mockRes();
await businessesAPI.getBusinessAccount(
{
params: {
business_id: "321",
id: "1234",
},
business: {
id: "321",
},
},
res
);

const response = res.send.lastCall.args[0];
expect(response.errors[0]).to.have.property("status", 404);
});

it("should return account", async () => {
const businessId = "321";
const accountId = "1234";
await db.flushDb();

res = mockRes();
await businessesAPI.getBusinessAccount(
{
params: {
business_id: businessId,
account_id: accountId,
},
business: {
id: businessId,
account: {
id: accountId,
},
},
},
res
);

const lastCall = res.send.args[res.send.args.length - 1];
expect(lastCall[0].id).to.equal(accountId);
});
});
});

0 comments on commit 7e4c6b1

Please sign in to comment.