0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

test(test): add wellknown integration test (#1694)

add wellknown api integration test
This commit is contained in:
simeng-li 2022-07-29 17:48:23 +08:00 committed by GitHub
parent a850694070
commit c76a0b8430
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 1 deletions

View file

@ -7,5 +7,6 @@ export * from './session';
export * from './logs';
export * from './dashboard';
export * from './me';
export * from './wellknown';
export { default as api, authedAdminApi } from './api';

View file

@ -0,0 +1,12 @@
import { SignInExperience } from '@logto/schemas';
import api from './api';
export const getWellKnownSignInExperience = (interactionCookie: string) =>
api
.get('.well-known/sign-in-exp', {
headers: {
cookie: interactionCookie,
},
})
.json<SignInExperience>();

View file

@ -22,7 +22,7 @@ export default class MockClient {
private readonly storage: MemoryStorage;
private readonly logto: LogtoClient;
constructor(config?: LogtoConfig) {
constructor(config?: Partial<LogtoConfig>) {
this.storage = new MemoryStorage();
this.logto = new LogtoClient(

View file

@ -6,3 +6,4 @@ export const logtoUrl = getEnv('LOGTO_URL');
export const discoveryUrl = `${logtoUrl}/oidc/.well-known/openid-configuration`;
export const demoAppRedirectUri = `${logtoUrl}/${demoAppApplicationId}`;
export const adminConsoleRedirectUri = `${logtoUrl}/console/callback`;

View file

@ -0,0 +1,40 @@
import { adminConsoleApplicationId } from '@logto/schemas/lib/seeds';
import { assert } from '@silverhand/essentials';
import { getWellKnownSignInExperience } from '@/api';
import MockClient from '@/client';
import { adminConsoleRedirectUri } from '@/constants';
describe('wellknown api', () => {
it('get /.well-known/sign-in-exp for AC', async () => {
const client = new MockClient({ appId: adminConsoleApplicationId });
await client.initSession(adminConsoleRedirectUri);
assert(client.interactionCookie, new Error('Session not found'));
const response = await getWellKnownSignInExperience(client.interactionCookie);
expect(response).toMatchObject({
signInMethods: {
username: 'primary',
email: 'disabled',
sms: 'disabled',
social: 'disabled',
},
signInMode: 'SignIn',
});
});
it('get /.well-known/sign-in-exp for general app', async () => {
const client = new MockClient();
await client.initSession();
assert(client.interactionCookie, new Error('Session not found'));
const response = await getWellKnownSignInExperience(client.interactionCookie);
// Should support sign-in and register
expect(response).toMatchObject({ signInMode: 'SignInAndRegister' });
});
});