UNPKG

@pedwise/next-firebase-auth-edge

Version:

Next.js 13 Firebase Authentication for Edge and server runtimes. Dedicated for Next 13 server components. Compatible with Next.js middleware.

41 lines 2.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const is_expired_1 = require("./is-expired"); const decode_1 = require("./decode"); jest.mock("./decode"); const mockedDecode = decode_1.decode; const fakeJWT = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJleHAiOjk0NjY4ODQwMH0.c2VjcmV0"; describe("isExpired", () => { it("should return false for JWT without exp", () => { expect.assertions(1); mockedDecode.mockImplementation(() => ({})); expect((0, is_expired_1.isExpired)(fakeJWT)).toBe(false); }); it("should return false for JWT with future exp date", () => { expect.assertions(1); const exp = Math.floor(new Date().getTime() / 1000) + 60; mockedDecode.mockImplementation(() => ({ exp })); expect((0, is_expired_1.isExpired)(fakeJWT)).toBe(false); }); it("should return true for JWT with past exp date", () => { expect.assertions(1); const exp = Math.floor(new Date().getTime() / 1000) - 60; mockedDecode.mockImplementation(() => ({ exp })); expect((0, is_expired_1.isExpired)(fakeJWT)).toBe(true); }); describe("options.expiredWithinSeconds", () => { it("should return false when expiredWithinSeconds = 60 and JWT is expiring in 61 seconds", () => { expect.assertions(1); const exp = Math.floor(new Date().getTime() / 1000) + 61; mockedDecode.mockImplementation(() => ({ exp })); expect((0, is_expired_1.isExpired)(fakeJWT, { expiredWithinSeconds: 60 })).toBe(false); }); it("should return true when expiredWithinSeconds = 60 and JWT is expiring in 59 seconds", () => { expect.assertions(1); const exp = Math.floor(new Date().getTime() / 1000) + 59; mockedDecode.mockImplementation(() => ({ exp })); expect((0, is_expired_1.isExpired)(fakeJWT, { expiredWithinSeconds: 60 })).toBe(true); }); }); }); //# sourceMappingURL=is-expired.test.js.map