mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 18:25:24 +00:00
Added tests for type getter and setter
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
|||||||
localizationSymbol,
|
localizationSymbol,
|
||||||
certificatesSymbol,
|
certificatesSymbol,
|
||||||
propsSymbol,
|
propsSymbol,
|
||||||
|
passTypeSymbol,
|
||||||
} from "../lib/PKPass";
|
} from "../lib/PKPass";
|
||||||
|
|
||||||
describe("PKPass", () => {
|
describe("PKPass", () => {
|
||||||
@@ -527,6 +528,69 @@ describe("PKPass", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("type", () => {
|
||||||
|
describe("getter", () => {
|
||||||
|
it("should return undefined if no type have been setted", () => {
|
||||||
|
expect(pass.type).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return a type if set through pass.json", () => {
|
||||||
|
pass.addBuffer(
|
||||||
|
"pass.json",
|
||||||
|
Buffer.from(
|
||||||
|
JSON.stringify({
|
||||||
|
boardingPass: {},
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(pass.type).toBe("boardingPass");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("setter", () => {
|
||||||
|
it("should throw error if a non recognized type is assigned", () => {
|
||||||
|
expect(
|
||||||
|
() =>
|
||||||
|
// @ts-expect-error
|
||||||
|
(pass.type = "asfdg"),
|
||||||
|
).toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should save the new type under a Symbol in class instance", () => {
|
||||||
|
pass.type = "boardingPass";
|
||||||
|
expect(pass[passTypeSymbol]).toBe("boardingPass");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should reset fields if they have been previously set", () => {
|
||||||
|
pass.type = "boardingPass";
|
||||||
|
|
||||||
|
const {
|
||||||
|
primaryFields,
|
||||||
|
secondaryFields,
|
||||||
|
auxiliaryFields,
|
||||||
|
headerFields,
|
||||||
|
backFields,
|
||||||
|
} = pass;
|
||||||
|
|
||||||
|
pass.type = "coupon";
|
||||||
|
|
||||||
|
expect(pass.primaryFields).not.toBe(primaryFields);
|
||||||
|
expect(pass.secondaryFields).not.toBe(secondaryFields);
|
||||||
|
expect(pass.auxiliaryFields).not.toBe(auxiliaryFields);
|
||||||
|
expect(pass.headerFields).not.toBe(headerFields);
|
||||||
|
expect(pass.backFields).not.toBe(backFields);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should delete the previous type if previously setted", () => {
|
||||||
|
pass.type = "boardingPass";
|
||||||
|
pass.type = "coupon";
|
||||||
|
|
||||||
|
expect(pass["boardingPass"]).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("localize", () => {
|
describe("localize", () => {
|
||||||
it("should fail throw if lang is not a string", () => {
|
it("should fail throw if lang is not a string", () => {
|
||||||
expect(() => pass.localize(null)).toThrowError(
|
expect(() => pass.localize(null)).toThrowError(
|
||||||
|
|||||||
Reference in New Issue
Block a user