view data fixes
This commit is contained in:
@@ -1,59 +1,47 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import type { DashboardStatsResponseDto } from '../../types/generated/DashboardStatsResponseDTO';
|
||||
import type { AdminDashboardViewData } from '../../view-data/AdminDashboardViewData';
|
||||
import { AdminDashboardViewDataBuilder } from './AdminDashboardViewDataBuilder';
|
||||
import type { DashboardStatsResponseDTO } from '@/lib/types/generated/DashboardStatsResponseDTO';
|
||||
|
||||
describe('AdminDashboardViewDataBuilder', () => {
|
||||
describe('happy paths', () => {
|
||||
it('should transform DashboardStatsResponseDTO to AdminDashboardViewData correctly', () => {
|
||||
const dashboardStats: DashboardStatsResponseDTO = {
|
||||
totalUsers: 1000,
|
||||
activeUsers: 800,
|
||||
suspendedUsers: 50,
|
||||
deletedUsers: 150,
|
||||
systemAdmins: 5,
|
||||
recentLogins: 120,
|
||||
newUsersToday: 15,
|
||||
};
|
||||
it('should transform DashboardStatsResponseDto to AdminDashboardViewData correctly', () => {
|
||||
const apiDto: DashboardStatsResponseDto = {
|
||||
totalUsers: 1000,
|
||||
activeUsers: 800,
|
||||
suspendedUsers: 50,
|
||||
deletedUsers: 150,
|
||||
systemAdmins: 5,
|
||||
recentLogins: 200,
|
||||
newUsersToday: 10,
|
||||
};
|
||||
|
||||
const result = AdminDashboardViewDataBuilder.build(dashboardStats);
|
||||
const result: AdminDashboardViewData = AdminDashboardViewDataBuilder.build(apiDto);
|
||||
|
||||
expect(result).toEqual({
|
||||
stats: {
|
||||
totalUsers: 1000,
|
||||
activeUsers: 800,
|
||||
suspendedUsers: 50,
|
||||
deletedUsers: 150,
|
||||
systemAdmins: 5,
|
||||
recentLogins: 120,
|
||||
newUsersToday: 15,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle zero values correctly', () => {
|
||||
const dashboardStats: DashboardStatsResponseDTO = {
|
||||
totalUsers: 0,
|
||||
activeUsers: 0,
|
||||
suspendedUsers: 0,
|
||||
deletedUsers: 0,
|
||||
systemAdmins: 0,
|
||||
recentLogins: 0,
|
||||
newUsersToday: 0,
|
||||
};
|
||||
|
||||
const result = AdminDashboardViewDataBuilder.build(dashboardStats);
|
||||
|
||||
expect(result).toEqual({
|
||||
stats: {
|
||||
totalUsers: 0,
|
||||
activeUsers: 0,
|
||||
suspendedUsers: 0,
|
||||
deletedUsers: 0,
|
||||
systemAdmins: 0,
|
||||
recentLogins: 0,
|
||||
newUsersToday: 0,
|
||||
},
|
||||
});
|
||||
expect(result.stats).toEqual({
|
||||
totalUsers: 1000,
|
||||
activeUsers: 800,
|
||||
suspendedUsers: 50,
|
||||
deletedUsers: 150,
|
||||
systemAdmins: 5,
|
||||
recentLogins: 200,
|
||||
newUsersToday: 10,
|
||||
});
|
||||
});
|
||||
|
||||
it('should not modify the input DTO', () => {
|
||||
const apiDto: DashboardStatsResponseDto = {
|
||||
totalUsers: 1000,
|
||||
activeUsers: 800,
|
||||
suspendedUsers: 50,
|
||||
deletedUsers: 150,
|
||||
systemAdmins: 5,
|
||||
recentLogins: 200,
|
||||
newUsersToday: 10,
|
||||
};
|
||||
|
||||
const originalDto = { ...apiDto };
|
||||
AdminDashboardViewDataBuilder.build(apiDto);
|
||||
|
||||
expect(apiDto).toEqual(originalDto);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user