refactor: logout test
This commit is contained in:
@ -11,10 +11,7 @@ import {
|
||||
trimSlashes,
|
||||
normalize,
|
||||
} from "../../src/common/util"
|
||||
import { Cookie as CookieEnum } from "../../src/node/routes/login"
|
||||
import { hash } from "../../src/node/util"
|
||||
import { PASSWORD } from "../utils/constants"
|
||||
import { checkForCookie, createCookieIfDoesntExist, loggerModule, Cookie } from "../utils/helpers"
|
||||
import { loggerModule } from "../utils/helpers"
|
||||
|
||||
const dom = new JSDOM()
|
||||
global.document = dom.window.document
|
||||
@ -252,58 +249,4 @@ describe("util", () => {
|
||||
expect(loggerModule.logger.error).toHaveBeenCalledWith("api: oh no")
|
||||
})
|
||||
})
|
||||
|
||||
describe("checkForCookie", () => {
|
||||
it("should check if the cookie exists and has a value", () => {
|
||||
const fakeCookies: Cookie[] = [
|
||||
{
|
||||
name: CookieEnum.Key,
|
||||
value: hash(PASSWORD),
|
||||
domain: "localhost",
|
||||
secure: false,
|
||||
sameSite: "Lax",
|
||||
httpOnly: false,
|
||||
expires: 18000,
|
||||
path: "/",
|
||||
},
|
||||
]
|
||||
expect(checkForCookie(fakeCookies, CookieEnum.Key)).toBe(true)
|
||||
})
|
||||
it("should return false if there are no cookies", () => {
|
||||
const fakeCookies: Cookie[] = []
|
||||
expect(checkForCookie(fakeCookies, "key")).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe("createCookieIfDoesntExist", () => {
|
||||
it("should create a cookie if it doesn't exist", () => {
|
||||
const cookies: Cookie[] = []
|
||||
const cookieToStore = {
|
||||
name: CookieEnum.Key,
|
||||
value: hash(PASSWORD),
|
||||
domain: "localhost",
|
||||
secure: false,
|
||||
sameSite: "Lax" as const,
|
||||
httpOnly: false,
|
||||
expires: 18000,
|
||||
path: "/",
|
||||
}
|
||||
expect(createCookieIfDoesntExist(cookies, cookieToStore)).toStrictEqual([cookieToStore])
|
||||
})
|
||||
it("should return the same cookies if the cookie already exists", () => {
|
||||
const PASSWORD = "123supersecure"
|
||||
const cookieToStore = {
|
||||
name: CookieEnum.Key,
|
||||
value: hash(PASSWORD),
|
||||
domain: "localhost",
|
||||
secure: false,
|
||||
sameSite: "Lax" as const,
|
||||
httpOnly: false,
|
||||
expires: 18000,
|
||||
path: "/",
|
||||
}
|
||||
const cookies: Cookie[] = [cookieToStore]
|
||||
expect(createCookieIfDoesntExist(cookies, cookieToStore)).toStrictEqual(cookies)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user