import {
  require_supertest
} from "../chunk-X4KDK3QI.mjs";
import {
  describe,
  globalExpect,
  it
} from "../chunk-C6GVXLFJ.mjs";
import {
  createServer
} from "../chunk-RBFZAKDG.mjs";
import "../chunk-YONIONVZ.mjs";
import "../chunk-TRQQUNIW.mjs";
import "../chunk-XMSQJY6Q.mjs";
import "../chunk-BU4RBUBJ.mjs";
import {
  __toESM
} from "../chunk-2CV3WTQN.mjs";

// src/__tests__/app.test.ts
var import_supertest = __toESM(require_supertest());
describe("app", async () => {
  const rpc = createServer({
    fn: {
      // prefix: '/apk2',
    }
  });
  rpc.fn("/a", function(a) {
    return { a };
  });
  rpc.fn("/b", function(a) {
    if (this.method === "POST") {
      return { a, method: "post" };
    }
    if (this.method === "GET") {
      return { a, method: "get" };
    }
  });
  rpc.fn("com.yourcompany.a", function(a) {
    return { a };
  });
  rpc.fn("com.yourcompany.b", function(a) {
    return `${this.path} , ${a} `;
  });
  rpc.add({
    "/add": function(a, b) {
      return { a };
    }
  });
  const request = (0, import_supertest.default)(rpc.callback());
  it("should start === rpc.callback", async () => {
    const request2 = (0, import_supertest.default)(rpc.start(30001));
    const res = await request2.get('/api/a?$p=["hello"]');
    globalExpect(res.type).toEqual("application/json");
    globalExpect(res.status).toEqual(200);
    globalExpect(res.body).toEqual({ a: "hello" });
  });
  it("should access /a", async () => {
    const res = await request.get('/api/a?$p=["hello"]');
    globalExpect(res.type).toEqual("application/json");
    globalExpect(res.status).toEqual(200);
    globalExpect(res.body).toEqual({ a: "hello" });
  });
  it("should access no routers[key]", async () => {
    const res = await request.get("/api/a123");
    globalExpect(res.type).toEqual("text/plain");
    globalExpect(res.status).toEqual(200);
    globalExpect(res.text).toEqual("not match $p param, no process");
  });
  it("should access no routers[key]", async () => {
    const res = await request.get('/api/a123?$p=["hello"]');
    globalExpect(res.type).toEqual("text/plain");
    globalExpect(res.status).toEqual(200);
    globalExpect(res.text).toEqual("[fn plugin] no fn repsonse, please check your fn if exist");
  });
  it("should access /add", async () => {
    const res = await request.get('/api/add?$p=["hello"]');
    globalExpect(res.type).toEqual("application/json");
    globalExpect(res.status).toEqual(200);
    globalExpect(res.body).toEqual({ a: "hello" });
  });
  it("should access GET /b", async () => {
    const res = await request.get('/api/b?$p=["hello1"]');
    globalExpect(res.type).toEqual("application/json");
    globalExpect(res.status).toEqual(200);
    globalExpect(res.body).toEqual({ a: "hello1", method: "get" });
  });
  it("should access POST /b", async () => {
    const res = await request.post("/api/b").send(["hello"]).set("Accept", "application/json");
    globalExpect(res.type).toEqual("application/json");
    globalExpect(res.status).toEqual(200);
    globalExpect(res.body).toEqual({ a: "hello", method: "post" });
  });
  it("should access com.yourcompany.b", async () => {
    const res = await request.get('/api/com/yourcompany/b?$p=["hello"]');
    globalExpect(res.type).toEqual("text/plain");
    globalExpect(res.status).toEqual(200);
    globalExpect(res.text).toEqual("/com/yourcompany/b , hello ");
  });
});
