From e3e95629d1d77d985f8a7e1640187861e70e0518 Mon Sep 17 00:00:00 2001 From: MuckT Date: Tue, 7 Nov 2023 12:54:42 -0800 Subject: [PATCH] test: add check for base description length --- src/schema.test.ts | 22 ++++++++++++++++++++++ src/schema.ts | 6 ++++++ 2 files changed, 28 insertions(+) diff --git a/src/schema.test.ts b/src/schema.test.ts index 54c936aa..2c9a2c8a 100644 --- a/src/schema.test.ts +++ b/src/schema.test.ts @@ -511,4 +511,26 @@ describe('invalid applications entries', () => { 'ValidationError: "applications[1]" contains a duplicate value', ) }) + + it('errors on a base description that is over 50 characters', () => { + jest + .spyOn(i18next, 't') + .mockReturnValueOnce( + 'It was the best of times, it was the worst of times', + ) + const testDappObject = { + categories: [category], + applications: [ + { + name: 'GoodDollar', + id: 'gooddollar', + categoryId: 'social-impact', + url: 'https://gooddapp.org/', + }, + ], + } + expect(`${schema.validate(testDappObject).error}`).toBe( + "ValidationError: \"categories[0].id\" failed custom validation because Localization key 'categories.social-impact' in 'locales/base.json' must not be longer than 50 characters", + ) + }) }) diff --git a/src/schema.ts b/src/schema.ts index f9b84ba8..6d3441e4 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -35,6 +35,12 @@ const checkMatchingLocalization: CustomValidator = (value) => { ) } + if (localizedValue.length > 50) { + throw new Error( + `Localization key '${value}' in 'locales/base.json' must not be longer than 50 characters`, + ) + } + return value }