mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 22:25:24 +00:00
Added setRelevantDate implementation along tests and added and fixed tests of setExpirationDate
This commit is contained in:
@@ -126,8 +126,22 @@ describe("PKPass", () => {
|
|||||||
|
|
||||||
expect(pass.props["nfc"]).toBeUndefined();
|
expect(pass.props["nfc"]).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("setExpirationDate", () => {
|
describe("setExpirationDate", () => {
|
||||||
|
it("should reset instance.props['expirationDate'] if 'null' is passed as value", () => {
|
||||||
|
const pass = new PKPass({}, {});
|
||||||
|
|
||||||
|
pass.setExpirationDate(new Date(2020, 6, 1, 0, 0, 0, 0));
|
||||||
|
// Month starts from 0 in Date Object when used this way, therefore
|
||||||
|
// we expect one month more
|
||||||
|
expect(pass.props["expirationDate"]).toBe("2020-07-01T00:00:00Z");
|
||||||
|
|
||||||
|
pass.setExpirationDate(null);
|
||||||
|
|
||||||
|
expect(pass.props["expirationDate"]).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
it("Won't apply changes without a valid argument", () => {
|
it("Won't apply changes without a valid argument", () => {
|
||||||
const pass = new PKPass({}, {});
|
const pass = new PKPass({}, {});
|
||||||
|
|
||||||
@@ -146,9 +160,7 @@ describe("PKPass", () => {
|
|||||||
pass.setExpirationDate(new Date(2020, 6, 1, 0, 0, 0, 0));
|
pass.setExpirationDate(new Date(2020, 6, 1, 0, 0, 0, 0));
|
||||||
// Month starts from 0 in Date Object when used this way, therefore
|
// Month starts from 0 in Date Object when used this way, therefore
|
||||||
// we expect one month more
|
// we expect one month more
|
||||||
expect(pass.props["expirationDate"]).toBe(
|
expect(pass.props["expirationDate"]).toBe("2020-07-01T00:00:00Z");
|
||||||
"2020-07-01T00:00:00Z",
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("An invalid date, will not apply changes", () => {
|
it("An invalid date, will not apply changes", () => {
|
||||||
@@ -163,5 +175,50 @@ describe("PKPass", () => {
|
|||||||
expect(pass.props["expirationDate"]).toBe(undefined);
|
expect(pass.props["expirationDate"]).toBe(undefined);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("setRelevantDate", () => {
|
||||||
|
it("should reset instance.props['relevantDate'] if 'null' is passed as value", () => {
|
||||||
|
const pass = new PKPass({}, {});
|
||||||
|
|
||||||
|
pass.setRelevantDate(new Date(2020, 6, 1, 0, 0, 0, 0));
|
||||||
|
// Month starts from 0 in Date Object when used this way, therefore
|
||||||
|
// we expect one month more
|
||||||
|
expect(pass.props["relevantDate"]).toBe("2020-07-01T00:00:00Z");
|
||||||
|
|
||||||
|
pass.setRelevantDate(null);
|
||||||
|
|
||||||
|
expect(pass.props["relevantDate"]).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Won't apply changes without a valid argument", () => {
|
||||||
|
const pass = new PKPass({}, {});
|
||||||
|
|
||||||
|
// @ts-expect-error
|
||||||
|
pass.setRelevantDate();
|
||||||
|
expect(pass.props["relevantDate"]).toBe(undefined);
|
||||||
|
|
||||||
|
// @ts-expect-error
|
||||||
|
pass.setRelevantDate(42);
|
||||||
|
expect(pass.props["relevantDate"]).toBe(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("expects a Date object as the only argument", () => {
|
||||||
|
const pass = new PKPass({}, {});
|
||||||
|
|
||||||
|
pass.setRelevantDate(new Date("10-04-2021"));
|
||||||
|
expect(pass.props["relevantDate"]).toBe("2021-10-04T00:00:00Z");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("An invalid date, will not apply changes", () => {
|
||||||
|
const pass = new PKPass({}, {});
|
||||||
|
|
||||||
|
// @ts-expect-error
|
||||||
|
pass.setRelevantDate("32/18/228317");
|
||||||
|
expect(pass.props["relevantDate"]).toBe(undefined);
|
||||||
|
|
||||||
|
// @ts-expect-error
|
||||||
|
pass.setRelevantDate("32/18/228317");
|
||||||
|
expect(pass.props["relevantDate"]).toBe(undefined);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -367,9 +367,16 @@ export default class PKPass extends Bundle {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
setRelevantDate(date: Date): this {
|
setRelevantDate(date: Date): this {
|
||||||
/**
|
if (date === null) {
|
||||||
* @TODO implement
|
delete this[propsSymbol]["relevantDate"];
|
||||||
*/
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsedDate = processDate("relevantDate", date);
|
||||||
|
|
||||||
|
if (parsedDate) {
|
||||||
|
this[propsSymbol]["relevantDate"] = parsedDate;
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user