Files
github-stats-extended/apps/backend/tests/private-instance/api.test.js
T
Martin 6e109e50d1 restructure tests, add tests, remove dotenv (#83)
- add a few tests
- re-organize tests to allow testing with different env vars and
creating a combined coverage report
- extract test data into separate files, because importing data from
testA in testB leads to weird jest errors
- remove `dotenv` because it's not being used
- "GitHub Trends" -> "GitHub Stats Extended"
2026-02-20 19:38:16 +01:00

42 lines
1.1 KiB
JavaScript

// @ts-check
import { afterEach, describe, expect, it, jest } from "@jest/globals";
import axios from "axios";
import MockAdapter from "axios-mock-adapter";
import api from "../../api-renamed/index.js";
import { renderError } from "../../src/common/render.js";
import { data_stats } from "../test-data/api-data.js";
const mock = new MockAdapter(axios);
afterEach(() => {
mock.reset();
});
describe("Test /api/", () => {
it("should render error card if username not in whitelist", async () => {
const req = {
query: {
username: "renovate-bot",
},
};
const res = {
setHeader: jest.fn(),
send: jest.fn(),
};
mock.onPost("https://api.github.com/graphql").replyOnce(200, data_stats);
await api(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 },
}),
);
});
});