mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 18:25:24 +00:00
Removed PKPass.pack to be async and moved an error to messages
This commit is contained in:
@@ -1086,18 +1086,15 @@ describe("PKPass", () => {
|
|||||||
pass[freezeSymbol]();
|
pass[freezeSymbol]();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should should throw error if not all the files passed are PKPasses", async () => {
|
it("should should throw error if not all the files passed are PKPasses", () => {
|
||||||
await expectAsync(
|
expect(
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
PKPass.pack(pass, "pass.json", pass),
|
() => PKPass.pack(pass, "pass.json", pass),
|
||||||
).toBeRejectedWithError(
|
).toThrowError(Error, Messages.PACK.INVALID);
|
||||||
Error,
|
|
||||||
"Cannot pack passes. Only PKPass instances allowed",
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should output a frozen bundle of bundles", async () => {
|
it("should output a frozen bundle of bundles", () => {
|
||||||
const pkPassesBundle = await PKPass.pack(pass, pass);
|
const pkPassesBundle = PKPass.pack(pass, pass);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
pkPassesBundle[filesSymbol]["packed-pass-1.pkpass"],
|
pkPassesBundle[filesSymbol]["packed-pass-1.pkpass"],
|
||||||
@@ -1109,8 +1106,8 @@ describe("PKPass", () => {
|
|||||||
expect(pkPassesBundle.isFrozen).toBe(true);
|
expect(pkPassesBundle.isFrozen).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should output a bundle with pkpasses mimetype", async () => {
|
it("should output a bundle with pkpasses mimetype", () => {
|
||||||
const pkPassesBundle = await PKPass.pack(pass, pass);
|
const pkPassesBundle = PKPass.pack(pass, pass);
|
||||||
|
|
||||||
expect(pkPassesBundle.mimeType).toBe(
|
expect(pkPassesBundle.mimeType).toBe(
|
||||||
"application/vnd.apple.pkpasses",
|
"application/vnd.apple.pkpasses",
|
||||||
|
|||||||
@@ -105,16 +105,12 @@ export default class PKPass extends Bundle {
|
|||||||
* @param passes
|
* @param passes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static async pack(...passes: PKPass[]): Promise<Bundle> {
|
static pack(...passes: PKPass[]): Bundle {
|
||||||
if (!passes.every((pass) => pass instanceof PKPass)) {
|
if (!passes.every((pass) => pass instanceof PKPass)) {
|
||||||
throw new Error(
|
throw new Error(Messages.PACK.INVALID);
|
||||||
"Cannot pack passes. Only PKPass instances allowed",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const buffers = await Promise.all(
|
const buffers = passes.map((pass) => pass.getAsBuffer());
|
||||||
passes.map((pass) => pass.getAsBuffer()),
|
|
||||||
);
|
|
||||||
|
|
||||||
const [bundle, freezeBundle] = Bundle.freezable(
|
const [bundle, freezeBundle] = Bundle.freezable(
|
||||||
"application/vnd.apple.pkpasses",
|
"application/vnd.apple.pkpasses",
|
||||||
|
|||||||
@@ -78,6 +78,10 @@ export const BUNDLE = {
|
|||||||
CLOSED: "Cannot add file. Bundle is closed.",
|
CLOSED: "Cannot add file. Bundle is closed.",
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
export const PACK = {
|
||||||
|
INVALID: "Cannot pack passes. Only PKPass instances allowed",
|
||||||
|
} as const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a message with replaced values
|
* Creates a message with replaced values
|
||||||
* @param messageName
|
* @param messageName
|
||||||
|
|||||||
Reference in New Issue
Block a user