Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/glacials/whatsinstandard. a Magic: The Gathering format reference whatsinstandard.com
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322/// <reference types="node" />
import { existsSync, readFileSync } from "fs";import { use, expect } from "chai";import { describe } from "mocha";
import chaiJsonSchema from "chai-json-schema";
use(chaiJsonSchema);
describe("API", () => { const apiPath = "./api";
describe("v1", () => { const versionPath = apiPath + "/1";
it("shouldn't exist", () => { const exists = existsSync(versionPath); expect(exists).to.be.false; }); });
describe("v2", () => { const versionPath = apiPath + "/2";
it("shouldn't exist", () => { const exists = existsSync(versionPath); expect(exists).to.be.false; }); });
describe("v3", () => { const versionPath = apiPath + "/3";
it("shouldn't exist", () => { const exists = existsSync(versionPath); expect(exists).to.be.false; }); });
describe("v4", () => { const versionPath = apiPath + "/4";
it("shouldn't exist", () => { const exists = existsSync(versionPath); expect(exists).to.be.false; }); });
describe("v5", () => { const versionPath = apiPath + "/v5";
describe("sets.json", () => { const setsPath = versionPath + "/sets.json"; const body = JSON.parse(readFileSync(setsPath, "utf8"));
it("should be an object", () => { expect(body).to.be.an("object"); });
it("should be marked deprecated", () => { expect(body.deprecated).to.be.true; });
it("should have a sets array", () => { expect(body.sets).to.be.an("array"); });
it("shouldn't have too few sets", () => { expect(body.sets).to.have.length.above(8); });
body.sets.forEach((set) => { describe(set.name, () => { describe("name", () => { const name = set.name;
it("should be a string", () => { expect(name).to.be.a.string; });
it("should have a nonzero length", () => { expect(name).to.not.have.length(0); }); });
describe("block", () => { const block = set.block;
it("should be a string", () => { expect(block).to.be.a.string; });
it("should have a nonzero length or be null", () => { expect(block || "abc").to.not.have.length(0); });
it("should be the same as the previous set's block or equal to this set's name or be null", () => { const validNames = new Set([set.name, null]); if (body.sets.indexOf(set) > 0) { validNames.add(body.sets[body.sets.indexOf(set) - 1].block); }
expect(block).to.be.oneOf([...validNames]); }); });
describe("code", () => { const code = set.code;
it("should be a string", () => { expect(code).to.be.a.string; });
it("should be three characters", () => { expect(code).to.have.length(3); });
it("should be all caps", () => { expect(code).to.equal(code.toUpperCase()); }); });
describe("symbol", () => { const symbol = set.symbol;
it("should be absent", () => { expect(symbol).to.be.undefined; }); });
describe("enter date", () => { const enterDate = set.enter_date;
it("should be a string or null", () => { expect(enterDate || "").to.be.a.string; });
it("should be an ISO 8601 datetime if present", () => { expect( Date.parse(enterDate || "1970-01-01T00:00:00.000") ).to.be.a("number"); });
it("should represent midnight if present", () => { expect(enterDate || "1970-01-01T00:00:00.000").to.contain( "00:00:00.00" ); });
it("should not attach a timezone if present", () => { expect( (enterDate || "1970-01-01T00:00:00.000").substring( (enterDate || "1970-01-01T00:00:00.000").length - 12, (enterDate || "1970-01-01T00:00:00.000").length - 1 ) ).to.equal("00:00:00.00"); }); });
describe("exit date", () => { const exitDate = set.exit_date;
it("should be a string or null", () => { expect(exitDate || "").to.be.a.string; });
it("should be an ISO 8601 datetime if present", () => { expect(Date.parse(exitDate || "1970-01-01T00:00:00.000")).to.be.a( "number" ); });
it("should represent midnight if present", () => { expect(exitDate || "1970-01-01T00:00:00.000").to.contain( "00:00:00.00" ); });
it("should not attach a timezone if present", () => { expect( (exitDate || "1970-01-01T00:00:00.000").substring( (exitDate || "1970-01-01T00:00:00.000").length - 12, (exitDate || "1970-01-01T00:00:00.000").length - 1 ) ).to.equal("00:00:00.00"); }); });
describe("rough exit date", () => { const roughExitDate = set.rough_exit_date;
it("should be a string", () => { expect(roughExitDate).to.be.a.string; });
it("should be QX 20XX", () => { expect(roughExitDate).to.match(/Q\d 20\d\d/); }); }); }); });
body.bans.forEach((ban) => { describe(ban.card_name, () => { describe("card name", () => { const cardName = ban.card_name;
it("should be a string", () => { expect(cardName).to.be.a.string; });
it("should have a nonzero length", () => { expect(cardName).to.not.have.length(0); }); });
describe("card image URL", () => { const cardImageURL = ban.card_image_url;
it("should be a string", () => { expect(cardImageURL).to.be.a.string; });
it("should have a nonzero length", () => { expect(cardImageURL).to.not.have.length(0); });
it("should use HTTPS", () => { expect(new URL(cardImageURL).protocol).to.eq("https:"); }); });
describe("set code", () => { const setCode = ban.set_code;
it("should be in the sets array", () => { const validCodes = new Set(body.sets.map((set) => set.code));
expect(setCode).to.be.oneOf([...validCodes]); }); });
describe("reason", () => { const reason = ban.reason;
it("should be a string", () => { expect(reason).to.be.a.string; });
it("should have a nonzero length", () => { expect(reason).to.not.have.length(0); });
it("should be a complete sentence", () => { expect(reason.substr(-1)).to.equal("."); expect(reason[0]).to.equal(reason[0].toUpperCase()); });
it("should start with 'Banned for' or 'Banned to'", () => { expect(reason).to.match(/^Banned (for|to) .*$/); });
// Old bans are grandparented in if ( new Date( body.sets.find((set) => set.code === ban.set_code).enter_date ) > new Date("2023-07-02T00:00:00.000Z") ) { it("should start with 'Banned to'", () => { expect(reason).to.match(/^Banned to .*$/); }); } });
describe("announcement URL", () => { const announcementURL = ban.announcement_url;
it("should be a string", () => { expect(announcementURL).to.be.a.string; });
it("should have a nonzero length", () => { expect(announcementURL).to.not.have.length(0); });
it("should use HTTPS", () => { expect(new URL(announcementURL).protocol).to.eq("https:"); });
it("should be an official Wizards of the Coast link", () => { expect(new URL(announcementURL).hostname).to.eq( "magic.wizards.com" ); }); }); }); }); }); });
describe("v6", () => { const versionPath = apiPath + "/v6";
describe("standard.json", () => { const apiPath = versionPath + "/standard.json"; const schemaPath = versionPath + "/schema.json"; const schemaUrl = "https://whatsinstandard.com/api/v6/schema.json"; const api = JSON.parse(readFileSync(apiPath, "utf8")); const schema = JSON.parse(readFileSync(schemaPath, "utf8"));
it("should declare its schema", () => { expect(api["$schema"]).to.equal(schemaUrl); });
it("should adhere to its schema", () => { expect(api).to.be.jsonSchema(schema); }); }); });});