mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 14:25:17 +00:00
Updated examples and tests
This commit is contained in:
@@ -35,7 +35,7 @@ app.all(async function manageRequest(request, response) {
|
||||
// After this, pass.props["barcodes"] will have support for all the formats
|
||||
// while pass.props["barcode"] will be the first of barcodes.
|
||||
|
||||
bc = pass.barcode("Thank you for using this package <3");
|
||||
bc = pass.barcode("Thank you for using this package <3") as PassWithBarcodeMethods
|
||||
} else {
|
||||
// After this, pass.props["barcodes"] will have support for just two of three
|
||||
// of the passed format (the valid ones) and pass.props["barcode"] the first of barcodes.
|
||||
@@ -50,7 +50,7 @@ app.all(async function manageRequest(request, response) {
|
||||
}, {
|
||||
message: "Thank you for using this package <3",
|
||||
format: "PKBarcodeFormatMock44617"
|
||||
});
|
||||
}) as PassWithBarcodeMethods;
|
||||
}
|
||||
|
||||
// You can change the format chosen for barcode prop support by calling .backward()
|
||||
|
||||
@@ -50,8 +50,9 @@ app.all(async function manageRequest(request, response) {
|
||||
|
||||
// This language does not exist but is still added as .lproj folder
|
||||
pass.localize("zu", {});
|
||||
|
||||
// @ts-ignore - ignoring for logging purposes. Do not replicate
|
||||
console.log("Added languages", Object.keys(pass.l10nBundles).join(", "))
|
||||
console.log("Added languages", pass.localize().join(", "))
|
||||
|
||||
const stream = pass.generate();
|
||||
response.set({
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createPass } from "..";
|
||||
import { Pass } from "../src/pass";
|
||||
import { Pass, PassWithBarcodeMethods } from "../src/pass";
|
||||
|
||||
/*
|
||||
* Yes, I know that I'm checking against "private" properties
|
||||
@@ -111,6 +111,8 @@ describe("Node-Passkit-generator", function () {
|
||||
|
||||
describe("locations :: ", () => {
|
||||
it("One-Invalid-schema location won't apply changes", () => {
|
||||
const oldAmountOfLocations = pass.locations().length;
|
||||
|
||||
pass.locations({
|
||||
// @ts-ignore
|
||||
"ibrupofene": "no",
|
||||
@@ -118,10 +120,12 @@ describe("Node-Passkit-generator", function () {
|
||||
});
|
||||
|
||||
// @ts-ignore -- Ignoring for test purposes
|
||||
expect(pass._props["locations"]).toBe(undefined);
|
||||
expect(pass._props["locations"].length).toBe(oldAmountOfLocations);
|
||||
});
|
||||
|
||||
it("Two locations, with one invalid, will be filtered", () => {
|
||||
const oldAmountOfLocations = pass.locations().length;
|
||||
|
||||
pass.locations({
|
||||
//@ts-ignore
|
||||
"ibrupofene": "no",
|
||||
@@ -132,7 +136,7 @@ describe("Node-Passkit-generator", function () {
|
||||
});
|
||||
|
||||
// @ts-ignore -- Ignoring for test purposes
|
||||
expect(pass._props["locations"].length).toBe(1);
|
||||
expect(pass._props["locations"].length).toBe(oldAmountOfLocations+1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -170,34 +174,31 @@ describe("Node-Passkit-generator", function () {
|
||||
});
|
||||
|
||||
describe("barcode()", () => {
|
||||
it("Missing data will won't apply changes", () => {
|
||||
// @ts-ignore -- Ignoring for test purposes
|
||||
pass.barcode();
|
||||
it("Missing data will return the current data", () => {
|
||||
const oldAmountOfBarcodes = pass.barcode().length;
|
||||
|
||||
// @ts-ignore -- Ignoring for test purposes
|
||||
expect(pass._props["barcode"]).toBe(undefined);
|
||||
// @ts-ignore -- Ignoring for test purposes
|
||||
expect(pass._props["barcodes"]).toBe(undefined);
|
||||
expect(pass.barcode().length).toBe(oldAmountOfBarcodes);
|
||||
});
|
||||
|
||||
it("Boolean parameter won't apply changes", () => {
|
||||
const oldAmountOfBarcodes = pass.barcode().length;
|
||||
|
||||
// @ts-ignore -- Ignoring for test purposes
|
||||
pass.barcode(true);
|
||||
|
||||
// @ts-ignore -- Ignoring for test purposes
|
||||
expect(pass._props["barcode"]).toBe(undefined);
|
||||
// @ts-ignore -- Ignoring for test purposes
|
||||
expect(pass._props["barcodes"]).toBe(undefined);
|
||||
expect(pass.barcode().length).toBe(oldAmountOfBarcodes);
|
||||
});
|
||||
|
||||
it("Numeric parameter won't apply changes", () => {
|
||||
const oldAmountOfBarcodes = pass.barcode().length;
|
||||
|
||||
// @ts-ignore -- Ignoring for test purposes
|
||||
pass.barcode(42);
|
||||
|
||||
// @ts-ignore -- Ignoring for test purposes
|
||||
expect(pass._props["barcode"]).toBe(undefined);
|
||||
// @ts-ignore -- Ignoring for test purposes
|
||||
expect(pass._props["barcodes"]).toBe(undefined);
|
||||
expect(pass.barcode().length).toBe(oldAmountOfBarcodes);
|
||||
});
|
||||
|
||||
it("String parameter will autogenerate all the objects", () => {
|
||||
@@ -207,11 +208,10 @@ describe("Node-Passkit-generator", function () {
|
||||
expect(pass._props["barcode"] instanceof Object).toBe(true);
|
||||
// @ts-ignore -- Ignoring for test purposes
|
||||
expect(pass._props["barcode"].message).toBe("28363516282");
|
||||
// @ts-ignore -- Ignoring for test purposes
|
||||
expect(pass._props["barcodes"].length).toBe(4);
|
||||
expect(pass.barcode().length).toBe(4);
|
||||
});
|
||||
|
||||
it("Object parameter will be automatically converted to one-element Array", () => {
|
||||
it("Object parameter will be accepted", () => {
|
||||
pass.barcode({
|
||||
message: "28363516282",
|
||||
format: "PKBarcodeFormatPDF417",
|
||||
@@ -223,7 +223,7 @@ describe("Node-Passkit-generator", function () {
|
||||
// @ts-ignore -- Ignoring for test purposes
|
||||
expect(pass._props["barcode"].format).toBe("PKBarcodeFormatPDF417");
|
||||
// @ts-ignore -- Ignoring for test purposes
|
||||
expect(pass._props["barcodes"].length).toBe(1);
|
||||
expect(pass.barcode().length).toBe(1);
|
||||
});
|
||||
|
||||
it("Array parameter will apply changes", () => {
|
||||
@@ -256,18 +256,19 @@ describe("Node-Passkit-generator", function () {
|
||||
});
|
||||
|
||||
it("Object without message property, will be filtered out", () => {
|
||||
const oldAmountOfBarcodes = pass.barcode().length;
|
||||
|
||||
// @ts-ignore -- Ignoring for test purposes
|
||||
pass.barcode({
|
||||
format: "PKBarcodeFormatPDF417",
|
||||
});
|
||||
|
||||
// @ts-ignore -- Ignoring for test purposes
|
||||
expect(pass._props["barcode"]).toBe(undefined);
|
||||
// @ts-ignore -- Ignoring for test purposes
|
||||
expect(pass._props["barcodes"]).toBe(undefined);
|
||||
expect(pass.barcode().length).toBe(oldAmountOfBarcodes);
|
||||
});
|
||||
|
||||
it("Array containing non-object elements will be rejected", () => {
|
||||
const oldAmountOfBarcodes = pass.barcode().length;
|
||||
// @ts-ignore -- Ignoring for test purposes
|
||||
pass.barcode(5, 10, 15, {
|
||||
message: "28363516282",
|
||||
@@ -275,9 +276,7 @@ describe("Node-Passkit-generator", function () {
|
||||
}, 7, 1);
|
||||
|
||||
// @ts-ignore -- Ignoring for test purposes
|
||||
expect(pass._props["barcode"] instanceof Object).toBe(false);
|
||||
// @ts-ignore -- Ignoring for test purposes
|
||||
expect(pass._props["barcodes"]).toBeUndefined();
|
||||
expect(pass.barcode().length).toBe(1)
|
||||
});
|
||||
});
|
||||
|
||||
@@ -294,8 +293,7 @@ describe("Node-Passkit-generator", function () {
|
||||
});
|
||||
|
||||
it("Null will delete backward support", () => {
|
||||
pass
|
||||
.barcode("Message-22645272183")
|
||||
(pass.barcode("Message-22645272183") as PassWithBarcodeMethods)
|
||||
.backward(null);
|
||||
|
||||
// @ts-ignore -- Ignoring for test purposes
|
||||
|
||||
Reference in New Issue
Block a user