Commit 467f9c26 authored by Diegodlh's avatar Diegodlh
Browse files

Reject template creation if a force required field is missing

parent 6eba2490
......@@ -153,3 +153,21 @@ it("constructor optionally skips invalid field definitions", () => {
new TranslationTemplate("example.com", definition as TemplateDefinition);
}).toThrow();
});
it("rejects creation if a mandatory field is missing", () => {
const definition: TemplateDefinition = {
path: "/",
fields: [
{
fieldname: "title",
required: true,
procedures: [],
},
],
};
expect(() => {
new TranslationTemplate("example.com", definition, {
forceRequiredFields: ["itemType", "title"],
});
}).toThrow('Mandatory field "itemType" missing from template definition');
});
......@@ -29,6 +29,19 @@ export abstract class BaseTranslationTemplate {
if (!isDomainName(domain)) {
throw new DomainNameError(domain);
}
// reject template creation if any mandatory field is missing
if ("fields" in template) {
const fieldnames = template.fields.map((field) => field.fieldname);
for (const field of forceRequiredFields) {
if (!fieldnames.includes(field)) {
throw new Error(
`Mandatory field "${field}" missing from template definition`
);
}
}
}
this.domain = domain;
this.forceRequiredFields = forceRequiredFields;
this.label = template.label ?? "";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment