Improved tests and added certificates setter tests

This commit is contained in:
Alexander Cerutti
2021-10-11 23:23:25 +02:00
parent 386fdd2e28
commit e69f302cf9

View File

@@ -1,22 +1,24 @@
import {
default as PKPass,
localizationSymbol,
certificatesSymbol,
propsSymbol,
} from "../lib/PKPass";
describe("PKPass", () => {
let pass: PKPass;
const baseCerts = {
signerCert: "",
signerKey: "",
wwdr: "",
signerKeyPassphrase: "p477w0rb",
};
beforeEach(() => {
pass = new PKPass(
{},
/** @ts-ignore - We don't need certificates here*/
{
signerCert: "",
signerKey: "",
wwdr: "",
signerKeyPassphrase: "p477w0rb",
},
baseCerts,
{},
);
});
@@ -383,41 +385,27 @@ describe("PKPass", () => {
describe("transitType", () => {
it("should accept a new value only if the pass is a boarding pass", () => {
const mockBPPassJSON = Buffer.from(
JSON.stringify({
boardingPass: {},
}),
);
const mockCPPassJSON = Buffer.from(
JSON.stringify({
coupon: {},
}),
);
const passBP = new PKPass(
{
"pass.json": mockBPPassJSON,
},
{
signerCert: "",
signerKey: "",
wwdr: "",
signerKeyPassphrase: "p477w0rb",
"pass.json": Buffer.from(
JSON.stringify({
boardingPass: {},
}),
),
},
baseCerts,
{},
);
const passCP = new PKPass(
{
"pass.json": mockCPPassJSON,
},
{
signerCert: "",
signerKey: "",
wwdr: "",
signerKeyPassphrase: "p477w0rb",
"pass.json": Buffer.from(
JSON.stringify({
coupon: {},
}),
),
},
baseCerts,
{},
);
@@ -434,6 +422,38 @@ describe("PKPass", () => {
});
});
describe("certificates setter", () => {
it("should throw an error if certificates provided are not complete or invalid", () => {
expect(() => {
// @ts-expect-error
pass.certificates = {
signerCert: "",
};
}).toThrow();
expect(() => {
pass.certificates = {
// @ts-expect-error
signerCert: 5,
// @ts-expect-error
signerKey: 3,
wwdr: "",
};
}).toThrow();
expect(() => {
pass.certificates = {
signerCert: undefined,
signerKey: null,
wwdr: "",
};
}).toThrow();
/** Expecting previous result */
expect(pass[certificatesSymbol]).toEqual(baseCerts);
});
});
describe("localize", () => {
it("should fail throw if lang is not a string", () => {
expect(() => pass.localize(null)).toThrowError(