mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 22:25:24 +00:00
Improved tests and added certificates setter tests
This commit is contained in:
@@ -1,22 +1,24 @@
|
|||||||
import {
|
import {
|
||||||
default as PKPass,
|
default as PKPass,
|
||||||
localizationSymbol,
|
localizationSymbol,
|
||||||
|
certificatesSymbol,
|
||||||
propsSymbol,
|
propsSymbol,
|
||||||
} from "../lib/PKPass";
|
} from "../lib/PKPass";
|
||||||
|
|
||||||
describe("PKPass", () => {
|
describe("PKPass", () => {
|
||||||
let pass: PKPass;
|
let pass: PKPass;
|
||||||
|
const baseCerts = {
|
||||||
|
signerCert: "",
|
||||||
|
signerKey: "",
|
||||||
|
wwdr: "",
|
||||||
|
signerKeyPassphrase: "p477w0rb",
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
pass = new PKPass(
|
pass = new PKPass(
|
||||||
{},
|
{},
|
||||||
/** @ts-ignore - We don't need certificates here*/
|
/** @ts-ignore - We don't need certificates here*/
|
||||||
{
|
baseCerts,
|
||||||
signerCert: "",
|
|
||||||
signerKey: "",
|
|
||||||
wwdr: "",
|
|
||||||
signerKeyPassphrase: "p477w0rb",
|
|
||||||
},
|
|
||||||
{},
|
{},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -383,41 +385,27 @@ describe("PKPass", () => {
|
|||||||
|
|
||||||
describe("transitType", () => {
|
describe("transitType", () => {
|
||||||
it("should accept a new value only if the pass is a boarding pass", () => {
|
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(
|
const passBP = new PKPass(
|
||||||
{
|
{
|
||||||
"pass.json": mockBPPassJSON,
|
"pass.json": Buffer.from(
|
||||||
},
|
JSON.stringify({
|
||||||
{
|
boardingPass: {},
|
||||||
signerCert: "",
|
}),
|
||||||
signerKey: "",
|
),
|
||||||
wwdr: "",
|
|
||||||
signerKeyPassphrase: "p477w0rb",
|
|
||||||
},
|
},
|
||||||
|
baseCerts,
|
||||||
{},
|
{},
|
||||||
);
|
);
|
||||||
|
|
||||||
const passCP = new PKPass(
|
const passCP = new PKPass(
|
||||||
{
|
{
|
||||||
"pass.json": mockCPPassJSON,
|
"pass.json": Buffer.from(
|
||||||
},
|
JSON.stringify({
|
||||||
{
|
coupon: {},
|
||||||
signerCert: "",
|
}),
|
||||||
signerKey: "",
|
),
|
||||||
wwdr: "",
|
|
||||||
signerKeyPassphrase: "p477w0rb",
|
|
||||||
},
|
},
|
||||||
|
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", () => {
|
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