2022-07-27 21:30:37 -05:00
|
|
|
import { getTotalUsersCount, getNewUsersData, getActiveUsersData, StatisticsData } from '@/api';
|
|
|
|
import { createUserByAdmin, registerNewUser, signIn } from '@/helpers';
|
|
|
|
import { generateUsername, generatePassword } from '@/utils';
|
2022-07-25 22:50:40 -05:00
|
|
|
|
|
|
|
describe('admin console dashboard', () => {
|
|
|
|
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-07-27 21:30:37 -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
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|