-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
1 changed file
with
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import StripeService from "./StripeService" | ||
import { productMock } from "test-config/mocks/Stripe.mock" | ||
|
||
jest.mock("stripe", () => { | ||
const stripe = jest.requireActual("stripe") | ||
jest | ||
.spyOn(stripe.resources.Products.prototype, "search") | ||
.mockImplementation(() => Promise.resolve([productMock])) | ||
|
||
jest | ||
.spyOn(stripe.resources.Products.prototype, "list") | ||
.mockImplementation((props) => { | ||
const { limit = 10 } = props as { | ||
limit?: number | ||
starting_after?: string | ||
} | ||
const products = [] | ||
for (let i=0; i < limit; ++i) { | ||
products.push(productMock) | ||
} | ||
|
||
}) | ||
|
||
jest | ||
.spyOn(stripe.resources.Products.prototype, "retrieve") | ||
.mockImplementation((id) => Promise.resolve({ ...productMock, id })) | ||
return stripe | ||
}) | ||
|
||
describe("Stripe service functionality", () => { | ||
|
||
it("should get a product with lookup key", async () => { | ||
const result = await new StripeService().getProductsWithLookupKey( | ||
"random_lookupKey" | ||
) | ||
expect(result).toEqual(productMock) | ||
}) | ||
|
||
it("should get all products with default length", async () => { | ||
const result = await new StripeService().getAllProducts() | ||
expect(result.length).toBe(10) | ||
}) | ||
|
||
it("should get a product by id", async () => { | ||
const result = await new StripeService().getProductById("random_id") | ||
expect(result).toEqual(productMock) | ||
}) | ||
|
||
it("should get a product by metadata", async () => { | ||
const result = await new StripeService().getProductByMetadata("random_key", "random_value") | ||
expect(result).toEqual(productMock) | ||
}) | ||
|
||
}) |