Added tests for PKPass.pack

This commit is contained in:
Alexander Cerutti
2021-10-13 23:14:14 +02:00
parent 62d54ab4d8
commit b584269bc0
2 changed files with 40 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
import { promises as fs } from "fs"; import { promises as fs } from "fs";
import * as path from "path"; import * as path from "path";
import { filesSymbol } from "../lib/Bundle"; import { filesSymbol, freezeSymbol } from "../lib/Bundle";
import FieldsArray from "../lib/FieldsArray"; import FieldsArray from "../lib/FieldsArray";
import { PassProps } from "../lib/schemas"; import { PassProps } from "../lib/schemas";
import { import {
@@ -1104,4 +1104,42 @@ describe("PKPass", () => {
}); });
}); });
}); });
describe("[static] pack", () => {
beforeEach(() => {
/** Bypass to avoid signature and manifest generation */
pass[freezeSymbol]();
});
it("should should throw error if not all the files passed are PKPasses", async () => {
await expectAsync(
// @ts-expect-error
PKPass.pack(pass, "pass.json", pass),
).toBeRejectedWithError(
Error,
"Cannot pack passes. Only PKPass instances allowed",
);
});
it("should output a frozen bundle of bundles", async () => {
const pkPassesBundle = await PKPass.pack(pass, pass);
expect(
pkPassesBundle[filesSymbol]["packed-pass-1.pkpass"],
).toBeInstanceOf(Buffer);
expect(
pkPassesBundle[filesSymbol]["packed-pass-2.pkpass"],
).toBeInstanceOf(Buffer);
expect(pkPassesBundle.isFrozen).toBe(true);
});
it("should output a bundle with pkpasses mimetype", async () => {
const pkPassesBundle = await PKPass.pack(pass, pass);
expect(pkPassesBundle.mimeType).toBe(
"application/vnd.apple.pkpasses",
);
});
});
}); });

View File

@@ -2,7 +2,7 @@ import { Stream } from "stream";
import { ZipFile } from "yazl"; import { ZipFile } from "yazl";
export const filesSymbol = Symbol("bundleFiles"); export const filesSymbol = Symbol("bundleFiles");
const freezeSymbol = Symbol("bundleFreeze"); export const freezeSymbol = Symbol("bundleFreeze");
const archiveSymbol = Symbol("zip"); const archiveSymbol = Symbol("zip");
namespace Mime { namespace Mime {