fix bug#7
Build & Push / Build & Push Docker Image (push) Failing after 2m50s
Test / Type Check (all packages) (push) Failing after 55s
Test / API Unit Tests (push) Has been skipped
Test / Homepage Unit Tests (push) Has been skipped
Test / Carplace Unit Tests (push) Has been skipped
Test / Admin Unit Tests (push) Has been skipped
Test / Dashboard Unit Tests (push) Has been skipped
Test / API Integration Tests (push) Has been skipped

This commit is contained in:
root
2026-07-20 01:01:21 -04:00
parent 7ce0a5adf3
commit fb7b4eefc1
33 changed files with 342 additions and 87 deletions
@@ -84,6 +84,17 @@ describe('dashboard scoped preferences', () => {
expect(readScopedPreference('theme', ['legacy-theme'])).toBe('base')
})
it('can read and write legacy cookie names for cross-app preferences', () => {
const browser = installBrowser('hpc-theme=dark')
expect(readScopedPreference('rentaldrivego-theme', [], ['hpc-theme'])).toBe('dark')
writeScopedPreference('rentaldrivego-theme', 'light', [], ['hpc-theme'])
expect(browser.cookie).toContain('rentaldrivego-theme=light')
expect(browser.cookie).toContain('hpc-theme=light')
})
it('writes shared and legacy preference values without auth-token scoping', () => {
const browser = installBrowser()
+21 -2
View File
@@ -1,6 +1,8 @@
export const SHARED_LANGUAGE_COOKIE = 'rentaldrivego-language'
export const SHARED_LANGUAGE_KEY = 'rentaldrivego-language'
export const SHARED_THEME_KEY = 'rentaldrivego-theme'
export const HOMEPAGE_THEME_COOKIE = 'hpc-theme'
export const HOMEPAGE_THEME_KEY = 'hpc.theme.preference'
function readEmployeeToken() {
return null
@@ -54,7 +56,11 @@ export function readCurrentUserScopedPreference(baseKey: string) {
return window.localStorage.getItem(getScopedPreferenceKey(baseKey))
}
export function readScopedPreference(baseKey: string, legacyKeys: string[] = []) {
export function readScopedPreference(
baseKey: string,
legacyKeys: string[] = [],
legacyCookieNames: string[] = [],
) {
if (typeof window === 'undefined') return null
const scopedCookie = readCookie(getScopedPreferenceCookieName(baseKey))
@@ -63,6 +69,11 @@ export function readScopedPreference(baseKey: string, legacyKeys: string[] = [])
const sharedCookie = readCookie(baseKey)
if (sharedCookie) return sharedCookie
for (const cookieName of legacyCookieNames) {
const legacyCookie = readCookie(cookieName)
if (legacyCookie) return legacyCookie
}
const scopedKey = getScopedPreferenceKey(baseKey)
const candidates = [scopedKey, baseKey, ...legacyKeys]
@@ -74,7 +85,12 @@ export function readScopedPreference(baseKey: string, legacyKeys: string[] = [])
return null
}
export function writeScopedPreference(baseKey: string, value: string, legacyKeys: string[] = []) {
export function writeScopedPreference(
baseKey: string,
value: string,
legacyKeys: string[] = [],
legacyCookieNames: string[] = [],
) {
if (typeof window === 'undefined') return
const scopedKey = getScopedPreferenceKey(baseKey)
@@ -84,6 +100,9 @@ export function writeScopedPreference(baseKey: string, value: string, legacyKeys
if (scopedCookie !== baseKey) {
writeCookie(scopedCookie, value)
}
for (const cookieName of legacyCookieNames) {
writeCookie(cookieName, value)
}
window.localStorage.setItem(scopedKey, value)
window.localStorage.setItem(baseKey, value)