-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add dashboard manager service tests
- Loading branch information
1 parent
e3a0c9f
commit 2f40708
Showing
1 changed file
with
162 additions
and
0 deletions.
There are no files selected for viewing
162 changes: 162 additions & 0 deletions
162
src/services/api/resources/dashboard/__tests__/dashboardManager.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; | ||
import http from '@/services/api/http'; | ||
import DashboardManagerApi from '../dashboardManager'; | ||
import { getProject } from '@/utils/config'; | ||
import { useProfile } from '@/store/modules/profile'; | ||
|
||
vi.mock('@/services/api/http'); | ||
vi.mock('@/utils/config'); | ||
vi.mock('@/store/modules/profile'); | ||
|
||
describe('DashboardManagerApi', () => { | ||
const params = { | ||
sector: '1', | ||
agent: 'agent', | ||
tag: 'tag', | ||
start_date: '2025-01-08', | ||
end_date: '2025-01-09', | ||
}; | ||
beforeEach(() => { | ||
getProject.mockReturnValue('project-uuid'); | ||
useProfile.mockReturnValue({ me: { email: '[email protected]' } }); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.resetAllMocks(); | ||
}); | ||
|
||
it('should return room info', async () => { | ||
http.get.mockReturnValue({ data: {} }); | ||
|
||
DashboardManagerApi.getRoomInfo( | ||
params.sector, | ||
params.agent, | ||
params.tag, | ||
params.start_date, | ||
params.end_date, | ||
); | ||
|
||
expect(http.get).toHaveBeenCalledWith('/dashboard/project-uuid/general/', { | ||
params, | ||
}); | ||
}); | ||
|
||
it('should return agent info', async () => { | ||
http.get.mockReturnValue({ data: {} }); | ||
|
||
DashboardManagerApi.getAgentInfo( | ||
params.sector, | ||
params.agent, | ||
params.tag, | ||
params.start_date, | ||
params.end_date, | ||
); | ||
|
||
expect(http.get).toHaveBeenCalledWith('dashboard/project-uuid/agent/', { | ||
params, | ||
}); | ||
}); | ||
|
||
it('should return sector info', async () => { | ||
http.get.mockReturnValue({ data: {} }); | ||
|
||
DashboardManagerApi.getSectorInfo( | ||
params.sector, | ||
params.agent, | ||
params.tag, | ||
params.start_date, | ||
params.end_date, | ||
); | ||
|
||
expect(http.get).toHaveBeenCalledWith('dashboard/project-uuid/division/', { | ||
params, | ||
}); | ||
}); | ||
|
||
it('should return raw info', async () => { | ||
http.get.mockReturnValue({ data: {} }); | ||
|
||
DashboardManagerApi.getRawInfo( | ||
params.sector, | ||
params.agent, | ||
params.tag, | ||
params.start_date, | ||
params.end_date, | ||
); | ||
|
||
expect(http.get).toHaveBeenCalledWith('dashboard/project-uuid/raw_data/', { | ||
params, | ||
}); | ||
}); | ||
|
||
it('should return viewed agent data', async () => { | ||
http.get.mockReturnValue({ data: {} }); | ||
|
||
DashboardManagerApi.getViewedAgentData('[email protected]'); | ||
|
||
expect(http.get).toHaveBeenCalledWith('/accounts/userdata/', { | ||
params: { user_email: '[email protected]' }, | ||
}); | ||
}); | ||
|
||
it('should download XLS data when option is "metrics_xls"', async () => { | ||
const mockResponse = { | ||
status: 200, | ||
data: { path_file: '/mock/path/to/file.xlsx' }, | ||
headers: { | ||
'content-type': | ||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', | ||
}, | ||
}; | ||
|
||
http.get.mockResolvedValueOnce(mockResponse); | ||
|
||
await DashboardManagerApi.downloadMetricData( | ||
params.sector, | ||
params.agent, | ||
params.tag, | ||
params.start_date, | ||
params.end_date, | ||
'metrics_xls', | ||
); | ||
|
||
expect(http.get).toHaveBeenCalledWith( | ||
'dashboard/project-uuid/export/?xls=on', | ||
{ | ||
params, | ||
}, | ||
); | ||
}); | ||
|
||
it('should download XLS data when option is "metrics_xls"', async () => { | ||
const mockResponse = { | ||
status: 200, | ||
data: { path_file: '/mock/path/to/file.xlsx' }, | ||
headers: { | ||
'content-type': | ||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', | ||
}, | ||
}; | ||
|
||
http.get.mockResolvedValueOnce(mockResponse); | ||
|
||
await DashboardManagerApi.downloadAllData( | ||
params.sector, | ||
params.agent, | ||
params.tag, | ||
params.start_date, | ||
params.end_date, | ||
'metrics_xls', | ||
); | ||
|
||
expect(http.get).toHaveBeenCalledWith( | ||
'dashboard/project-uuid/export_dashboard/', | ||
{ | ||
params: { | ||
...params, | ||
user_request: '[email protected]', | ||
}, | ||
}, | ||
); | ||
}); | ||
}); |