mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-25 08:31:37 -05:00
test: wrap with describe block
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { BetterAuthOptions } from "@better-auth/core";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
expireCookie,
|
||||
getCookieCache,
|
||||
@@ -99,38 +99,41 @@ describe("cookies", async () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("should use secure cookies in production when baseURL is not configured", async () => {
|
||||
// Set NODE_ENV to production
|
||||
vi.stubEnv("NODE_ENV", "production");
|
||||
|
||||
// Reset modules to reload with new NODE_ENV
|
||||
vi.resetModules();
|
||||
|
||||
// Re-import modules after NODE_ENV change
|
||||
const { getTestInstance: getTestInstanceReloaded } = await import(
|
||||
"../test-utils/test-instance"
|
||||
);
|
||||
|
||||
const { client, testUser } = await getTestInstanceReloaded({
|
||||
baseURL: undefined,
|
||||
describe("production environment", () => {
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
vi.resetModules();
|
||||
});
|
||||
|
||||
await client.signIn.email(
|
||||
{
|
||||
email: testUser.email,
|
||||
password: testUser.password,
|
||||
},
|
||||
{
|
||||
onResponse(context) {
|
||||
const setCookie = context.response.headers.get("set-cookie");
|
||||
expect(setCookie).toContain("Secure");
|
||||
},
|
||||
},
|
||||
);
|
||||
it("should use secure cookies when baseURL is not configured", async () => {
|
||||
// Set NODE_ENV to production
|
||||
vi.stubEnv("NODE_ENV", "production");
|
||||
|
||||
// Clean up
|
||||
vi.unstubAllEnvs();
|
||||
vi.resetModules();
|
||||
// Reset modules to reload with new NODE_ENV
|
||||
vi.resetModules();
|
||||
|
||||
// Re-import modules after NODE_ENV change
|
||||
const { getTestInstance: getTestInstanceReloaded } = await import(
|
||||
"../test-utils/test-instance"
|
||||
);
|
||||
|
||||
const { client, testUser } = await getTestInstanceReloaded({
|
||||
baseURL: undefined,
|
||||
});
|
||||
|
||||
await client.signIn.email(
|
||||
{
|
||||
email: testUser.email,
|
||||
password: testUser.password,
|
||||
},
|
||||
{
|
||||
onResponse(context) {
|
||||
const setCookie = context.response.headers.get("set-cookie");
|
||||
expect(setCookie).toContain("Secure");
|
||||
},
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user