@apptus/esales-api
Version:
Library for making requests to Elevate 4 API v3
65 lines (56 loc) • 1.98 kB
text/typescript
import { describe, it } from '#test';
import type { Facet } from './facets.ts';
/** Will produce type check error if any provided value is not a primitive value (e.g. undefined) */
const primitiveValues = (..._args: (string | number | boolean)[]) => { /* empty */ };
const suite = describe('Facets');
it(suite, 'should test facet type properties and type narrowing', () => {
const facets: Facet[] = [];
facets.forEach(f => {
// Check that various properties exist for different facet types,
// as well as verifying that type narrowing works.
switch (f.type) {
case 'TEXT': {
{
const { id, type, label, sort, selectedCount } = f;
primitiveValues(id, type, label, sort, selectedCount);
}
f.values.forEach(v => {
const { id, count, label, selected } = v;
primitiveValues(id, count, label, selected);
});
break;
}
case 'COLOR': {
{
const { id, type, label, selectedCount } = f;
primitiveValues(id, type, label, selectedCount);
}
f.values.forEach(v => {
const { id, count, label, selected, color } = v;
primitiveValues(id, count, label, selected, color);
});
break;
}
case 'RANGE': {
const { id, type, label, min, max, minSelected, maxSelected } = f;
primitiveValues(id, type, label, min!, max!, minSelected!, maxSelected!);
break;
}
case 'SIZE': {
{
const { id, type, label, selectedCount } = f;
primitiveValues(id, type, label, selectedCount);
}
f.sizeTypes.forEach(t => {
t.formats.forEach(format => {
format.values.forEach(v => {
const { id, count: innerCount, label: innerLabel, selected } = v;
primitiveValues(id, innerCount, innerLabel, selected);
});
});
});
break;
}
}
});
});