Build MerchantFlow onboarding CRM foundation
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { expect, it } from 'vitest';
|
||||
import { en, ru } from './locales';
|
||||
import { safeReturnTo } from './lib/api';
|
||||
function keys(value: object, prefix = ''): string[] {
|
||||
return Object.entries(value)
|
||||
.flatMap(([key, child]) =>
|
||||
typeof child === 'object' ? keys(child, `${prefix}${key}.`) : [`${prefix}${key}`],
|
||||
)
|
||||
.filter((key) => !/_(few|many)$/.test(key))
|
||||
.sort();
|
||||
}
|
||||
it('has matching EN/RU keys and interpolation variables', () => {
|
||||
expect(keys(en)).toEqual(keys(ru));
|
||||
for (const key of keys(en)) {
|
||||
const get = (obj: object) =>
|
||||
key.split('.').reduce<unknown>((v, k) => (v as Record<string, unknown>)[k], obj) as string;
|
||||
expect(get(en).match(/{{\w+}}/g)).toEqual(get(ru).match(/{{\w+}}/g));
|
||||
}
|
||||
});
|
||||
it('only accepts internal CRM return paths', () => {
|
||||
expect(safeReturnTo('/app/merchants/merchant-01?x=1')).toBe('/app/merchants/merchant-01?x=1');
|
||||
for (const unsafe of ['https://example.com', '//example.com', '/application', '/app\\evil', null])
|
||||
expect(safeReturnTo(unsafe)).toBe('/app');
|
||||
});
|
||||
Reference in New Issue
Block a user