0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-27 21:39:16 -05:00

test(test): add sign-in then sign-out test (#1702)

add sign-in then sign-out test
This commit is contained in:
simeng-li 2022-08-01 16:28:19 +08:00 committed by GitHub
parent ef9bc1e3fc
commit 6ca417fbd8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 1 deletions

View file

@ -87,6 +87,10 @@ export default class MockClient {
return this.logto.getAccessToken(resource);
}
public async signOut(postSignOutRedirectUri?: string) {
return this.logto.signOut(postSignOutRedirectUri);
}
public get isAuthenticated() {
return this.logto.isAuthenticated;
}

View file

@ -16,9 +16,16 @@ import {
sendSignInUserWithSmsPasscode,
verifySignInUserWithSmsPasscode,
disableConnector,
signInWithUsernameAndPassword,
} from '@/api';
import MockClient from '@/client';
import { registerNewUser, signIn, setUpConnector, readPasscode } from '@/helpers';
import {
registerNewUser,
signIn,
setUpConnector,
readPasscode,
createUserByAdmin,
} from '@/helpers';
import { generateUsername, generatePassword, generateEmail, generatePhone } from '@/utils';
describe('username and password flow', () => {
@ -179,3 +186,33 @@ describe('sms passwordless flow', () => {
void disableConnector(mockSmsConnectorId);
});
});
describe('sign-in and sign-out', () => {
const username = generateUsername();
const password = generatePassword();
beforeAll(async () => {
await createUserByAdmin(username, password);
});
it('verify sign-in and then sign-out', async () => {
const client = new MockClient();
await client.initSession();
assert(client.interactionCookie, new Error('Session not found'));
const { redirectTo } = await signInWithUsernameAndPassword(
username,
password,
client.interactionCookie
);
await client.processSession(redirectTo);
expect(client.isAuthenticated).toBe(true);
await client.signOut();
expect(client.isAuthenticated).toBe(false);
});
});