Updated examples and tests

This commit is contained in:
Alexander Cerutti
2019-06-27 23:43:44 +02:00
parent 05193aa32a
commit 53441a9b2f
3 changed files with 29 additions and 30 deletions

View File

@@ -35,7 +35,7 @@ app.all(async function manageRequest(request, response) {
// 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"); bc = pass.barcode("Thank you for using this package <3") as PassWithBarcodeMethods
} 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) 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", 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 .backward()

View File

@@ -50,8 +50,9 @@ app.all(async function manageRequest(request, response) {
// This language does not exist but is still added as .lproj folder // This language does not exist but is still added as .lproj folder
pass.localize("zu", {}); pass.localize("zu", {});
// @ts-ignore - ignoring for logging purposes. Do not replicate // @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(); const stream = pass.generate();
response.set({ response.set({

View File

@@ -1,5 +1,5 @@
import { createPass } from ".."; import { createPass } from "..";
import { Pass } from "../src/pass"; import { Pass, PassWithBarcodeMethods } from "../src/pass";
/* /*
* Yes, I know that I'm checking against "private" properties * Yes, I know that I'm checking against "private" properties
@@ -111,6 +111,8 @@ describe("Node-Passkit-generator", function () {
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;
pass.locations({ pass.locations({
// @ts-ignore // @ts-ignore
"ibrupofene": "no", "ibrupofene": "no",
@@ -118,10 +120,12 @@ describe("Node-Passkit-generator", function () {
}); });
// @ts-ignore -- Ignoring for test purposes // @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", () => { it("Two locations, with one invalid, will be filtered", () => {
const oldAmountOfLocations = pass.locations().length;
pass.locations({ pass.locations({
//@ts-ignore //@ts-ignore
"ibrupofene": "no", "ibrupofene": "no",
@@ -132,7 +136,7 @@ describe("Node-Passkit-generator", function () {
}); });
// @ts-ignore -- Ignoring for test purposes // @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()", () => { describe("barcode()", () => {
it("Missing data will won't apply changes", () => { it("Missing data will return the current data", () => {
// @ts-ignore -- Ignoring for test purposes const oldAmountOfBarcodes = pass.barcode().length;
pass.barcode();
// @ts-ignore -- Ignoring for test purposes // @ts-ignore -- Ignoring for test purposes
expect(pass._props["barcode"]).toBe(undefined); expect(pass.barcode().length).toBe(oldAmountOfBarcodes);
// @ts-ignore -- Ignoring for test purposes
expect(pass._props["barcodes"]).toBe(undefined);
}); });
it("Boolean parameter won't apply changes", () => { it("Boolean parameter won't apply changes", () => {
const oldAmountOfBarcodes = pass.barcode().length;
// @ts-ignore -- Ignoring for test purposes // @ts-ignore -- Ignoring for test purposes
pass.barcode(true); pass.barcode(true);
// @ts-ignore -- Ignoring for test purposes // @ts-ignore -- Ignoring for test purposes
expect(pass._props["barcode"]).toBe(undefined); expect(pass.barcode().length).toBe(oldAmountOfBarcodes);
// @ts-ignore -- Ignoring for test purposes
expect(pass._props["barcodes"]).toBe(undefined);
}); });
it("Numeric parameter won't apply changes", () => { it("Numeric parameter won't apply changes", () => {
const oldAmountOfBarcodes = pass.barcode().length;
// @ts-ignore -- Ignoring for test purposes // @ts-ignore -- Ignoring for test purposes
pass.barcode(42); pass.barcode(42);
// @ts-ignore -- Ignoring for test purposes // @ts-ignore -- Ignoring for test purposes
expect(pass._props["barcode"]).toBe(undefined); expect(pass.barcode().length).toBe(oldAmountOfBarcodes);
// @ts-ignore -- Ignoring for test purposes
expect(pass._props["barcodes"]).toBe(undefined);
}); });
it("String parameter will autogenerate all the objects", () => { 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); expect(pass._props["barcode"] instanceof Object).toBe(true);
// @ts-ignore -- Ignoring for test purposes // @ts-ignore -- Ignoring for test purposes
expect(pass._props["barcode"].message).toBe("28363516282"); expect(pass._props["barcode"].message).toBe("28363516282");
// @ts-ignore -- Ignoring for test purposes expect(pass.barcode().length).toBe(4);
expect(pass._props["barcodes"].length).toBe(4);
}); });
it("Object parameter will be automatically converted to one-element Array", () => { it("Object parameter will be accepted", () => {
pass.barcode({ pass.barcode({
message: "28363516282", message: "28363516282",
format: "PKBarcodeFormatPDF417", format: "PKBarcodeFormatPDF417",
@@ -223,7 +223,7 @@ describe("Node-Passkit-generator", function () {
// @ts-ignore -- Ignoring for test purposes // @ts-ignore -- Ignoring for test purposes
expect(pass._props["barcode"].format).toBe("PKBarcodeFormatPDF417"); expect(pass._props["barcode"].format).toBe("PKBarcodeFormatPDF417");
// @ts-ignore -- Ignoring for test purposes // @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", () => { it("Array parameter will apply changes", () => {
@@ -256,18 +256,19 @@ describe("Node-Passkit-generator", function () {
}); });
it("Object without message property, will be filtered out", () => { it("Object without message property, will be filtered out", () => {
const oldAmountOfBarcodes = pass.barcode().length;
// @ts-ignore -- Ignoring for test purposes // @ts-ignore -- Ignoring for test purposes
pass.barcode({ pass.barcode({
format: "PKBarcodeFormatPDF417", format: "PKBarcodeFormatPDF417",
}); });
// @ts-ignore -- Ignoring for test purposes // @ts-ignore -- Ignoring for test purposes
expect(pass._props["barcode"]).toBe(undefined); expect(pass.barcode().length).toBe(oldAmountOfBarcodes);
// @ts-ignore -- Ignoring for test purposes
expect(pass._props["barcodes"]).toBe(undefined);
}); });
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.barcode(5, 10, 15, {
message: "28363516282", message: "28363516282",
@@ -275,9 +276,7 @@ describe("Node-Passkit-generator", function () {
}, 7, 1); }, 7, 1);
// @ts-ignore -- Ignoring for test purposes // @ts-ignore -- Ignoring for test purposes
expect(pass._props["barcode"] instanceof Object).toBe(false); expect(pass.barcode().length).toBe(1)
// @ts-ignore -- Ignoring for test purposes
expect(pass._props["barcodes"]).toBeUndefined();
}); });
}); });
@@ -294,8 +293,7 @@ describe("Node-Passkit-generator", function () {
}); });
it("Null will delete backward support", () => { it("Null will delete backward support", () => {
pass (pass.barcode("Message-22645272183") as PassWithBarcodeMethods)
.barcode("Message-22645272183")
.backward(null); .backward(null);
// @ts-ignore -- Ignoring for test purposes // @ts-ignore -- Ignoring for test purposes