Skip to content

Commit

Permalink
tests: add getDashboardWidgetReportData test
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuseduardomedeiros committed Dec 26, 2024
1 parent edf75cb commit 737a980
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/services/api/resources/__tests__/dashboard.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import http from '@/services/api/http';
import DashboardService from '../dashboards';
import { createRequestQuery } from '@/utils/request';

vi.mock('@/utils/filter', () => ({
isFilteringDates: vi.fn(() => false),
Expand Down Expand Up @@ -262,6 +263,51 @@ describe('DashboardService', () => {
});
});

describe('getDashboardWidgetReportData', () => {
it('should throw an error if dashboardUuid or widgetUuid is not provided', async () => {
await expect(
DashboardService.getDashboardWidgetReportData({
dashboardUuid: null,
widgetUuid: null,
}),
).rejects.toThrow(
'Please provide valids UUIDs parameters to request report data of widget.',
);
});

it('should call http.get with the correct URL and query parameters', () => {
const mockResponse = { data: 'mock-widget-report-data' };
http.get.mockResolvedValueOnce(mockResponse);

DashboardService.getDashboardWidgetReportData({
dashboardUuid: 'dashboard-uuid',
widgetUuid: 'widget-uuid',
slug: 'slug',
offset: 0,
limit: 5,
next: null,
});

const params = createRequestQuery(
{ status: 'open', priority: 'high' },
{
project: 'mock-project-uuid',
is_live: true,
slug: 'slug',
offset: 0,
limit: 5,
next: null,
},
);

expect(http.get).toHaveBeenCalled();
expect(http.get).toHaveBeenCalledWith(
'/dashboards/dashboard-uuid/widgets/widget-uuid/report/data/',
{ params },
);
});
});

describe('setDefaultDashboard', () => {
it('should call http.patch with the correct URL, body, and query parameters', async () => {
const mockResponse = { success: true };
Expand Down

0 comments on commit 737a980

Please sign in to comment.