diff --git a/packages/core/src/caches/well-known.ts b/packages/core/src/caches/well-known.ts index 68bd31bcd..5c578c056 100644 --- a/packages/core/src/caches/well-known.ts +++ b/packages/core/src/caches/well-known.ts @@ -59,8 +59,9 @@ function getValueGuard(type: WellKnownCacheType): ZodType> { const data = await this.cacheStore.get(this.cacheKey(type, key)); + return trySafe(() => getValueGuard(type).parse(JSON.parse(data ?? ''))); } diff --git a/packages/integration-tests/src/tests/api/well-known.test.ts b/packages/integration-tests/src/tests/api/well-known.test.ts index 388f543c4..6386a599c 100644 --- a/packages/integration-tests/src/tests/api/well-known.test.ts +++ b/packages/integration-tests/src/tests/api/well-known.test.ts @@ -1,7 +1,6 @@ -import type { SignInExperience } from '@logto/schemas'; +import type { SignInExperience, Translation } from '@logto/schemas'; -import { adminTenantApi } from '#src/api/api.js'; -import { api } from '#src/api/index.js'; +import api, { adminTenantApi, authedAdminApi } from '#src/api/api.js'; describe('.well-known api', () => { it('get /.well-known/sign-in-exp for console', async () => { @@ -27,10 +26,19 @@ describe('.well-known api', () => { }); }); - it('get /.well-known/sign-in-exp for general app', async () => { - const response = await api.get('.well-known/sign-in-exp').json(); + // Also test for Redis cache invalidation + it('should be able to return updated phrases', async () => { + const notification = 'Big brother is watching you.'; + const original = await api + .get('.well-known/phrases?lng=en') + .json<{ translation: Translation }>(); - // Should support sign-in and register - expect(response).toMatchObject({ signInMode: 'SignInAndRegister' }); + expect(original.translation.demo_app).not.toHaveProperty('notification', notification); + + await authedAdminApi.put('custom-phrases/en', { json: { demo_app: { notification } } }); + const updated = await api + .get('.well-known/phrases?lng=en') + .json<{ translation: Translation }>(); + expect(updated.translation.demo_app).toHaveProperty('notification', notification); }); });