Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/core/src/hosted-projects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,14 @@ describe('hosted project contract', () => {
});

describe('createLingvaHostedProjectUpdatePayload', () => {
it('normalizes optional names and rejects blank or oversized names', () => {
const project = { projectId: 'demo', defaultLocale: 'en', locales: ['en'] };
expect(createLingvaHostedProjectUpdatePayload({ ...project, name: ' Mobile app ' }).name).toBe('Mobile app');
expect(createLingvaHostedProjectUpdatePayload(project)).not.toHaveProperty('name');
expect(() => createLingvaHostedProjectUpdatePayload({ ...project, name: ' ' })).toThrow();
expect(() => createLingvaHostedProjectUpdatePayload({ ...project, name: 'x'.repeat(121) })).toThrow();
});

it('normalizes a valid locale list and pins the default first', () => {
expect(
createLingvaHostedProjectUpdatePayload({
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/hosted-projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ export interface LingvaHostedProjectDeleteInput {
}

export interface LingvaHostedProjectUpdateInput {
/** Omit to preserve the current display name. Project ID never changes. */
name?: string;
defaultLocale: string;
locales: readonly string[];
projectId: string;
Expand Down Expand Up @@ -999,6 +1001,10 @@ export function normalizeLingvaHostedProjectUpdateInput(
): LingvaHostedProjectUpdateInput {
const projectId = normalizeIdentifier(input.projectId, 'projectId', LINGVA_HOSTED_PROJECT_ID_PATTERN);
const defaultLocale = normalizeLocaleCode(input.defaultLocale, 'defaultLocale');
const name = input.name === undefined ? undefined : normalizeRequiredString(input.name, 'name');
if (name !== undefined && name.length > LINGVA_HOSTED_PROJECT_NAME_MAX_LENGTH) {
throw new Error('Lingva hosted project name is too long.');
}

if (!Array.isArray(input.locales) || input.locales.length === 0) {
throw new Error('Lingva hosted project locales must include at least one entry.');
Expand All @@ -1020,6 +1026,7 @@ export function normalizeLingvaHostedProjectUpdateInput(
}

return {
...(name === undefined ? {} : { name }),
projectId,
defaultLocale,
locales: [defaultLocale, ...locales.filter((locale) => locale !== defaultLocale)],
Expand Down
Loading