-
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.
- Loading branch information
1 parent
9569c93
commit 5995997
Showing
4 changed files
with
101 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* @module Resources/ECInfo | ||
*/ | ||
import { AuthParams, ResponseCallback, SendData } from "../api/RestAPI"; | ||
|
||
import { CRUDResource } from "./CRUDResource"; | ||
import { ECFormLinkItem } from "./ECFormLinks"; | ||
import { ECFormItem } from "./ECForms"; | ||
import { EmailItem } from "./Emails"; | ||
|
||
export type ECInfoItem = { | ||
id: string; | ||
jwt: string; | ||
|
||
form: ECFormItem; | ||
link: ECFormLinkItem; | ||
email: EmailItem; | ||
}; | ||
|
||
export type ECInfoGetParams = { secret: string }; | ||
export type ResponseECInfo = ECInfoItem; | ||
|
||
export class ECInfo extends CRUDResource { | ||
static routeBase = "/checkout/info"; | ||
|
||
get( | ||
id: string, | ||
data?: SendData<ECInfoGetParams>, | ||
auth?: AuthParams, | ||
callback?: ResponseCallback<ResponseECInfo> | ||
): Promise<ResponseECInfo> { | ||
return this._getRoute()(data, callback, auth, { id }); | ||
} | ||
} |
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,16 @@ | ||
import { v4 as uuid } from "uuid"; | ||
|
||
import { ECInfoItem } from "../../src/resources/ECInfo"; | ||
|
||
import { generateFixture as generateForm } from "./ec-form"; | ||
import { generateFixture as generateLink } from "./ec-form-link"; | ||
import { generateFixture as generateEmail } from "./emails"; | ||
|
||
export const generateFixture = (): ECInfoItem => ({ | ||
id: uuid(), | ||
jwt: "myjwt", | ||
|
||
form: generateForm(), | ||
link: generateLink(), | ||
email: generateEmail(), | ||
}); |
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,48 @@ | ||
import { expect } from "chai"; | ||
import fetchMock from "fetch-mock"; | ||
import { pathToRegexp } from "path-to-regexp"; | ||
import { v4 as uuid } from "uuid"; | ||
|
||
import { RestAPI } from "../../src/api/RestAPI"; | ||
import { ECInfo } from "../../src/resources/ECInfo"; | ||
import { generateFixture as generateCheckoutInfo } from "../fixtures/ec-info"; | ||
import { testEndpoint } from "../utils"; | ||
|
||
describe("EC Form links", () => { | ||
let api: RestAPI; | ||
let ecInfo: ECInfo; | ||
|
||
const recordData = generateCheckoutInfo(); | ||
const recordPathMatcher = new RegExp( | ||
`^${testEndpoint}${pathToRegexp("/checkout/info/:id", [], { start: false, end: false }).source}` | ||
); | ||
|
||
beforeEach(() => { | ||
api = new RestAPI({ endpoint: testEndpoint }); | ||
ecInfo = new ECInfo(api); | ||
}); | ||
|
||
afterEach(() => { | ||
fetchMock.restore(); | ||
}); | ||
|
||
context("GET /checkout/info/:id", () => { | ||
it("should get response", async () => { | ||
fetchMock.getOnce( | ||
{ | ||
url: recordPathMatcher, | ||
query: { | ||
secret: "mysecret", | ||
}, | ||
}, | ||
{ | ||
status: 200, | ||
body: recordData, | ||
headers: { "Content-Type": "application/json" }, | ||
} | ||
); | ||
|
||
await expect(ecInfo.get(uuid(), { secret: "mysecret" })).to.eventually.eql(recordData); | ||
}); | ||
}); | ||
}); |