0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-23 20:33:16 -05:00
logto/packages/integration-tests/tests/api/dashboard.test.ts

62 lines
2.2 KiB
TypeScript
Raw Normal View History

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