Use `vitest` for backend tests: - `bench` script now uses [vitest's `bench`](https://vitest.dev/api/#bench) - e2e test fails with same error happening now with jest:`data-testid` attribute not present. vitest left, jest right <img width="1264" height="603" alt="image" src="https://github.com/user-attachments/assets/56fc43a6-e143-4208-bf14-7e016aae7fa9" />
65 lines
1.7 KiB
JavaScript
65 lines
1.7 KiB
JavaScript
// @ts-check
|
|
|
|
import axios from "axios";
|
|
import MockAdapter from "axios-mock-adapter";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
|
|
import pin from "../../api-renamed/pin.js";
|
|
import { renderError } from "../../src/common/render.js";
|
|
import { data_user } from "../test-data/pin-data.js";
|
|
|
|
const mock = new MockAdapter(axios);
|
|
|
|
afterEach(() => {
|
|
mock.reset();
|
|
});
|
|
|
|
describe("Test /api/pin", () => {
|
|
it("should render error card if username not in whitelist", async () => {
|
|
const req = {
|
|
query: {
|
|
username: "renovate-bot",
|
|
repo: "convoychat",
|
|
},
|
|
};
|
|
const res = {
|
|
setHeader: vi.fn(),
|
|
send: vi.fn(),
|
|
};
|
|
mock.onPost("https://api.github.com/graphql").reply(200, data_user);
|
|
|
|
await pin(req, res);
|
|
|
|
expect(res.setHeader).toHaveBeenCalledWith("Content-Type", "image/svg+xml");
|
|
expect(res.send).toHaveBeenCalledWith(
|
|
renderError({
|
|
message: "This username is not whitelisted",
|
|
secondaryMessage: "Please deploy your own instance",
|
|
renderOptions: { show_repo_link: false },
|
|
}),
|
|
);
|
|
});
|
|
|
|
it("should render error card if missing required parameters", async () => {
|
|
const req = {
|
|
query: {},
|
|
};
|
|
const res = {
|
|
setHeader: vi.fn(),
|
|
send: vi.fn(),
|
|
};
|
|
mock.onPost("https://api.github.com/graphql").reply(200, data_user);
|
|
|
|
await pin(req, res);
|
|
|
|
expect(res.setHeader).toHaveBeenCalledWith("Content-Type", "image/svg+xml");
|
|
expect(res.send).toHaveBeenCalledWith(
|
|
renderError({
|
|
message: "This username is not whitelisted",
|
|
secondaryMessage: "Please deploy your own instance",
|
|
renderOptions: { show_repo_link: false },
|
|
}),
|
|
);
|
|
});
|
|
});
|