Duplicate url check w/o trailing / (#7623)
This commit is contained in:
parent
862932d5cd
commit
24ded43d17
@ -62,34 +62,35 @@ describe('urls are sorted', (): void => {
|
||||
describe('urls are not duplicated', (): void => {
|
||||
let hasDevelopment = false;
|
||||
let lastHeader = '';
|
||||
const filtered = allEndpoints.filter(({ isDisabled, isHeader, isUnreachable, text }): boolean => {
|
||||
hasDevelopment = hasDevelopment || (!!isHeader && text === 'Development');
|
||||
const map = allEndpoints
|
||||
.filter(({ isDisabled, isHeader, isUnreachable, text }): boolean => {
|
||||
hasDevelopment = hasDevelopment || (!!isHeader && text === 'Development');
|
||||
|
||||
return !hasDevelopment && !isDisabled && !isUnreachable;
|
||||
});
|
||||
const map: Record<string, string[]> = {};
|
||||
|
||||
filtered.forEach(({ isHeader, text, value }): void => {
|
||||
if (isHeader) {
|
||||
lastHeader = text as string;
|
||||
} else {
|
||||
const path = `${lastHeader} -> ${text as string}`;
|
||||
|
||||
if (!map[value]) {
|
||||
map[value] = [path];
|
||||
return !hasDevelopment && !isDisabled && !isUnreachable;
|
||||
})
|
||||
.reduce((map, { isHeader, text, value }): Record<string, string[]> => {
|
||||
if (isHeader) {
|
||||
lastHeader = text as string;
|
||||
} else {
|
||||
map[value].push(path);
|
||||
}
|
||||
}
|
||||
});
|
||||
const path = `${lastHeader} -> ${text as string}`;
|
||||
const key = value.endsWith('/')
|
||||
? value.substring(0, value.length - 1)
|
||||
: value;
|
||||
|
||||
it('has no duplicates, e.g. parachain & live', (): void => {
|
||||
expect(
|
||||
Object
|
||||
.entries(map)
|
||||
.filter(([, paths]) => paths.length !== 1)
|
||||
).toEqual([]);
|
||||
});
|
||||
map[key] ||= [];
|
||||
map[key].push(path);
|
||||
}
|
||||
|
||||
return map;
|
||||
}, {} as Record<string, string[]>);
|
||||
|
||||
Object
|
||||
.entries(map)
|
||||
.forEach(([url, paths]) =>
|
||||
it(url, (): void => {
|
||||
assert(paths.length === 1, `${url} appears multiple times - ${paths.map((p) => `\n\t"${p}"`).join('')}`);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
describe('endpopints do not contain emojis or all uppercase', (): void => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user