// ! API 参考 https://httpbin.org/#/ import { expect, describe, it } from "vitest"; import { Link, authPlugin } from "../../src/index"; const root = __Root__; describe("auth 测试", function () { it("basic Auth 测试", async () => { const username = "Konghayao"; const passwd = "123456"; const link = new Link({ url: root + `/basic-auth/${username}/${passwd}`, }); return link .use( authPlugin({ type: "basic", username, password: passwd, }) ) .send() .then(async (res) => { const data = await res.json(); expect(data).to.eql({ authenticated: true, user: username, }); }); }); it("Bearer Auth 测试", async () => { const token = "34567"; const link = new Link({ url: root + `/bearer`, }); return link .use( authPlugin({ type: "bearer", token, }) ) .send() .then(async (res) => { const data = await res.json(); expect(data).to.eql({ authenticated: true, token, }); }); }); });