mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 14:25:17 +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
|
||||
expect(pass._props["locations"].length).toBe(oldAmountOfLocations);
|
||||
expect(pass.locations().length).toBe(oldAmountOfLocations);
|
||||
});
|
||||
|
||||
it("Two locations, with one invalid, will be filtered", () => {
|
||||
@@ -136,12 +136,14 @@ describe("Node-Passkit-generator", function () {
|
||||
});
|
||||
|
||||
// @ts-ignore -- Ignoring for test purposes
|
||||
expect(pass._props["locations"].length).toBe(oldAmountOfLocations+1);
|
||||
expect(pass.locations().length).toBe(oldAmountOfLocations+1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Beacons :: ", () => {
|
||||
it("One-Invalid-schema beacon data won't apply changes", () => {
|
||||
const oldBeacons = pass.beacons();
|
||||
|
||||
pass.beacons({
|
||||
// @ts-ignore
|
||||
"ibrupofene": "no",
|
||||
@@ -151,10 +153,12 @@ describe("Node-Passkit-generator", function () {
|
||||
});
|
||||
|
||||
// @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", () => {
|
||||
const oldBeacons = pass.beacons();
|
||||
|
||||
pass.beacons({
|
||||
"major": 55,
|
||||
"minor": 0,
|
||||
@@ -168,7 +172,7 @@ describe("Node-Passkit-generator", function () {
|
||||
});
|
||||
|
||||
// @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[] {
|
||||
if (data === undefined) {
|
||||
return this._props["beacons"];
|
||||
if (data === null) {
|
||||
delete this._props["beacons"];
|
||||
return assignLength<PassWithLengthField>(0, this);
|
||||
}
|
||||
|
||||
if (!data.length) {
|
||||
this._props["beacons"] = [];
|
||||
return assignLength(0, this);
|
||||
return this._props["beacons"];
|
||||
}
|
||||
|
||||
const validBeacons = data.reduce<schema.Beacon[]>((acc, current) => {
|
||||
@@ -307,13 +307,13 @@ export class Pass implements PassIndexSignature {
|
||||
*/
|
||||
|
||||
locations(...data: schema.Location[]): PassWithLengthField | schema.Location[] {
|
||||
if (data === undefined) {
|
||||
return this._props["locations"];
|
||||
if (data === null) {
|
||||
delete this._props["locations"];
|
||||
return assignLength<PassWithLengthField>(0, this);
|
||||
}
|
||||
|
||||
if (!data.length) {
|
||||
this._props["locations"] = [];
|
||||
return assignLength(0, this);
|
||||
return this._props["locations"];
|
||||
}
|
||||
|
||||
const validLocations = data.reduce<schema.Location[]>((acc, current) => {
|
||||
@@ -328,8 +328,6 @@ export class Pass implements PassIndexSignature {
|
||||
return assignLength(0, this);
|
||||
}
|
||||
|
||||
console.log("Locations:", this._props["locations"]);
|
||||
|
||||
(this._props["locations"] || (this._props["locations"] = [])).push(...validLocations);
|
||||
|
||||
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[] {
|
||||
console.log(first, data);
|
||||
if (first === undefined && (data === undefined || !data.length)) {
|
||||
return this._props["barcodes"];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user