mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 18:25:24 +00:00
Added constructor check for buffers
This commit is contained in:
@@ -32,6 +32,18 @@ describe("PKPass", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("constructor", () => {
|
||||||
|
it("should warn about a non-object buffer parameter", () => {
|
||||||
|
console.warn = jasmine.createSpy("warn");
|
||||||
|
|
||||||
|
pass = new PKPass(undefined, baseCerts);
|
||||||
|
|
||||||
|
expect(console.warn).toHaveBeenCalledWith(
|
||||||
|
Messages.INIT.INVALID_BUFFERS.replace("%s", "undefined"),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("setBeacons", () => {
|
describe("setBeacons", () => {
|
||||||
it("should reset instance.props['beacons'] if 'null' is passed as value", () => {
|
it("should reset instance.props['beacons'] if 'null' is passed as value", () => {
|
||||||
pass.setBeacons({
|
pass.setBeacons({
|
||||||
|
|||||||
@@ -130,15 +130,21 @@ export default class PKPass extends Bundle {
|
|||||||
) {
|
) {
|
||||||
super("application/vnd.apple.pkpass");
|
super("application/vnd.apple.pkpass");
|
||||||
|
|
||||||
const buffersEntries = Object.entries(buffers);
|
if (buffers && typeof buffers === "object") {
|
||||||
|
const buffersEntries = Object.entries(buffers);
|
||||||
|
|
||||||
for (
|
for (
|
||||||
let i = buffersEntries.length, buffer: [string, Buffer];
|
let i = buffersEntries.length, buffer: [string, Buffer];
|
||||||
(buffer = buffersEntries[--i]);
|
(buffer = buffersEntries[--i]);
|
||||||
|
|
||||||
) {
|
) {
|
||||||
const [fileName, contentBuffer] = buffer;
|
const [fileName, contentBuffer] = buffer;
|
||||||
this.addBuffer(fileName, contentBuffer);
|
this.addBuffer(fileName, contentBuffer);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.warn(
|
||||||
|
Messages.format(Messages.INIT.INVALID_BUFFERS, typeof buffers),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props) {
|
if (props) {
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
export const INIT = {
|
||||||
|
INVALID_BUFFERS:
|
||||||
|
"Cannot set buffers in constructor: expected object but received %s",
|
||||||
|
} as const;
|
||||||
|
|
||||||
export const CERTIFICATES = {
|
export const CERTIFICATES = {
|
||||||
INVALID:
|
INVALID:
|
||||||
"Invalid certificate(s) loaded. %s. Please provide valid WWDR certificates and developer signer certificate and key (with passphrase).\nRefer to docs to obtain them",
|
"Invalid certificate(s) loaded. %s. Please provide valid WWDR certificates and developer signer certificate and key (with passphrase).\nRefer to docs to obtain them",
|
||||||
|
|||||||
Reference in New Issue
Block a user