mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 21:25:26 +00:00
Fixed beacons and locations content getting
This commit is contained in:
@@ -120,7 +120,7 @@ describe("Node-Passkit-generator", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
// @ts-ignore -- Ignoring for test purposes
|
||||||
expect(pass._props["locations"].length).toBe(oldAmountOfLocations);
|
expect(pass.locations().length).toBe(oldAmountOfLocations);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Two locations, with one invalid, will be filtered", () => {
|
it("Two locations, with one invalid, will be filtered", () => {
|
||||||
@@ -136,12 +136,14 @@ describe("Node-Passkit-generator", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
// @ts-ignore -- Ignoring for test purposes
|
||||||
expect(pass._props["locations"].length).toBe(oldAmountOfLocations+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();
|
||||||
|
|
||||||
pass.beacons({
|
pass.beacons({
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
"ibrupofene": "no",
|
"ibrupofene": "no",
|
||||||
@@ -151,10 +153,12 @@ describe("Node-Passkit-generator", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
// @ts-ignore -- Ignoring for test purposes
|
||||||
expect(pass._props["beacons"]).toBe(undefined);
|
expect(pass.beacons()).toBe(oldBeacons ? oldBeacons.length : undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Two beacons sets, with one invalid, will be filtered", () => {
|
it("Two beacons sets, with one invalid, will be filtered", () => {
|
||||||
|
const oldBeacons = pass.beacons();
|
||||||
|
|
||||||
pass.beacons({
|
pass.beacons({
|
||||||
"major": 55,
|
"major": 55,
|
||||||
"minor": 0,
|
"minor": 0,
|
||||||
@@ -168,7 +172,7 @@ describe("Node-Passkit-generator", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// @ts-ignore -- Ignoring for test purposes
|
// @ts-ignore -- Ignoring for test purposes
|
||||||
expect(pass._props["beacons"].length).toBe(1);
|
expect(pass.beacons().length).toBe(oldBeacons ? oldBeacons.length+1 : 1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
19
src/pass.ts
19
src/pass.ts
@@ -274,13 +274,13 @@ export class Pass implements PassIndexSignature {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
beacons(...data: schema.Beacon[]): PassWithLengthField | schema.Beacon[] {
|
beacons(...data: schema.Beacon[]): PassWithLengthField | schema.Beacon[] {
|
||||||
if (data === undefined) {
|
if (data === null) {
|
||||||
return this._props["beacons"];
|
delete this._props["beacons"];
|
||||||
|
return assignLength<PassWithLengthField>(0, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.length) {
|
if (!data.length) {
|
||||||
this._props["beacons"] = [];
|
return this._props["beacons"];
|
||||||
return assignLength(0, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const validBeacons = data.reduce<schema.Beacon[]>((acc, current) => {
|
const validBeacons = data.reduce<schema.Beacon[]>((acc, current) => {
|
||||||
@@ -307,13 +307,13 @@ export class Pass implements PassIndexSignature {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
locations(...data: schema.Location[]): PassWithLengthField | schema.Location[] {
|
locations(...data: schema.Location[]): PassWithLengthField | schema.Location[] {
|
||||||
if (data === undefined) {
|
if (data === null) {
|
||||||
return this._props["locations"];
|
delete this._props["locations"];
|
||||||
|
return assignLength<PassWithLengthField>(0, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.length) {
|
if (!data.length) {
|
||||||
this._props["locations"] = [];
|
return this._props["locations"];
|
||||||
return assignLength(0, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const validLocations = data.reduce<schema.Location[]>((acc, current) => {
|
const validLocations = data.reduce<schema.Location[]>((acc, current) => {
|
||||||
@@ -328,8 +328,6 @@ export class Pass implements PassIndexSignature {
|
|||||||
return assignLength(0, this);
|
return assignLength(0, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Locations:", this._props["locations"]);
|
|
||||||
|
|
||||||
(this._props["locations"] || (this._props["locations"] = [])).push(...validLocations);
|
(this._props["locations"] || (this._props["locations"] = [])).push(...validLocations);
|
||||||
|
|
||||||
return assignLength(this._props["locations"].length, this);
|
return assignLength(this._props["locations"].length, this);
|
||||||
@@ -377,7 +375,6 @@ export class Pass implements PassIndexSignature {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
barcode(first?: string | schema.Barcode, ...data: schema.Barcode[]): PassWithBarcodeMethods | schema.Barcode[] {
|
barcode(first?: string | schema.Barcode, ...data: schema.Barcode[]): PassWithBarcodeMethods | schema.Barcode[] {
|
||||||
console.log(first, data);
|
|
||||||
if (first === undefined && (data === undefined || !data.length)) {
|
if (first === undefined && (data === undefined || !data.length)) {
|
||||||
return this._props["barcodes"];
|
return this._props["barcodes"];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user