Added tests for type getter and setter

This commit is contained in:
Alexander Cerutti
2021-10-12 22:44:20 +02:00
parent 77db921aea
commit 57c6021dca

View File

@@ -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(