const { expect } = require("chai"); require("ts-node/register/transpile-only"); const { default: Gist } = require("../src/core/Gist"); function makeGist(options) { return new Gist({ gistId: "g-test", owner: "000000000000000000000001", source: { gistId: "abc" }, options: { terms: ["Alice"], content: true, title: true, image: true, ...options }, gist: { description: "By Alice", files: [ { filename: "notes-Alice.md", content: "Written by Alice", language: "Markdown", size: 16 }, { filename: "plot-Alice.png", content: "iVBORw0KGgoAlice==", encoding: "base64", size: 12, type: "image/png" }, { filename: "paper.pdf", content: "JVBERi0xLjQK", encoding: "base64", size: 9, type: "application/pdf" }, { filename: "huge.bin", content: "", encoding: "base64", size: 99999999, tooLarge: true }, ], }, }); } describe("Gist.content() binary files", function () { it("anonymizes text files and names, and passes binary bytes through unchanged", function () { const [md, png, pdf, huge] = makeGist().content().files; expect(md).to.include({ filename: "notes-XXXX-1.md", content: "Written by XXXX-1" }); expect(md).to.not.have.property("encoding"); expect(png).to.include({ filename: "plot-XXXX-1.png", encoding: "base64", content: "iVBORw0KGgoAlice==" }); expect(pdf).to.include({ encoding: "base64", content: "JVBERi0xLjQK" }); expect(huge).to.include({ tooLarge: true, encoding: "base64" }); expect(huge.content).to.be.undefined; }); it("withholds images when images are not displayed, but keeps other binaries", function () { const [, png, pdf] = makeGist({ image: false }).content().files; expect(png.content).to.be.undefined; expect(png.hidden).to.equal(true); expect(pdf.content).to.equal("JVBERi0xLjQK"); }); });