Summary
validateBrandKit is supposed to reject a brand kit that carries an unknown type style or caption style — both error messages exist for exactly that case. In practice those two guards can never fire, so a kit with a bogus typeStyle or captionStyle passes validation as if it were valid.
Steps to reproduce
const BK = require("./app/show-brand-kit.js");
const kit = BK.createBrandKit("show-1");
kit.typeStyle = "not-a-real-style";
kit.captionStyle = "also-bogus";
BK.validateBrandKit(kit); // => { ok: true } (expected { ok: false })
Root cause
The guards call the lookup helpers:
if (!getTypeStyle(k.typeStyle)) { ... }
if (!getCaptionStyle(k.captionStyle)) { ... }
But getTypeStyle/getCaptionStyle always return a value because they fall back to the first entry:
function getTypeStyle(id) {
return TYPE_STYLES.find((item) => item.id === id) || TYPE_STYLES[0];
}
So the result is never falsy and the if (!...) branches are dead code. An invalid style id silently validates.
Impact
validateBrandKit is the gate used before a brand kit is saved/applied (and kits can arrive from deserialized storage or be constructed directly). A kit with an unknown style id is accepted, then downstream lookups quietly fall back to the default style — the creator's selection is lost with no error explaining why.
Proposed fix
Check membership against TYPE_STYLES / CAPTION_STYLES directly instead of relying on the falling-back getters, so unknown ids are actually rejected. Add a regression test covering both invalid type and caption style ids.
Summary
validateBrandKitis supposed to reject a brand kit that carries an unknown type style or caption style — both error messages exist for exactly that case. In practice those two guards can never fire, so a kit with a bogustypeStyleorcaptionStylepasses validation as if it were valid.Steps to reproduce
Root cause
The guards call the lookup helpers:
But
getTypeStyle/getCaptionStylealways return a value because they fall back to the first entry:So the result is never falsy and the
if (!...)branches are dead code. An invalid style id silently validates.Impact
validateBrandKitis the gate used before a brand kit is saved/applied (and kits can arrive from deserialized storage or be constructed directly). A kit with an unknown style id is accepted, then downstream lookups quietly fall back to the default style — the creator's selection is lost with no error explaining why.Proposed fix
Check membership against
TYPE_STYLES/CAPTION_STYLESdirectly instead of relying on the falling-back getters, so unknown ids are actually rejected. Add a regression test covering both invalid type and caption style ids.