Skip to content

Commit

Permalink
test: saving api
Browse files Browse the repository at this point in the history
  • Loading branch information
abhiShandy committed Oct 26, 2023
1 parent 26c9234 commit 4fdc76a
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions pages/api/saving.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import Stripe from "stripe";
import handler from "./saving";

jest.mock("stripe", () => {
return jest.fn().mockImplementation(() => {
return {
paymentIntents: {
create: jest.fn().mockResolvedValueOnce({
client_secret: "secret",
}).mockRejectedValueOnce(new Error("error")),
},
};
});
});

describe("saving", () => {
it("should return a client secret", async () => {
console.log = jest.fn();

const req = {
body: {
idSaving: "123",
amount: 100,
currency: "USD",
},
};

const res = {
send: jest.fn(),
};

await handler(req, res);

expect(res.send).toHaveBeenCalledWith({
clientSecret: expect.any(String),
});
});

it("should log error", async () => {
console.log = jest.fn();

const req = {
body: {
idSaving: "123",
amount: 100,
currency: "USD",
},
};

const res = {
send: jest.fn(),
};

Stripe.mockImplementationOnce(() => {
throw new Error("error");
});

await handler(req, res);

expect(console.log).toHaveBeenCalledWith("api/saving", new Error("error"));
});
});

1 comment on commit 4fdc76a

@vercel
Copy link

@vercel vercel bot commented on 4fdc76a Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

wii-qare-fe – ./

wii-qare-fe-git-main-wiiqare.vercel.app
wii-qare-fe.vercel.app
wii-qare-fe-wiiqare.vercel.app

Please sign in to comment.