-
Notifications
You must be signed in to change notification settings - Fork 1
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
26c9234
commit 4fdc76a
Showing
1 changed file
with
62 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,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")); | ||
}); | ||
}); |
4fdc76a
There was a problem hiding this comment.
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