mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 21:25:26 +00:00
Updated tests and barcode example to latest changes
This commit is contained in:
@@ -29,19 +29,16 @@ app.all(async function manageRequest(request, response) {
|
|||||||
overrides: request.body || request.params || request.query,
|
overrides: request.body || request.params || request.query,
|
||||||
});
|
});
|
||||||
|
|
||||||
let bc: PassWithBarcodeMethods;
|
|
||||||
|
|
||||||
if (request.query.alt === true) {
|
if (request.query.alt === true) {
|
||||||
// After this, pass.props["barcodes"] will have support for all the formats
|
// After this, pass.props["barcodes"] will have support for all the formats
|
||||||
// while pass.props["barcode"] will be the first of barcodes.
|
// while pass.props["barcode"] will be the first of barcodes.
|
||||||
|
|
||||||
bc = pass.barcode("Thank you for using this package <3") as PassWithBarcodeMethods
|
pass.barcodes("Thank you for using this package <3");
|
||||||
} else {
|
} else {
|
||||||
// After this, pass.props["barcodes"] will have support for just two of three
|
// 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.
|
// of the passed format (the valid ones);
|
||||||
// if not specified, altText is automatically the message
|
|
||||||
|
|
||||||
bc = pass.barcode({
|
pass.barcodes({
|
||||||
message: "Thank you for using this package <3",
|
message: "Thank you for using this package <3",
|
||||||
format: "PKBarcodeFormatCode128"
|
format: "PKBarcodeFormatCode128"
|
||||||
}, {
|
}, {
|
||||||
@@ -50,29 +47,17 @@ app.all(async function manageRequest(request, response) {
|
|||||||
}, {
|
}, {
|
||||||
message: "Thank you for using this package <3",
|
message: "Thank you for using this package <3",
|
||||||
format: "PKBarcodeFormatMock44617"
|
format: "PKBarcodeFormatMock44617"
|
||||||
}) as PassWithBarcodeMethods;
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// You can change the format chosen for barcode prop support by calling .backward()
|
// You can change the format chosen for barcode prop support by calling .barcode()
|
||||||
// or cancel the support by calling empty .backward
|
// or cancel the support by calling empty .barcode
|
||||||
// like bc.backward().
|
// like pass.barcode().
|
||||||
// If the property passed does not exists, things does not change.
|
|
||||||
|
|
||||||
bc.backward("PKBarcodeFormatPDF417");
|
pass.barcode("PKBarcodeFormatPDF417");
|
||||||
|
|
||||||
// If your barcode structures got not autogenerated yet (as happens with string
|
console.log("Barcode property is now:", pass.props["barcode"]);
|
||||||
// parameter of barcode) you can call .autocomplete() to generate the support
|
console.log("Barcodes support is autocompleted:", pass.props["barcodes"]);
|
||||||
// to all the structures. Please beware that this will overwrite ONLY barcodes and not barcode.
|
|
||||||
|
|
||||||
if (!request.query.alt) {
|
|
||||||
// String generated barcode returns autocomplete as empty function
|
|
||||||
bc.autocomplete();
|
|
||||||
}
|
|
||||||
|
|
||||||
// @ts-ignore - ignoring for logging purposes
|
|
||||||
console.log("Barcode property is now:", pass._props["barcode"]);
|
|
||||||
// @ts-ignore - ignoring for logging purposes
|
|
||||||
console.log("Barcodes support is autocompleted:", pass._props["barcodes"]);
|
|
||||||
|
|
||||||
const stream = pass.generate();
|
const stream = pass.generate();
|
||||||
response.set({
|
response.set({
|
||||||
|
|||||||
174
spec/index.ts
174
spec/index.ts
@@ -67,33 +67,28 @@ describe("Node-Passkit-generator", function () {
|
|||||||
it("Missing first argument or not a string won't apply changes", () => {
|
it("Missing first argument or not a string won't apply changes", () => {
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
// @ts-ignore -- Ignoring for test purposes
|
||||||
pass.expiration();
|
pass.expiration();
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
expect(pass.props["expirationDate"]).toBe(undefined);
|
||||||
expect(pass._props["expirationDate"]).toBe(undefined);
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
// @ts-ignore -- Ignoring for test purposes
|
||||||
pass.expiration(42);
|
pass.expiration(42);
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
expect(pass.props["expirationDate"]).toBe(undefined);
|
||||||
expect(pass._props["expirationDate"]).toBe(undefined);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("A date as a Date object will apply changes", () => {
|
it("A date as a Date object will apply changes", () => {
|
||||||
pass.expiration(new Date(2020,5,1,0,0,0));
|
pass.expiration(new Date(2020,5,1,0,0,0));
|
||||||
// this is made to avoid problems with winter and summer time:
|
// this is made to avoid problems with winter and summer time:
|
||||||
// we focus only on the date and time for the tests.
|
// we focus only on the date and time for the tests.
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
let noTimeZoneDateTime = pass.props["expirationDate"].split("+")[0];
|
||||||
let noTimeZoneDateTime = pass._props["expirationDate"].split("+")[0];
|
|
||||||
expect(noTimeZoneDateTime).toBe("2020-06-01T00:00:00");
|
expect(noTimeZoneDateTime).toBe("2020-06-01T00:00:00");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("An invalid date, will not apply changes", () => {
|
it("An invalid date, will not apply changes", () => {
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
// @ts-ignore -- Ignoring for test purposes
|
||||||
pass.expiration("32/18/228317");
|
pass.expiration("32/18/228317");
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
expect(pass.props["expirationDate"]).toBe(undefined);
|
||||||
expect(pass._props["expirationDate"]).toBe(undefined);
|
|
||||||
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
// @ts-ignore -- Ignoring for test purposes
|
||||||
pass.expiration("32/18/228317");
|
pass.expiration("32/18/228317");
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
expect(pass.props["expirationDate"]).toBe(undefined);
|
||||||
expect(pass._props["expirationDate"]).toBe(undefined);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -103,28 +98,32 @@ describe("Node-Passkit-generator", function () {
|
|||||||
pass.relevantDate(new Date("10-04-2021"));
|
pass.relevantDate(new Date("10-04-2021"));
|
||||||
// this is made to avoid problems with winter and summer time:
|
// this is made to avoid problems with winter and summer time:
|
||||||
// we focus only on the date and time for the tests.
|
// we focus only on the date and time for the tests.
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
let noTimeZoneDateTime = pass.props["relevantDate"].split("+")[0];
|
||||||
let noTimeZoneDateTime = pass._props["relevantDate"].split("+")[0];
|
|
||||||
expect(noTimeZoneDateTime).toBe("2021-10-04T00:00:00");
|
expect(noTimeZoneDateTime).toBe("2021-10-04T00:00:00");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("locations :: ", () => {
|
describe("locations :: ", () => {
|
||||||
it("One-Invalid-schema location won't apply changes", () => {
|
it("One-Invalid-schema location won't apply changes", () => {
|
||||||
const oldAmountOfLocations = pass.locations().length;
|
const props = pass.props["locations"] || [];
|
||||||
|
const oldAmountOfLocations = props && props.length || 0;
|
||||||
|
|
||||||
pass.locations({
|
pass.locations({
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
"ibrupofene": "no",
|
"ibrupofene": "no",
|
||||||
"longitude": 0.00000000
|
"longitude": 0.00000000
|
||||||
});
|
}, ...props);
|
||||||
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
if (oldAmountOfLocations) {
|
||||||
expect(pass.locations().length).toBe(oldAmountOfLocations);
|
expect(pass.props["locations"].length).toBe(oldAmountOfLocations);
|
||||||
|
} else {
|
||||||
|
expect(pass.props["locations"]).toBe(undefined);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Two locations, with one invalid, will be filtered", () => {
|
it("Two locations, with one invalid, will be filtered", () => {
|
||||||
const oldAmountOfLocations = pass.locations().length;
|
const props = pass.props["locations"] || [];
|
||||||
|
const oldAmountOfLocations = props && props.length || 0;
|
||||||
|
|
||||||
pass.locations({
|
pass.locations({
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
@@ -133,16 +132,16 @@ describe("Node-Passkit-generator", function () {
|
|||||||
}, {
|
}, {
|
||||||
"longitude": 4.42634523,
|
"longitude": 4.42634523,
|
||||||
"latitude": 5.344233323352
|
"latitude": 5.344233323352
|
||||||
});
|
}, ...(pass.props["locations"] || []));
|
||||||
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
expect(pass.props["locations"].length).toBe((oldAmountOfLocations || 0) + 1);
|
||||||
expect(pass.locations().length).toBe(oldAmountOfLocations+1);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Beacons :: ", () => {
|
describe("Beacons :: ", () => {
|
||||||
it("One-Invalid-schema beacon data won't apply changes", () => {
|
it("One-Invalid-schema beacon data won't apply changes", () => {
|
||||||
const oldBeacons = pass.beacons();
|
const props = pass.props["beacons"] || [];
|
||||||
|
const oldAmountOfBeacons = props && props.length || 0;
|
||||||
|
|
||||||
pass.beacons({
|
pass.beacons({
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -150,14 +149,18 @@ describe("Node-Passkit-generator", function () {
|
|||||||
"major": 55,
|
"major": 55,
|
||||||
"minor": 0,
|
"minor": 0,
|
||||||
"proximityUUID": "2707c5f4-deb9-48ff-b760-671bc885b6a7"
|
"proximityUUID": "2707c5f4-deb9-48ff-b760-671bc885b6a7"
|
||||||
});
|
}, ...props);
|
||||||
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
if (oldAmountOfBeacons) {
|
||||||
expect(pass.beacons()).toBe(oldBeacons ? oldBeacons.length : undefined);
|
expect(pass.props["beacons"].length).toBe(oldAmountOfBeacons);
|
||||||
|
} else {
|
||||||
|
expect(pass.props["beacons"]).toBe(undefined);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Two beacons sets, with one invalid, will be filtered", () => {
|
it("Two beacons sets, with one invalid, will be filtered out", () => {
|
||||||
const oldBeacons = pass.beacons();
|
const props = pass.props["beacons"] || [];
|
||||||
|
const oldAmountOfBeacons = props && props.length || 0;
|
||||||
|
|
||||||
pass.beacons({
|
pass.beacons({
|
||||||
"major": 55,
|
"major": 55,
|
||||||
@@ -169,149 +172,130 @@ describe("Node-Passkit-generator", function () {
|
|||||||
"proximityUUID": "fdcbbf48-a4ae-4ffb-9200-f8a373c5c18e",
|
"proximityUUID": "fdcbbf48-a4ae-4ffb-9200-f8a373c5c18e",
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
"animal": "Monkey"
|
"animal": "Monkey"
|
||||||
});
|
}, ...props);
|
||||||
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
|
||||||
expect(pass.beacons().length).toBe(oldBeacons ? oldBeacons.length+1 : 1);
|
expect(pass.props["beacons"].length).toBe(oldAmountOfBeacons + 1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("barcode()", () => {
|
describe("barcodes()", () => {
|
||||||
it("Missing data will return the current data", () => {
|
it("Missing data will left situation unchanged", () => {
|
||||||
const oldAmountOfBarcodes = pass.barcode().length;
|
const props = pass.props["barcodes"] || [];
|
||||||
|
const oldAmountOfBarcodes = props && props.length || 0;
|
||||||
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
pass.barcodes();
|
||||||
expect(pass.barcode().length).toBe(oldAmountOfBarcodes);
|
expect(pass.props["barcodes"].length).toBe(oldAmountOfBarcodes);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Boolean parameter won't apply changes", () => {
|
it("Boolean parameter won't apply changes", () => {
|
||||||
const oldAmountOfBarcodes = pass.barcode().length;
|
const props = pass.props["barcodes"] || [];
|
||||||
|
const oldAmountOfBarcodes = props && props.length || 0;
|
||||||
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
// @ts-ignore -- Ignoring for test purposes
|
||||||
pass.barcode(true);
|
pass.barcode(true);
|
||||||
|
expect(props.length).toBe(oldAmountOfBarcodes);
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
|
||||||
expect(pass.barcode().length).toBe(oldAmountOfBarcodes);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Numeric parameter won't apply changes", () => {
|
it("Numeric parameter won't apply changes", () => {
|
||||||
const oldAmountOfBarcodes = pass.barcode().length;
|
const props = pass.props["barcodes"] || [];
|
||||||
|
const oldAmountOfBarcodes = props && props.length || 0;
|
||||||
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
// @ts-ignore -- Ignoring for test purposes
|
||||||
pass.barcode(42);
|
pass.barcodes(42);
|
||||||
|
expect(pass.props["barcodes"].length).toBe(oldAmountOfBarcodes);
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
|
||||||
expect(pass.barcode().length).toBe(oldAmountOfBarcodes);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("String parameter will autogenerate all the objects", () => {
|
it("String parameter will autogenerate all the objects", () => {
|
||||||
pass.barcode("28363516282");
|
pass.barcodes("28363516282");
|
||||||
|
expect(pass.props["barcodes"].length).toBe(4);
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
|
||||||
expect(pass._props["barcode"] instanceof Object).toBe(true);
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
|
||||||
expect(pass._props["barcode"].message).toBe("28363516282");
|
|
||||||
expect(pass.barcode().length).toBe(4);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Object parameter will be accepted", () => {
|
it("Object parameter will be accepted", () => {
|
||||||
pass.barcode({
|
pass.barcodes({
|
||||||
message: "28363516282",
|
message: "28363516282",
|
||||||
format: "PKBarcodeFormatPDF417",
|
format: "PKBarcodeFormatPDF417",
|
||||||
messageEncoding: "utf8"
|
messageEncoding: "utf8"
|
||||||
});
|
});
|
||||||
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
expect(pass.props["barcodes"].length).toBe(1);
|
||||||
expect(pass._props["barcode"] instanceof Object).toBe(true);
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
|
||||||
expect(pass._props["barcode"].format).toBe("PKBarcodeFormatPDF417");
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
|
||||||
expect(pass.barcode().length).toBe(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Array parameter will apply changes", () => {
|
it("Array parameter will apply changes", () => {
|
||||||
pass.barcode({
|
pass.barcodes({
|
||||||
message: "28363516282",
|
message: "28363516282",
|
||||||
format: "PKBarcodeFormatPDF417",
|
format: "PKBarcodeFormatPDF417",
|
||||||
messageEncoding: "utf8"
|
messageEncoding: "utf8"
|
||||||
});
|
});
|
||||||
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
expect(pass.props["barcodes"].length).toBe(1);
|
||||||
expect(pass._props["barcode"] instanceof Object).toBe(true);
|
|
||||||
// @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);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Missing messageEncoding gets automatically added.", () => {
|
it("Missing messageEncoding gets automatically added.", () => {
|
||||||
pass.barcode({
|
pass.barcodes({
|
||||||
message: "28363516282",
|
message: "28363516282",
|
||||||
format: "PKBarcodeFormatPDF417",
|
format: "PKBarcodeFormatPDF417",
|
||||||
});
|
});
|
||||||
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
expect(pass.props["barcodes"][0].messageEncoding).toBe("iso-8859-1");
|
||||||
expect(pass._props["barcode"] instanceof Object).toBe(true);
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
|
||||||
expect(pass._props["barcode"].messageEncoding).toBe("iso-8859-1");
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
|
||||||
expect(pass._props["barcodes"][0].messageEncoding).toBe("iso-8859-1");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Object without message property, will be filtered out", () => {
|
it("Object without message property, will be ignored", () => {
|
||||||
const oldAmountOfBarcodes = pass.barcode().length;
|
const props = pass.props["barcodes"] || [];
|
||||||
|
const oldAmountOfBarcodes = props && props.length || 0;
|
||||||
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
// @ts-ignore -- Ignoring for test purposes
|
||||||
pass.barcode({
|
pass.barcodes({
|
||||||
format: "PKBarcodeFormatPDF417",
|
format: "PKBarcodeFormatPDF417",
|
||||||
});
|
});
|
||||||
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
expect(pass.props["barcodes"].length).toBe(oldAmountOfBarcodes);
|
||||||
expect(pass.barcode().length).toBe(oldAmountOfBarcodes);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Array containing non-object elements will be rejected", () => {
|
it("Array containing non-object elements will be rejected", () => {
|
||||||
const oldAmountOfBarcodes = pass.barcode().length;
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
// @ts-ignore -- Ignoring for test purposes
|
||||||
pass.barcode(5, 10, 15, {
|
pass.barcodes(5, 10, 15, {
|
||||||
message: "28363516282",
|
message: "28363516282",
|
||||||
format: "PKBarcodeFormatPDF417"
|
format: "PKBarcodeFormatPDF417"
|
||||||
}, 7, 1);
|
}, 7, 1);
|
||||||
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
expect(pass.props["barcodes"].length).toBe(1)
|
||||||
expect(pass.barcode().length).toBe(1)
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("barcode().backward()", () => {
|
describe("barcode retrocompatibility", () => {
|
||||||
it("Passing argument of type different from string or null, won't apply changes", function () {
|
it("Passing argument of type different from string or null, won't apply changes", function () {
|
||||||
|
const oldBarcode = pass.props["barcode"] || undefined;
|
||||||
|
|
||||||
pass
|
pass
|
||||||
.barcode("Message-22645272183")
|
.barcodes("Message-22645272183")
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
// @ts-ignore -- Ignoring for test purposes
|
||||||
.backward(5);
|
.barcode(55)
|
||||||
|
|
||||||
// unchanged
|
// unchanged
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
expect(pass.props["barcode"]).toEqual(oldBarcode);
|
||||||
expect(pass._props["barcode"].format).toBe("PKBarcodeFormatQR");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Null will delete backward support", () => {
|
it("Null will delete backward support", () => {
|
||||||
(pass.barcode("Message-22645272183") as PassWithBarcodeMethods)
|
pass.barcodes("Message-22645272183")
|
||||||
.backward(null);
|
.barcode("PKBarcodeFormatAztec");
|
||||||
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
expect(pass.props["barcode"].format).toBe("PKBarcodeFormatAztec");
|
||||||
expect(pass._props["barcode"]).toBe(undefined);
|
|
||||||
|
pass.barcode(null);
|
||||||
|
expect(pass.props["barcode"]).toBe(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Unknown format won't apply changes", () => {
|
it("Unknown format won't apply changes", () => {
|
||||||
pass
|
const oldBarcode = pass.props["barcode"] || undefined;
|
||||||
.barcode("Message-22645272183")
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
|
||||||
.backward("PKBingoBongoFormat");
|
|
||||||
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
pass
|
||||||
expect(pass._props["barcode"].format).toBe("PKBarcodeFormatQR");
|
.barcodes("Message-22645272183")
|
||||||
|
// @ts-ignore -- Ignoring for test purposes
|
||||||
|
.barcode("PKBingoBongoFormat");
|
||||||
|
|
||||||
|
expect(pass.props["barcode"]).toEqual(oldBarcode);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user