Made a reader for Quilt metadata

This commit is contained in:
Kir_Antipov 2023-03-21 09:34:46 +00:00
parent 547d8d486e
commit ad769f1e9c
2 changed files with 55 additions and 0 deletions

View file

@ -0,0 +1,14 @@
import { ZippedTextLoaderMetadataReader } from "@/loaders/zipped-loader-metadata-reader";
import { QuiltMetadata } from "./quilt-metadata";
import { QUILT_MOD_JSON, RawQuiltMetadata } from "./raw-quilt-metadata";
/**
* A metadata reader that is able to read Quilt mod metadata from a zipped file.
*/
export class QuiltMetadataReader extends ZippedTextLoaderMetadataReader<QuiltMetadata, RawQuiltMetadata> {
/**
* Constructs a new {@link QuiltMetadataReader} instance.
*/
constructor() {
super(QUILT_MOD_JSON, QuiltMetadata.from, JSON.parse);
}
}

View file

@ -0,0 +1,41 @@
import { zipFile } from "@/../tests/utils/zip-utils";
import mockFs from "mock-fs";
import { QuiltMetadata } from "@/loaders/quilt/quilt-metadata";
import { QuiltMetadataReader } from "@/loaders/quilt/quilt-metadata-reader";
beforeEach(async () => {
mockFs({
"quilt.mod.jar": await zipFile([__dirname, "../../../content/quilt/quilt.mod.json"]),
"text.txt": "",
});
});
afterEach(() => {
mockFs.restore();
});
describe("QuiltMetadataReader", () => {
test("successfully reads quilt.mod.json", async () => {
const reader = new QuiltMetadataReader();
const metadata = await reader.readMetadataFile("quilt.mod.jar");
expect(metadata).toBeInstanceOf(QuiltMetadata);
});
test("returns undefined if file is not a Quilt mod", async () => {
const reader = new QuiltMetadataReader();
const metadata = await reader.readMetadataFile("text.txt");
expect(metadata).toBeUndefined();
});
test("returns undefined if file does not exist", async () => {
const reader = new QuiltMetadataReader();
const metadata = await reader.readMetadataFile("text.json");
expect(metadata).toBeUndefined();
});
});