generated from nhcarrigan/template
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
|
/**
|
||
|
* @copyright nhcarrigan
|
||
|
* @license Naomi's Public License
|
||
|
* @author Naomi Carrigan
|
||
|
*/
|
||
|
/* eslint-disable new-cap */
|
||
|
import { NextResponse } from "next/server";
|
||
|
import { describe, it, expect, vi } from "vitest";
|
||
|
import { GET } from "../../../../src/app/api/contribute/route";
|
||
|
import { getCodebergIssues } from "../../../../src/lib/codeberg";
|
||
|
|
||
|
vi.mock("../../../../src/lib/codeberg");
|
||
|
|
||
|
describe("gET /api/contribute", () => {
|
||
|
it("should return a sorted and limited list of activities", async() => {
|
||
|
expect.assertions(2);
|
||
|
const mockCodebergData = [
|
||
|
{
|
||
|
body: "body1",
|
||
|
html_url: "https://codeberg.org/repo1/issue1",
|
||
|
labels: [ { name: "label1" } ],
|
||
|
number: 1,
|
||
|
title: "issue1",
|
||
|
},
|
||
|
];
|
||
|
|
||
|
vi.mocked(getCodebergIssues).mockResolvedValue(mockCodebergData);
|
||
|
|
||
|
const response = await GET();
|
||
|
const json = await response.json();
|
||
|
|
||
|
expect(response, "did not respond with Next").toBeInstanceOf(NextResponse);
|
||
|
expect(json, "incorrect payload").toStrictEqual([
|
||
|
{
|
||
|
body: "body1",
|
||
|
labels: [ "label1" ],
|
||
|
number: 1,
|
||
|
title: "issue1",
|
||
|
url: "https://codeberg.org/repo1/issue1",
|
||
|
},
|
||
|
]);
|
||
|
});
|
||
|
|
||
|
it("should handle empty data from both sources", async() => {
|
||
|
expect.assertions(2);
|
||
|
vi.mocked(getCodebergIssues).mockResolvedValue([]);
|
||
|
|
||
|
const response = await GET();
|
||
|
const json = await response.json();
|
||
|
|
||
|
expect(response, "did not use Next to respond").
|
||
|
toBeInstanceOf(NextResponse);
|
||
|
expect(json, "was not empty array").toStrictEqual([]);
|
||
|
});
|
||
|
});
|