2022-10-31 21:08:47 -05:00
|
|
|
import { SignUpIdentifier } from '@logto/schemas';
|
|
|
|
|
2022-10-21 00:14:17 -05:00
|
|
|
import type { StatisticsData } from '@/api';
|
|
|
|
import { getTotalUsersCount, getNewUsersData, getActiveUsersData } from '@/api';
|
2022-10-31 21:08:47 -05:00
|
|
|
import { createUserByAdmin, registerNewUser, setSignUpIdentifier, signIn } from '@/helpers';
|
2022-07-27 21:30:37 -05:00
|
|
|
import { generateUsername, generatePassword } from '@/utils';
|
2022-07-25 22:50:40 -05:00
|
|
|
|
|
|
|
describe('admin console dashboard', () => {
|
2022-10-31 21:08:47 -05:00
|
|
|
beforeAll(async () => {
|
|
|
|
await setSignUpIdentifier(SignUpIdentifier.Username);
|
|
|
|
});
|
|
|
|
|
2022-07-25 22:50:40 -05:00
|
|
|
it('should get total user count successfully', async () => {
|
2022-07-27 21:30:37 -05:00
|
|
|
const { totalUserCount: originTotalUserCount } = await getTotalUsersCount();
|
2022-07-25 22:50:40 -05:00
|
|
|
|
2022-07-27 21:30:37 -05:00
|
|
|
const password = generatePassword();
|
|
|
|
const username = generateUsername();
|
|
|
|
await createUserByAdmin(username, password);
|
2022-07-25 22:50:40 -05:00
|
|
|
|
2022-07-27 21:30:37 -05:00
|
|
|
const { totalUserCount } = await getTotalUsersCount();
|
2022-07-25 22:50:40 -05:00
|
|
|
|
|
|
|
expect(totalUserCount).toBe(originTotalUserCount + 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should get new user statistics successfully', async () => {
|
2022-07-27 21:30:37 -05:00
|
|
|
const originUserStatistics = await getNewUsersData();
|
2022-07-25 22:50:40 -05:00
|
|
|
|
2022-07-27 21:30:37 -05:00
|
|
|
await registerNewUser(generateUsername(), generatePassword());
|
2022-07-25 22:50:40 -05:00
|
|
|
|
2022-07-27 21:30:37 -05:00
|
|
|
const newUserStatistics = await getNewUsersData();
|
2022-07-25 22:50:40 -05:00
|
|
|
|
|
|
|
const keyToCompare: Array<keyof StatisticsData> = ['count', 'delta'];
|
|
|
|
|
|
|
|
for (const key of keyToCompare) {
|
|
|
|
expect(newUserStatistics.today[key]).toBe(originUserStatistics.today[key] + 1);
|
|
|
|
expect(newUserStatistics.last7Days[key]).toBe(originUserStatistics.last7Days[key] + 1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should get active user statistics successfully', async () => {
|
2022-07-27 21:30:37 -05:00
|
|
|
const originActiveUserStatistics = await getActiveUsersData();
|
2022-07-25 22:50:40 -05:00
|
|
|
|
2022-07-27 21:30:37 -05:00
|
|
|
const password = generatePassword();
|
|
|
|
const username = generateUsername();
|
|
|
|
await createUserByAdmin(username, password);
|
2022-07-25 22:50:40 -05:00
|
|
|
|
2022-11-10 03:37:12 -05:00
|
|
|
await signIn({ username, password });
|
2022-07-25 22:50:40 -05:00
|
|
|
|
2022-07-27 21:30:37 -05:00
|
|
|
const newActiveUserStatistics = await getActiveUsersData();
|
2022-07-25 22:50:40 -05:00
|
|
|
|
2022-07-27 21:30:37 -05:00
|
|
|
expect(newActiveUserStatistics.dauCurve.length).toBeGreaterThan(0);
|
2022-07-25 22:50:40 -05:00
|
|
|
|
|
|
|
const keyToCompare: Array<keyof StatisticsData> = ['count', 'delta'];
|
|
|
|
|
|
|
|
for (const key of keyToCompare) {
|
2022-07-27 21:30:37 -05:00
|
|
|
expect(newActiveUserStatistics.dau[key]).toBe(originActiveUserStatistics.dau[key] + 1);
|
|
|
|
expect(newActiveUserStatistics.wau[key]).toBe(originActiveUserStatistics.wau[key] + 1);
|
|
|
|
expect(newActiveUserStatistics.mau[key]).toBe(originActiveUserStatistics.mau[key] + 1);
|
2022-07-25 22:50:40 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|