-
Notifications
You must be signed in to change notification settings - Fork 0
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
9309bd4
commit 77de377
Showing
5 changed files
with
360 additions
and
74 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
110 changes: 110 additions & 0 deletions
110
packages/auth0-acul-js/tests/unit/screens/login-passwordless-email-code.test.ts
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,110 @@ | ||
import LoginPasswordlessEmailCode from "../../../src/screens/login-passwordless-email-code"; | ||
import { baseContextData } from "../../data/test-data"; | ||
import { FormHandler } from "../../../src/utils/form-handler"; | ||
import { SubmitCodeOptions } from "interfaces/screens/login-passwordless-email-code"; | ||
import { CustomOptions } from "interfaces/common"; | ||
|
||
jest.mock("../../../src/utils/form-handler"); | ||
|
||
describe("LoginPasswordlessEmailCode", () => { | ||
let loginPasswordlessEmailCode: LoginPasswordlessEmailCode; | ||
let mockFormHandler: { submitData: jest.Mock }; | ||
|
||
beforeEach(() => { | ||
global.window = Object.create(window); | ||
window.universal_login_context = baseContextData; | ||
|
||
loginPasswordlessEmailCode = new LoginPasswordlessEmailCode(); | ||
|
||
mockFormHandler = { | ||
submitData: jest.fn(), | ||
}; | ||
(FormHandler as jest.Mock).mockImplementation(() => mockFormHandler); | ||
}); | ||
|
||
describe("submitCode method", () => { | ||
it("should handle submitCode with valid payload correctly", async () => { | ||
const payload: SubmitCodeOptions = { | ||
email: "[email protected]", | ||
code: "123456", | ||
}; | ||
await loginPasswordlessEmailCode.submitCode(payload); | ||
|
||
expect(mockFormHandler.submitData).toHaveBeenCalledTimes(1); | ||
expect(mockFormHandler.submitData).toHaveBeenCalledWith( | ||
expect.objectContaining(payload) | ||
); | ||
}); | ||
|
||
it("should throw error when promise is rejected", async () => { | ||
mockFormHandler.submitData.mockRejectedValue(new Error("Mocked reject")); | ||
const payload: SubmitCodeOptions = { | ||
email: "[email protected]", | ||
code: "123456", | ||
}; | ||
await expect( | ||
loginPasswordlessEmailCode.submitCode(payload) | ||
).rejects.toThrow("Mocked reject"); | ||
}); | ||
|
||
it("should throw error when email is empty", async () => { | ||
mockFormHandler.submitData.mockRejectedValueOnce( | ||
new Error("Invalid email") | ||
); | ||
const payload = { email: "", code: "123456" }; | ||
|
||
await expect( | ||
loginPasswordlessEmailCode.submitCode(payload) | ||
).rejects.toThrow("Invalid email"); | ||
}); | ||
|
||
it("should throw error when code is empty", async () => { | ||
mockFormHandler.submitData.mockRejectedValueOnce( | ||
new Error("Invalid code") | ||
); | ||
const payload = { email: "[email protected]", code: "" }; | ||
|
||
await expect( | ||
loginPasswordlessEmailCode.submitCode(payload) | ||
).rejects.toThrow("Invalid code"); | ||
}); | ||
}); | ||
|
||
describe("resendCode method", () => { | ||
it("should handle resendCode with valid payload correctly", async () => { | ||
const payload: CustomOptions = { | ||
email: "[email protected]", | ||
}; | ||
await loginPasswordlessEmailCode.resendCode(payload); | ||
|
||
expect(mockFormHandler.submitData).toHaveBeenCalledTimes(1); | ||
expect(mockFormHandler.submitData).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
...payload, | ||
action: "resend", | ||
}) | ||
); | ||
}); | ||
|
||
it("should handle resendCode without payload correctly", async () => { | ||
await loginPasswordlessEmailCode.resendCode(); | ||
|
||
expect(mockFormHandler.submitData).toHaveBeenCalledTimes(1); | ||
expect(mockFormHandler.submitData).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
action: "resend", | ||
}) | ||
); | ||
}); | ||
|
||
it("should throw error when promise is rejected", async () => { | ||
mockFormHandler.submitData.mockRejectedValue(new Error("Mocked reject")); | ||
const payload: CustomOptions = { | ||
email: "[email protected]", | ||
}; | ||
await expect( | ||
loginPasswordlessEmailCode.resendCode(payload) | ||
).rejects.toThrow("Mocked reject"); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.