Open kodermax opened 2 months ago
@kodermax Request cloning doesn't work in bun so it's a dirty workaround to make it work on bun.This will work for json also
@divyam234 Have you tried the latest version of bun?
my json doesn't work in tests. My Code:
import { describe, expect, it } from "bun:test";
import { api } from "../index";
import { encode } from "@auth/core/jwt";
import { env } from "../../env";
describe("Companies API", () => {
describe("createCompany", () => {
it("should create a new company", async () => {
const token = await encode({
salt: "authjs.session-token",
secret: env.AUTH_SECRET,
token: {
id: 1,
},
});
const data = {
name: "Test Company",
};
const res = await api.request("/api/companies", {
method: "POST",
headers: {
"content-type": "application/json",
cookie: `authjs.session-token=${token}`,
},
body: JSON.stringify(data),
});
expect(res.status).toBe(201);
});
});
describe("getCompanies", () => {
it("should get all companies", async () => {
const token = await encode({
salt: "authjs.session-token",
secret: env.AUTH_SECRET,
token: {
id: 1,
},
});
const res = await api.request("/api/companies", {
method: "GET",
headers: {
"content-type": "application/json",
cookie: `authjs.session-token=${token}`,
},
});
expect(res.status).toBe(200);
const data = await res.json();
expect(Array.isArray(data)).toBe(true);
});
});
});
https://github.com/honojs/middleware/blob/e488b9f08acf6cdb756114831d7aa5e7da3fc8f7/packages/auth-js/src/index.ts#L42
why do we use a different request for bun, in this case, json does not work when we use burn? @divyam234 can you look at it?