2022-10-31 21:08:47 -05:00
|
|
|
import { SignUpIdentifier } from '@logto/schemas';
|
2022-07-26 01:29:38 -05:00
|
|
|
import { assert } from '@silverhand/essentials';
|
|
|
|
|
2022-07-27 21:30:37 -05:00
|
|
|
import { getLogs, getLog } from '@/api';
|
2022-10-31 21:08:47 -05:00
|
|
|
import { registerNewUser, setSignUpIdentifier } from '@/helpers';
|
2022-07-27 21:30:37 -05:00
|
|
|
import { generateUsername, generatePassword } from '@/utils';
|
2022-07-26 01:29:38 -05:00
|
|
|
|
|
|
|
describe('admin console logs', () => {
|
2022-07-27 21:30:37 -05:00
|
|
|
const username = generateUsername();
|
|
|
|
const password = generatePassword();
|
|
|
|
|
2022-10-31 21:08:47 -05:00
|
|
|
beforeAll(async () => {
|
|
|
|
await setSignUpIdentifier(SignUpIdentifier.Username);
|
|
|
|
});
|
|
|
|
|
2022-07-26 01:29:38 -05:00
|
|
|
it('should get logs and visit log details successfully', async () => {
|
2022-07-27 21:30:37 -05:00
|
|
|
await registerNewUser(username, password);
|
|
|
|
|
|
|
|
const logs = await getLogs();
|
2022-07-26 01:29:38 -05:00
|
|
|
|
2022-07-27 21:30:37 -05:00
|
|
|
const registerLog = logs.filter(
|
|
|
|
({ type, payload }) =>
|
|
|
|
type === 'RegisterUsernamePassword' &&
|
|
|
|
(payload as Record<string, unknown>).username === username
|
|
|
|
);
|
2022-07-26 01:29:38 -05:00
|
|
|
|
2022-07-27 21:30:37 -05:00
|
|
|
expect(registerLog.length).toBeGreaterThan(0);
|
2022-07-26 01:29:38 -05:00
|
|
|
|
2022-07-27 21:30:37 -05:00
|
|
|
assert(registerLog[0], new Error('Log is not valid'));
|
2022-07-26 01:29:38 -05:00
|
|
|
|
2022-07-27 21:30:37 -05:00
|
|
|
const logDetails = await getLog(registerLog[0].id);
|
2022-07-26 01:29:38 -05:00
|
|
|
|
2022-07-27 21:30:37 -05:00
|
|
|
expect(logDetails).toMatchObject(registerLog[0]);
|
2022-07-26 01:29:38 -05:00
|
|
|
});
|
|
|
|
});
|