0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-27 21:39:16 -05:00
logto/packages/integration-tests/tests/username-password-flow.test.ts

50 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-07-25 17:39:09 +08:00
import { LogtoConfig } from '@logto/node';
import { demoAppApplicationId } from '@logto/schemas/lib/seeds';
2022-07-25 17:39:09 +08:00
import LogtoClient from '@/client/logto-client';
import { demoAppRedirectUri, logtoUrl } from '@/constants';
import {
consentUserAndGetSignInCallbackUri,
registerUserWithUsernameAndPassword,
signInWithUsernameAndPassword,
visitSignInUri,
} from '@/ui-actions';
import { generatePassword, generateUsername } from '@/utils';
describe('username and password flow', () => {
2022-07-25 17:39:09 +08:00
it('should register and sign in with username and password successfully', async () => {
const logtoConfig: LogtoConfig = {
endpoint: logtoUrl,
appId: demoAppApplicationId,
persistAccessToken: false,
};
2022-07-25 17:39:09 +08:00
const logtoClient = new LogtoClient(logtoConfig);
2022-07-25 17:39:09 +08:00
await logtoClient.signIn(demoAppRedirectUri);
2022-07-25 17:39:09 +08:00
expect(logtoClient.navigateUrl).toBeTruthy();
2022-07-25 17:39:09 +08:00
const interactionCookie = await visitSignInUri(logtoClient.navigateUrl);
2022-07-25 17:39:09 +08:00
const username = generateUsername();
const password = generatePassword();
2022-07-25 17:39:09 +08:00
await registerUserWithUsernameAndPassword(username, password, interactionCookie);
2022-07-25 17:39:09 +08:00
const interactionCookieWithSession = await signInWithUsernameAndPassword(
username,
password,
interactionCookie
);
2022-07-25 17:39:09 +08:00
const signInCallbackUri = await consentUserAndGetSignInCallbackUri(
interactionCookieWithSession
);
2022-07-25 17:39:09 +08:00
await logtoClient.handleSignInCallback(signInCallbackUri);
expect(logtoClient.isAuthenticated).toBeTruthy();
});
});