-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #207 from kontist/KRP-1227-create-legal-rep
KRP-1229 - Legal Representation creation
- Loading branch information
Showing
5 changed files
with
128 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from "./businesses"; | ||
export * from "./documents"; | ||
export * from "./beneficialOwner"; | ||
export * from "./legalRepresentative"; | ||
export * from "./identification"; | ||
export * from "./complianceQuestions"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import type { Response } from "express"; | ||
|
||
import generateID from "../../helpers/id"; | ||
import { saveBusiness } from "../../db"; | ||
import uuid from "node-uuid"; | ||
import { | ||
LegalRepresentative, | ||
LegalRepresentativeType, | ||
LegalRepresentativeRepresentationType, | ||
} from "../../helpers/types"; | ||
import { RequestWithBusiness } from "../../helpers/middlewares"; | ||
|
||
export const createLegalRepresentative = async ( | ||
req: RequestWithBusiness, | ||
res: Response | ||
) => { | ||
const { business } = req; | ||
|
||
try { | ||
const legalRepresentative: LegalRepresentative = { | ||
id: generateID(), | ||
legal_representative_id: req.body.person_id, | ||
business_id: business.id, | ||
valid_until: null, | ||
legal_representative_type: LegalRepresentativeType.PERSON, | ||
power_of_attorney_confirmed_at: req.body.power_of_attorney_confirmed_at, | ||
type_of_representation: LegalRepresentativeRepresentationType.ALONE, | ||
}; | ||
|
||
if (!business.legalRepresentatives) { | ||
business.legalRepresentatives = [{ ...legalRepresentative }]; | ||
} else { | ||
business.legalRepresentatives.push({ ...legalRepresentative }); | ||
} | ||
|
||
await saveBusiness(business); | ||
|
||
return res.status(201).send(legalRepresentative); | ||
} catch (error) { | ||
return res.status(500).send({ | ||
errors: [ | ||
{ | ||
id: uuid.v4(), | ||
status: 500, | ||
}, | ||
], | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { expect } from "chai"; | ||
import sinon from "sinon"; | ||
import { mockReq, mockRes } from "sinon-express-mock"; | ||
import * as db from "../../../src/db"; | ||
|
||
import * as businessesAPI from "../../../src/routes/business/businesses"; | ||
import { createLegalRepresentative } from "../../../src/routes/business/legalRepresentative"; | ||
|
||
describe("createLegalRepresentative", () => { | ||
let res: sinon.SinonSpy; | ||
|
||
describe("when business is found", () => { | ||
let businessId: string; | ||
let req; | ||
|
||
before(async () => { | ||
await db.flushDb(); | ||
res = mockRes(); | ||
|
||
await businessesAPI.createBusiness( | ||
{ | ||
body: { | ||
name: "Kontist GmbH", | ||
}, | ||
headers: {}, | ||
}, | ||
res | ||
); | ||
|
||
businessId = res.send.args[0][0].id; | ||
|
||
res = mockRes(); | ||
req = mockReq({ | ||
params: { | ||
business_id: businessId, | ||
}, | ||
body: { | ||
person_id: "1234abcdef", | ||
}, | ||
business: { | ||
id: businessId, | ||
}, | ||
}); | ||
await createLegalRepresentative(req, res); | ||
}); | ||
|
||
it("should return created legal representative", () => { | ||
const lastCall = res.send.args[res.send.args.length - 1]; | ||
expect(lastCall[0].business_id).to.equal(businessId); | ||
expect(lastCall[0].legal_representative_id).to.equal(req.body.person_id); | ||
}); | ||
|
||
it("should add legal representative to business", async () => { | ||
const business = await db.getBusiness(businessId); | ||
expect(business.legalRepresentatives.length).to.equal(1); | ||
expect(business.legalRepresentatives[0].business_id).to.equal(businessId); | ||
expect(business.legalRepresentatives[0].legal_representative_id).to.equal( | ||
req.body.person_id | ||
); | ||
}); | ||
}); | ||
}); |