-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* started test driving data collector util * add tests and todos, break fns down a bit * add fraudnet util * update correct fn url * cleanup * outline of fraudnet work * ohhhh boy, its messy vitest/flow stuff * more test crazyiness * moving server tests and client api to vitest WIP * lots of tests, lots of inprogress * graphql tests updated * lots more tests and such, evaluating the meta things cause ugh * in prgoress but coming along a ton...merge script and scriptutils tests * so close. a couple challenges but otherwise so much progress converting to vitest * so many files done now to fix up some lingering problem tests * all skipped tests addressed other than logger * remove client test index and remove msw usage for mocking request * remove console logs * remove unused modules and comment out logger test for now * remove some deps * remove local env pathin domain * remove logger from vitest run while evaluate deletion * remove logger from vitest run while evaluate deletion * got coverage going for vitest on src files * use single coverageupload in main flow * remove mocha * broken for now thats ok * start testing fraudnet * add tests for fraudnet * spy on logger, handle test for suppressing of all errors * clear all gql mocks * removed unneeded files, scriptUtils now all in script.test.js * Update src/fraudnet.js * remove unused vars/imports * remove iteration from single case test * remove test index, iterate over globals for vitest setup * make envs a fn for clarity * clean up vite config file * so much flow ignore bruh * nock out some of the lint issues, but not all * resotre logger domain local block * fix api test * forgot to import host and protocol fns * colocate test files and impl, remove test globals file as not needed * put test file back since it's used in other repos * fix globals ref in webpack config * remove sticky session id use because flow * remove test ref from lint step * fix lint errors * fix flow again * put make mock element function in helper and adjust to always pass mock url * fix test lint imports * add input type for makemockscript * add test back as an export * update old coverage ignore lines to work with vitest v8 * move globals vars to own file for webpack and vitest usage * fix webpack build and ignore hermes flow types * add back in stickysession once belter updated * test stickysessionid fix * remove old codeblock comment * sort input --------- Co-authored-by: Shraddha Shah <[email protected]>
- Loading branch information
Showing
43 changed files
with
1,628 additions
and
2,243 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
This file was deleted.
Oops, something went wrong.
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
3 changes: 2 additions & 1 deletion
3
test/server/meta.integration.test.js → server/meta.integration.test.js
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 |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* @flow */ | ||
import { describe, beforeEach, it, expect, vi } from "vitest"; | ||
import { getCurrentScript, request, memoize } from "@krakenjs/belter/src"; | ||
|
||
import { createAccessToken, createOrder } from "./api"; | ||
|
||
vi.mock("@krakenjs/belter/src", async () => { | ||
const actual = await vi.importActual("@krakenjs/belter/src"); | ||
return { | ||
...actual, | ||
getCurrentScript: vi.fn(), | ||
request: vi.fn().mockResolvedValue(), | ||
}; | ||
}); | ||
|
||
describe("api cases", () => { | ||
let order; | ||
const invalidClientId = "invalid-client-id"; | ||
const emptyResponseClientId = "empty-response-client-id"; | ||
const createOrderValidId = "create-order-valid-order-id"; | ||
const expectedToken = | ||
"A21AAKNZBaqilFBC4dVVz-tr-ySIT78NREeBidy3lkGdr-EA8wbhGrByPayhgnJRPE5xg4QW46moDbCFjZ13i1GH-Ax4SjtjA"; | ||
const defaultAuthResponse = { | ||
scope: "https://uri.paypal.com/services/invoicing", | ||
access_token: expectedToken, | ||
token_type: "Bearer", | ||
app_id: "APP-80W284485P519543T", | ||
expires_in: 31838, | ||
nonce: "2022-03-07T22:41:38ZqHkiC0_odfzFwo27_X0wVuF67STYq39KRplBeeyY2bk", | ||
error: null, | ||
}; | ||
|
||
beforeEach(() => { | ||
memoize.clear(); | ||
window.__PAYPAL_DOMAIN__ = "testurl"; | ||
// $FlowIgnore | ||
getCurrentScript.mockReturnValue({ | ||
src: `https://sdkplz.com/sdk/js?intent=capture`, | ||
attributes: [], | ||
}); | ||
vi.clearAllMocks(); | ||
|
||
order = { | ||
intent: "CAPTURE", | ||
purchase_units: [ | ||
{ | ||
amount: { | ||
value: "10.00", | ||
currency_code: "USD", | ||
}, | ||
}, | ||
], | ||
}; | ||
}); | ||
|
||
describe("createAccessToken()", () => { | ||
it("createAccessToken should return a valid token", async () => { | ||
// $FlowIgnore | ||
request.mockResolvedValueOnce({ body: defaultAuthResponse }); | ||
|
||
const result = await createAccessToken("testClient"); | ||
|
||
expect(result).toEqual(expectedToken); | ||
}); | ||
|
||
it("createAccessToken should throw invalid client argument error", async () => { | ||
// $FlowIgnore | ||
request.mockResolvedValueOnce({ body: { error: "invalid_client" } }); | ||
|
||
await expect(() => | ||
createAccessToken(invalidClientId) | ||
).rejects.toThrowError(/Auth Api invalid client id:/); | ||
}); | ||
|
||
it("createAccessToken should return an error message when response is an empty object", async () => { | ||
// $FlowIgnore | ||
request.mockResolvedValueOnce({ body: {} }); | ||
|
||
await expect(() => | ||
createAccessToken(emptyResponseClientId) | ||
).rejects.toThrow(/Auth Api response error:/); | ||
}); | ||
}); | ||
|
||
describe("createOrder()", () => { | ||
it("createOrder should throw an error when clientId is null", () => { | ||
// $FlowIgnore | ||
expect(() => createOrder(null)).toThrowError(/Client ID not passed/); | ||
}); | ||
|
||
it("createOrder should throw an error when order is null", () => { | ||
// $FlowIgnore | ||
expect(() => createOrder("testClient", null)).toThrow( | ||
/Expected order details to be passed/ | ||
); | ||
}); | ||
|
||
it("createOrder should throw an error when order intent does not match with query parameters intent", () => { | ||
const expectedErrorMessage = | ||
"Unexpected intent: AUTHORIZE passed to order.create. Please ensure you are passing /sdk/js?intent=authorize in the paypal script tag."; | ||
|
||
order.intent = "AUTHORIZE"; | ||
|
||
expect(() => createOrder("testClient", order)).toThrowError( | ||
expectedErrorMessage | ||
); | ||
}); | ||
|
||
it("createOrder should throw an error when order currency does not match with query parameters currency", () => { | ||
const expectedErrorMessage = | ||
"Unexpected currency: AUD passed to order.create. Please ensure you are passing /sdk/js?currency=AUD in the paypal script tag."; | ||
order.purchase_units[0].amount.currency_code = "AUD"; | ||
|
||
expect(() => createOrder("testClient", order)).toThrow( | ||
expectedErrorMessage | ||
); | ||
}); | ||
|
||
it("createOrder should throw an error when order identifier is not in the server response", async () => { | ||
const expectedErrorMessage = "Order Api response error:"; | ||
const failuredPayload = {}; | ||
|
||
request | ||
// $FlowIgnore | ||
.mockResolvedValueOnce({ body: defaultAuthResponse }) | ||
.mockResolvedValueOnce({ body: failuredPayload }); | ||
|
||
await expect(() => createOrder("testClient", order)).rejects.toThrow( | ||
expectedErrorMessage | ||
); | ||
}); | ||
|
||
it("createOrder should return a valid orderId", async () => { | ||
const expectedOrderId = "9BL31648CM342010L"; | ||
const mockOrderResponse = { | ||
id: expectedOrderId, | ||
status: "CREATED", | ||
links: [], | ||
}; | ||
|
||
request | ||
// $FlowIgnore | ||
.mockResolvedValueOnce({ body: defaultAuthResponse }) | ||
.mockResolvedValueOnce({ body: mockOrderResponse }); | ||
|
||
const result = await createOrder(createOrderValidId, order); | ||
expect(result).toEqual(expectedOrderId); | ||
}); | ||
}); | ||
}); |
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,39 @@ | ||
/* @flow */ | ||
import { describe, it, expect } from "vitest"; | ||
|
||
import { | ||
getPayPalLoggerDomain, | ||
buildPayPalUrl, | ||
buildPayPalAPIUrl, | ||
getPayPalLoggerUrl, | ||
} from "./domains"; | ||
|
||
describe(`config cases`, () => { | ||
it("should successfully get the global paypal logger domain", () => { | ||
const expectedDomain = "mock://www.paypal.com"; | ||
window.__PAYPAL_DOMAIN__ = expectedDomain; | ||
const domain = getPayPalLoggerDomain(); | ||
expect(domain).toEqual(expectedDomain); | ||
}); | ||
|
||
it("should successfully build a paypal url", () => { | ||
const expectedPayPalUrl = `${window.location.protocol}//${window.location.host}/foo/bar`; | ||
const result = buildPayPalUrl("/foo/bar"); | ||
|
||
expect(result).toEqual(expectedPayPalUrl); | ||
}); | ||
|
||
it("should successfully build a paypal api url", () => { | ||
const expectedPayPalUrl = `${window.location.protocol}//${window.location.host}/bar/baz`; | ||
const result = buildPayPalAPIUrl("/bar/baz"); | ||
|
||
expect(result).toEqual(expectedPayPalUrl); | ||
}); | ||
|
||
it("should successfully build a paypal logger url", () => { | ||
const expectedPayPalUrl = `${window.location.protocol}//${window.location.host}/xoplatform/logger/api/logger`; | ||
const result = getPayPalLoggerUrl(); | ||
|
||
expect(result).toEqual(expectedPayPalUrl); | ||
}); | ||
}); |
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
Oops, something went wrong.