mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 19:25:23 +00:00
Unified props passing to PKPass.from between template and PKPass
This commit is contained in:
@@ -1052,18 +1052,20 @@ describe("PKPass", () => {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
const newPass = await PKPass.from({
|
const newPass = await PKPass.from(
|
||||||
model: path.resolve(
|
{
|
||||||
__dirname,
|
model: path.resolve(
|
||||||
"../examples/models/exampleBooking.pass",
|
__dirname,
|
||||||
),
|
"../examples/models/exampleBooking.pass",
|
||||||
certificates: {
|
),
|
||||||
...baseCerts,
|
certificates: {
|
||||||
|
...baseCerts,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
props: {
|
{
|
||||||
voided: true,
|
voided: true,
|
||||||
},
|
},
|
||||||
});
|
);
|
||||||
|
|
||||||
expect(Object.keys(newPass[filesSymbol]).length).toBe(7);
|
expect(Object.keys(newPass[filesSymbol]).length).toBe(7);
|
||||||
|
|
||||||
|
|||||||
@@ -39,13 +39,10 @@ export default class PKPass extends Bundle {
|
|||||||
|
|
||||||
static async from<S extends PKPass | Schemas.Template>(
|
static async from<S extends PKPass | Schemas.Template>(
|
||||||
source: S,
|
source: S,
|
||||||
additionalProps?: S extends PKPass
|
props?: Schemas.OverridablePassProps,
|
||||||
? Schemas.OverridablePassProps
|
|
||||||
: never,
|
|
||||||
): Promise<PKPass> {
|
): Promise<PKPass> {
|
||||||
let certificates: Schemas.CertificatesSchema = undefined;
|
let certificates: Schemas.CertificatesSchema = undefined;
|
||||||
let buffers: Schemas.FileBuffers = undefined;
|
let buffers: Schemas.FileBuffers = undefined;
|
||||||
let props: Schemas.OverridablePassProps = {};
|
|
||||||
|
|
||||||
if (!source) {
|
if (!source) {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
@@ -86,20 +83,13 @@ export default class PKPass extends Bundle {
|
|||||||
|
|
||||||
buffers = await getModelFolderContents(source.model);
|
buffers = await getModelFolderContents(source.model);
|
||||||
certificates = source.certificates;
|
certificates = source.certificates;
|
||||||
props = Schemas.validate(
|
|
||||||
Schemas.OverridablePassProps,
|
|
||||||
source.props,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (additionalProps && Object.keys(additionalProps).length) {
|
return new PKPass(
|
||||||
Object.assign(
|
buffers,
|
||||||
props,
|
certificates,
|
||||||
Schemas.validate(Schemas.OverridablePassProps, additionalProps),
|
Schemas.validate(Schemas.OverridablePassProps, props),
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
return new PKPass(buffers, certificates, props);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -154,13 +154,11 @@ export const PassProps = Joi.object<
|
|||||||
export interface Template {
|
export interface Template {
|
||||||
model: string;
|
model: string;
|
||||||
certificates: CertificatesSchema;
|
certificates: CertificatesSchema;
|
||||||
props?: OverridablePassProps;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Template = Joi.object<Template>({
|
export const Template = Joi.object<Template>({
|
||||||
model: Joi.string().required(),
|
model: Joi.string().required(),
|
||||||
certificates: Joi.object().required(),
|
certificates: Joi.object().required(),
|
||||||
props: OverridablePassProps,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// --------- UTILITIES ---------- //
|
// --------- UTILITIES ---------- //
|
||||||
|
|||||||
Reference in New Issue
Block a user