mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
test: add integration test
This commit is contained in:
parent
45cc8f4fb0
commit
8deb493d14
2 changed files with 19 additions and 9 deletions
|
@ -59,8 +59,9 @@ function getValueGuard(type: WellKnownCacheType): ZodType<WellKnownMap[typeof ty
|
|||
|
||||
/**
|
||||
* A reusable cache for well-known data. The name "well-known" has no direct relation to the `.well-known` routes,
|
||||
* but indicates the data to store should be publicly viewable. You should never store any data that is protected
|
||||
* by any authentication method.
|
||||
* but indicates the data to store should be publicly viewable.
|
||||
*
|
||||
* **CAUTION** You should never store any data that is protected by any authentication method.
|
||||
*
|
||||
* For better code maintainability, we recommend to use the cache for database queries only unless you have a strong
|
||||
* reason.
|
||||
|
@ -85,6 +86,7 @@ export class WellKnownCache {
|
|||
key: string
|
||||
): Promise<Optional<WellKnownMap[Type]>> {
|
||||
const data = await this.cacheStore.get(this.cacheKey(type, key));
|
||||
|
||||
return trySafe(() => getValueGuard(type).parse(JSON.parse(data ?? '')));
|
||||
}
|
||||
|
||||
|
|
|
@ -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<SignInExperience>();
|
||||
// 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);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue