mirror of
https://github.com/logto-io/logto.git
synced 2024-12-23 20:33:16 -05:00
6a2e604926
* test(ui): init smoke testing * fix(test): logto url env key
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { managementResource } from '@logto/schemas/lib/seeds';
|
|
import { assert } from '@silverhand/essentials';
|
|
|
|
import { signInWithUsernameAndPassword } from '@/api';
|
|
import MockClient from '@/client';
|
|
import { createUserByAdmin } from '@/helpers';
|
|
import { generateUsername, generatePassword } from '@/utils';
|
|
|
|
describe('get access token', () => {
|
|
const username = generateUsername();
|
|
const password = generatePassword();
|
|
|
|
beforeAll(async () => {
|
|
await createUserByAdmin(username, password);
|
|
});
|
|
|
|
it('sign-in and getAccessToken', async () => {
|
|
const client = new MockClient({ resources: [managementResource.indicator] });
|
|
await client.initSession();
|
|
assert(client.interactionCookie, new Error('Session not found'));
|
|
|
|
const { redirectTo } = await signInWithUsernameAndPassword(
|
|
username,
|
|
password,
|
|
client.interactionCookie
|
|
);
|
|
|
|
await client.processSession(redirectTo);
|
|
|
|
assert(client.isAuthenticated, new Error('Sign in get get access token failed'));
|
|
|
|
const accessToken = await client.getAccessToken(managementResource.indicator);
|
|
|
|
expect(accessToken).not.toBeNull();
|
|
|
|
// Request for invalid resource should throw
|
|
void expect(client.getAccessToken('api.foo.com')).rejects.toThrow();
|
|
});
|
|
});
|