0
Fork 0
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:
Gao Sun 2023-04-07 23:39:03 +08:00
parent 45cc8f4fb0
commit 8deb493d14
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
2 changed files with 19 additions and 9 deletions

View file

@ -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, * 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 * but indicates the data to store should be publicly viewable.
* by any authentication method. *
* **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 * For better code maintainability, we recommend to use the cache for database queries only unless you have a strong
* reason. * reason.
@ -85,6 +86,7 @@ export class WellKnownCache {
key: string key: string
): Promise<Optional<WellKnownMap[Type]>> { ): Promise<Optional<WellKnownMap[Type]>> {
const data = await this.cacheStore.get(this.cacheKey(type, key)); const data = await this.cacheStore.get(this.cacheKey(type, key));
return trySafe(() => getValueGuard(type).parse(JSON.parse(data ?? ''))); return trySafe(() => getValueGuard(type).parse(JSON.parse(data ?? '')));
} }

View file

@ -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, { adminTenantApi, authedAdminApi } from '#src/api/api.js';
import { api } from '#src/api/index.js';
describe('.well-known api', () => { describe('.well-known api', () => {
it('get /.well-known/sign-in-exp for console', async () => { 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 () => { // Also test for Redis cache invalidation
const response = await api.get('.well-known/sign-in-exp').json<SignInExperience>(); 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(original.translation.demo_app).not.toHaveProperty('notification', notification);
expect(response).toMatchObject({ signInMode: 'SignInAndRegister' });
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);
}); });
}); });