-
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 #729 from companieshouse/feature/lp-284-patch-email
lp-284 : add patchLimitedPartnership method to limited partnership service
- Loading branch information
Showing
3 changed files
with
186 additions
and
51 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
22 changes: 16 additions & 6 deletions
22
test/services/limited-partnerships/limited.partnerships.mock.ts
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 |
---|---|---|
|
@@ -3,7 +3,11 @@ import { expect } from "chai"; | |
import sinon from "sinon"; | ||
|
||
import * as mockValues from "./limited.partnerships.mock"; | ||
import { LimitedPartnershipCreated, LimitedPartnershipsService, NameEndingType } from "../../../src/services/limited-partnerships"; | ||
import { | ||
LimitedPartnershipCreated, | ||
LimitedPartnershipsService, | ||
NameEndingType | ||
} from "../../../src/services/limited-partnerships"; | ||
import Resource, { ApiErrorResponse } from "../../../src/services/resource"; | ||
|
||
describe("LimitedPartnershipsService POST Tests suite", () => { | ||
|
@@ -12,62 +16,163 @@ describe("LimitedPartnershipsService POST Tests suite", () => { | |
sinon.restore(); | ||
}); | ||
|
||
afterEach(done => { | ||
afterEach((done) => { | ||
sinon.reset(); | ||
sinon.restore(); | ||
done(); | ||
}); | ||
|
||
it("should return object Id for postLimitedPartnership method", async () => { | ||
const mockRequest = sinon.stub(mockValues.requestClient, "httpPost").resolves(mockValues.mockPostLimitedPartnershipResponse[201]); | ||
const service = new LimitedPartnershipsService(mockValues.requestClient); | ||
const response = (await service.postLimitedPartnership( | ||
mockValues.TRANSACTION_ID, | ||
mockValues.LIMITED_PARTNERSHIP_OBJECT_MOCK | ||
)) as Resource<LimitedPartnershipCreated>; | ||
|
||
expect(mockRequest).to.have.been.calledOnce; | ||
expect( | ||
mockRequest.calledWith("/transactions/12345/limited-partnership/partnership", | ||
{ | ||
data: { | ||
partnership_name: "Legalised Asset Stashing", | ||
name_ending: "Limited Partnership" | ||
describe("postLimitedPartnership", () => { | ||
it("should return object Id for postLimitedPartnership method", async () => { | ||
const mockRequest = sinon | ||
.stub(mockValues.requestClient, "httpPost") | ||
.resolves(mockValues.mockPostLimitedPartnershipResponse[201]); | ||
const service = new LimitedPartnershipsService( | ||
mockValues.requestClient | ||
); | ||
const response = (await service.postLimitedPartnership( | ||
mockValues.TRANSACTION_ID, | ||
mockValues.LIMITED_PARTNERSHIP_OBJECT_MOCK | ||
)) as Resource<LimitedPartnershipCreated>; | ||
|
||
expect(mockRequest).to.have.been.calledOnce; | ||
expect( | ||
mockRequest.calledWith( | ||
"/transactions/12345/limited-partnership/partnership", | ||
{ | ||
data: { | ||
partnership_name: "Legalised Asset Stashing", | ||
name_ending: "Limited Partnership" | ||
} | ||
} | ||
}) | ||
).to.be.true; | ||
) | ||
).to.be.true; | ||
|
||
expect(response.httpStatusCode).to.equal(201); | ||
expect(response.resource?.id).to.equal(mockValues.mockLimitedPartnershipCreatedResource.id); | ||
}); | ||
expect(response.httpStatusCode).to.equal(201); | ||
expect(response.resource?.id).to.equal( | ||
mockValues.mockLimitedPartnershipCreatedResource.id | ||
); | ||
}); | ||
|
||
it("should return error 401 (Unauthorised) for postLimitedPartnership method", async () => { | ||
const mockRequest = sinon.stub(mockValues.requestClient, "httpPost").resolves(mockValues.mockPostLimitedPartnershipResponse[401]); | ||
it("should return error 401 (Unauthorised) for postLimitedPartnership method", async () => { | ||
const mockRequest = sinon | ||
.stub(mockValues.requestClient, "httpPost") | ||
.resolves(mockValues.mockPostLimitedPartnershipResponse[401]); | ||
|
||
const service = new LimitedPartnershipsService(mockValues.requestClient); | ||
const response = await service.postLimitedPartnership(mockValues.TRANSACTION_ID, { data: {} }) as ApiErrorResponse; | ||
const service = new LimitedPartnershipsService( | ||
mockValues.requestClient | ||
); | ||
const response = (await service.postLimitedPartnership( | ||
mockValues.TRANSACTION_ID, | ||
{ data: {} } | ||
)) as ApiErrorResponse; | ||
|
||
expect(mockRequest).to.have.been.calledOnce; | ||
expect( | ||
mockRequest.calledWith("/transactions/12345/limited-partnership/partnership", { data: {} }) | ||
).to.be.true; | ||
expect(mockRequest).to.have.been.calledOnce; | ||
expect( | ||
mockRequest.calledWith( | ||
"/transactions/12345/limited-partnership/partnership", | ||
{ data: {} } | ||
) | ||
).to.be.true; | ||
|
||
expect(response.httpStatusCode).to.equal(401); | ||
expect(response.errors?.[0]).to.equal(mockValues.UNAUTHORISED); | ||
}); | ||
expect(response.httpStatusCode).to.equal(401); | ||
expect(response.errors?.[0]).to.equal(mockValues.UNAUTHORISED); | ||
}); | ||
|
||
it("should return error 400 (Bad Request) for postLimitedPartnership method", async () => { | ||
const mockRequest = sinon.stub(mockValues.requestClient, "httpPost").resolves(mockValues.mockPostLimitedPartnershipResponse[400]); | ||
it("should return error 400 (Bad Request) for postLimitedPartnership method", async () => { | ||
const mockRequest = sinon | ||
.stub(mockValues.requestClient, "httpPost") | ||
.resolves(mockValues.mockPostLimitedPartnershipResponse[400]); | ||
|
||
const service = new LimitedPartnershipsService(mockValues.requestClient); | ||
const response = await service.postLimitedPartnership(mockValues.TRANSACTION_ID, { data: { name_ending: NameEndingType.LP } }) as ApiErrorResponse; | ||
const service = new LimitedPartnershipsService( | ||
mockValues.requestClient | ||
); | ||
const response = (await service.postLimitedPartnership( | ||
mockValues.TRANSACTION_ID, | ||
{ data: { name_ending: NameEndingType.LP } } | ||
)) as ApiErrorResponse; | ||
|
||
expect(mockRequest).to.have.been.calledOnce; | ||
expect( | ||
mockRequest.calledWith("/transactions/12345/limited-partnership/partnership", { data: { name_ending: NameEndingType.LP } }) | ||
).to.be.true; | ||
expect(mockRequest).to.have.been.calledOnce; | ||
expect( | ||
mockRequest.calledWith( | ||
"/transactions/12345/limited-partnership/partnership", | ||
{ data: { name_ending: NameEndingType.LP } } | ||
) | ||
).to.be.true; | ||
|
||
expect(response.httpStatusCode).to.equal(400); | ||
expect(response.errors?.[0]).to.equal(mockValues.BAD_REQUEST); | ||
}); | ||
expect(response.httpStatusCode).to.equal(400); | ||
expect(response.errors?.[0]).to.equal(mockValues.BAD_REQUEST); | ||
}); | ||
}) | ||
|
||
describe("patchLimitedPartnership", () => { | ||
it("should return a status 200", async () => { | ||
const mockRequest = sinon | ||
.stub(mockValues.requestClient, "httpPatch") | ||
.resolves(mockValues.mockPostLimitedPartnershipResponse[200]); | ||
|
||
const service = new LimitedPartnershipsService( | ||
mockValues.requestClient | ||
); | ||
|
||
const response = await service.patchLimitedPartnership( | ||
mockValues.TRANSACTION_ID, | ||
mockValues.SUBMISSION_ID, | ||
{ | ||
type: "email", | ||
data: { | ||
email: "[email protected]" | ||
} | ||
} | ||
); | ||
|
||
expect(mockRequest).to.have.been.calledOnce; | ||
expect( | ||
mockRequest.calledWith( | ||
"/transactions/12345/limited-partnership/partnership/09876", | ||
{ | ||
type: "email", | ||
data: { | ||
email: "[email protected]" | ||
} | ||
} | ||
) | ||
).to.be.true; | ||
expect(response.httpStatusCode).to.equal(200); | ||
}); | ||
|
||
it("should return error 400 (Bad Request)", async () => { | ||
const mockRequest = sinon | ||
.stub(mockValues.requestClient, "httpPatch") | ||
.resolves(mockValues.mockPostLimitedPartnershipResponse[400]); | ||
|
||
const service = new LimitedPartnershipsService( | ||
mockValues.requestClient | ||
); | ||
|
||
const response = await service.patchLimitedPartnership( | ||
mockValues.TRANSACTION_ID, | ||
mockValues.SUBMISSION_ID, | ||
{ | ||
type: "email", | ||
data: {} | ||
} | ||
) as ApiErrorResponse; | ||
|
||
expect(mockRequest).to.have.been.calledOnce; | ||
expect( | ||
mockRequest.calledWith( | ||
"/transactions/12345/limited-partnership/partnership/09876", | ||
{ | ||
type: "email", | ||
data: {} | ||
|
||
} | ||
) | ||
).to.be.true; | ||
|
||
expect(response.httpStatusCode).to.equal(400); | ||
expect(response.errors?.[0]).to.equal(mockValues.BAD_REQUEST); | ||
}); | ||
}) | ||
}); |