-
Notifications
You must be signed in to change notification settings - Fork 0
increment: enhance CmsService locale handling with validation and tests #179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
timosville
merged 4 commits into
main
from
sco-2800-querying-a-locale-that-does-not-exist-in-the-cms-returns-500
Jul 31, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9613165
increment: enhance CmsService locale handling with validation and tests
timosville e1119bf
test: accepts well formed tags
timosville f32ff79
test: add beforeEach hook to reset vine configuration in invitation v…
timosville 7e57752
test: add beforeEach hook to reset vine configuration in multiple val…
timosville File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { test, expect } from '@playwright/test'; | ||
| import type { HttpContext } from '@adonisjs/core/http'; | ||
|
|
||
| import { CmsService } from '../../src/backend/services/cms_service'; | ||
|
|
||
| function mockContext(query: Record<string, string | undefined>): HttpContext { | ||
| return { | ||
| request: { | ||
| qs: () => query, | ||
| }, | ||
| } as HttpContext; | ||
| } | ||
|
|
||
| test.describe('CmsService query locale', () => { | ||
| const cms = CmsService.default(); | ||
|
|
||
| test('localeFromQuery returns sourceLocale when param is absent', () => { | ||
| expect(cms.localeFromQuery(mockContext({}))).toBe('en'); | ||
| expect(cms.localeFromQuery(mockContext({ locale: undefined }))).toBe('en'); | ||
| }); | ||
|
|
||
| test('localeFromQuery returns valid tags as-is', () => { | ||
| expect(cms.localeFromQuery(mockContext({ locale: 'en' }))).toBe('en'); | ||
| expect(cms.localeFromQuery(mockContext({ locale: 'zh' }))).toBe('zh'); | ||
| expect(cms.localeFromQuery(mockContext({ locale: 'zh-Hans' }))).toBe('zh-Hans'); | ||
| expect(cms.localeFromQuery(mockContext({ locale: 'en-US' }))).toBe('en-US'); | ||
| }); | ||
|
|
||
| test('localeFromQuery throws E_ROUTE_NOT_FOUND for invalid tags', () => { | ||
| for (const locale of ['zh_Hans', 'zh_CN']) { | ||
| expect(() => cms.localeFromQuery(mockContext({ locale }))).toThrow(); | ||
| try { | ||
| cms.localeFromQuery(mockContext({ locale })); | ||
| } catch (error) { | ||
| expect((error as { code: string; status: number }).code).toBe('E_ROUTE_NOT_FOUND'); | ||
| expect((error as { code: string; status: number }).status).toBe(404); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| test('versionFromQuery mirrors localeFromQuery behavior', () => { | ||
| expect(cms.versionFromQuery(mockContext({}))).toEqual({ | ||
| apiVersion: 1, | ||
| locale: 'en', | ||
| }); | ||
|
|
||
| expect(cms.versionFromQuery(mockContext({ locale: 'zh' }))).toEqual({ | ||
| apiVersion: 1, | ||
| locale: 'zh', | ||
| }); | ||
|
|
||
| expect(() => cms.versionFromQuery(mockContext({ locale: 'zh_Hans' }))).toThrow(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
timosville marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { test, expect } from '@playwright/test'; | ||
|
|
||
| import { languages } from '../../src/frontend/settings/languages/languages'; | ||
| import { isValidLanguageTag } from '../../src/shared/language_helpers'; | ||
|
|
||
| test.describe('isValidLanguageTag', () => { | ||
| test('accepts short and extended BCP 47 tags', () => { | ||
| expect(isValidLanguageTag('en')).toBe(true); | ||
| expect(isValidLanguageTag('zh')).toBe(true); | ||
| expect(isValidLanguageTag('zh-Hans')).toBe(true); | ||
| expect(isValidLanguageTag('en-US')).toBe(true); | ||
| }); | ||
|
|
||
| test('accepts exotic, well-formed tags', () => { | ||
| expect(isValidLanguageTag('qqq')).toBe(true); | ||
| expect(isValidLanguageTag('xx-Sw')).toBe(true); | ||
| }); | ||
|
|
||
| test('rejects underscore-style tags and empty string', () => { | ||
|
timosville marked this conversation as resolved.
|
||
| expect(isValidLanguageTag('zh_Hans')).toBe(false); | ||
| expect(isValidLanguageTag('zh_CN')).toBe(false); | ||
| expect(isValidLanguageTag('')).toBe(false); | ||
| }); | ||
|
|
||
| // Kit language picker defaults — syntax only, not per-client config.languages. | ||
| test('kit language catalog locales are valid BCP 47 tags', () => { | ||
| for (const { locale } of languages) { | ||
| expect(isValidLanguageTag(locale), `invalid locale: ${locale}`).toBe(true); | ||
| } | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.