From f405fc5a7812f938eecf25728671ea8d9b69a2d4 Mon Sep 17 00:00:00 2001 From: kolaente Date: Fri, 17 Jul 2026 23:21:10 +0200 Subject: [PATCH] test: cover getErrorText interpolation of i18n_params Address pr-swarm finding: design (the fixed line itself was untested). --- frontend/src/message/index.test.ts | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 frontend/src/message/index.test.ts diff --git a/frontend/src/message/index.test.ts b/frontend/src/message/index.test.ts new file mode 100644 index 000000000..e61b559e0 --- /dev/null +++ b/frontend/src/message/index.test.ts @@ -0,0 +1,60 @@ +import {describe, it, expect} from 'vitest' + +import {getErrorText} from './index' + +describe('getErrorText', () => { + it('interpolates i18n_params into the translated error message', () => { + const text = getErrorText({ + response: { + data: { + code: 14002, + message: 'The permission frobnicate of group tasks is invalid.', + i18n_params: {permission: 'frobnicate', group: 'tasks'}, + }, + }, + }) + + expect(text).toContain('frobnicate') + expect(text).toContain('tasks') + }) + + it('falls back to empty placeholders when i18n_params is missing, without crashing', () => { + const text = getErrorText({ + response: { + data: { + code: 14002, + message: 'The permission frobnicate of group tasks is invalid.', + }, + }, + }) + + expect(text).not.toContain('{permission}') + expect(text).not.toContain('{group}') + expect(text).not.toContain('undefined') + }) + + it('falls back to data.message when there is no error code', () => { + const text = getErrorText({ + response: { + data: { + message: 'Something went wrong', + }, + }, + }) + + expect(text).toBe('Something went wrong') + }) + + it('falls back to data.message for an unknown error code', () => { + const text = getErrorText({ + response: { + data: { + code: 99999, + message: 'some backend message', + }, + }, + }) + + expect(text).toBe('some backend message') + }) +})