mc-publish/test/unit-tests/utils/modrinth/modrinth.test.ts

76 lines
3 KiB
TypeScript
Raw Normal View History

2022-06-06 11:17:42 -04:00
import { describe, test, expect } from "@jest/globals";
2022-07-05 13:44:29 -04:00
import { getProject, getVersions } from "../../../../src/utils/modrinth";
const timeout = 15000;
describe("getProject", () => {
test("returned versions have expected ids", async () => {
const projects = {
"sodium": "AANobbMI",
"fabric-api": "P7dR8mSH",
"sync-fabric": "OrJTMhHF",
"nether-chest": "okOUGirG",
"ebe": "OVuFYfre",
};
for (const [slug, id] of Object.entries(projects)) {
const project = await getProject(slug);
expect(project).toHaveProperty("id", id);
}
}, timeout);
test("the method returns null if project with the given slug does not exist", async () => {
const nonExistentProjects = [
"Na-11",
"api-fabric",
"sync-forge",
"ever-chest",
"beb",
"i-swear-to-god-if-someone-registers-these-mods"
];
for (const slug of nonExistentProjects) {
const project = await getProject(slug);
expect(project).toBeNull();
}
}, timeout);
});
describe("getVersions", () => {
test("returns unfiltered versions if no parameters were passed", async () => {
const versions = await getVersions("terra");
expect(versions.find(x => x.featured)).toBeTruthy();
expect(versions.find(x => !x.featured)).toBeTruthy();
expect(versions.find(x => x.loaders.includes("fabric"))).toBeTruthy();
expect(versions.find(x => x.loaders.includes("forge"))).toBeTruthy();
expect(versions.find(x => x.game_versions.includes("1.18.2"))).toBeTruthy();
expect(versions.find(x => x.game_versions.includes("1.16.5"))).toBeTruthy();
}, timeout);
test("returns only featured versions with featured === true", async () => {
2022-07-05 13:44:29 -04:00
const versions = await getVersions("terra", null!, null!, true);
expect(versions.every(x => x.featured)).toBe(true);
}, timeout);
test("returns only unfeatured versions with featured === false", async () => {
2022-07-05 13:44:29 -04:00
const versions = await getVersions("terra", null!, null!, false);
expect(versions.every(x => !x.featured)).toBe(true);
}, timeout);
test("returns only versions that support given modloaders", async () => {
const fabricVersions = await getVersions("terra", ["fabric"]);
expect(fabricVersions.every(x => x.loaders.includes("fabric"))).toBe(true);
const forgeVersions = await getVersions("terra", ["forge"]);
expect(forgeVersions.every(x => x.loaders.includes("forge"))).toBe(true);
}, timeout);
test("returns only versions that support given mc versions", async () => {
2022-07-05 13:44:29 -04:00
const versions_1_18_2 = await getVersions("terra", null!, ["1.18.2"]);
expect(versions_1_18_2.every(x => x.game_versions.includes("1.18.2"))).toBe(true);
2022-07-05 13:44:29 -04:00
const versions_1_16_5 = await getVersions("terra", null!, ["1.16.5"]);
expect(versions_1_16_5.every(x => x.game_versions.includes("1.16.5"))).toBe(true);
}, timeout);
});