|
| 1 | +import { describe, it, expect, beforeAll, afterEach } from "vitest"; |
| 2 | +import { |
| 3 | + validateEnvironmentVariables, |
| 4 | + createTestClient, |
| 5 | + createTestContext, |
| 6 | + setActiveProjectAndOrg, |
| 7 | + cleanupResources, |
| 8 | + parseToolResponse, |
| 9 | + generateUniqueKey, |
| 10 | + TEST_PROJECT_ID, |
| 11 | + TEST_ORG_ID, |
| 12 | + type CreatedResources, |
| 13 | +} from "../shared/test-utils"; |
| 14 | +import createDashboardTool from "../../src/tools/dashboards/create"; |
| 15 | +import updateDashboardTool from "../../src/tools/dashboards/update"; |
| 16 | +import deleteDashboardTool from "../../src/tools/dashboards/delete"; |
| 17 | +import getAllDashboardsTool from "../../src/tools/dashboards/getAll"; |
| 18 | +import getDashboardTool from "../../src/tools/dashboards/get"; |
| 19 | +import type { Context } from "../../src/tools/types"; |
| 20 | + |
| 21 | +describe("Dashboards", { concurrent: false }, () => { |
| 22 | + let context: Context; |
| 23 | + const createdResources: CreatedResources = { |
| 24 | + featureFlags: [], |
| 25 | + insights: [], |
| 26 | + dashboards: [], |
| 27 | + }; |
| 28 | + |
| 29 | + beforeAll(async () => { |
| 30 | + validateEnvironmentVariables(); |
| 31 | + const client = createTestClient(); |
| 32 | + context = createTestContext(client); |
| 33 | + await setActiveProjectAndOrg(context, TEST_PROJECT_ID!, TEST_ORG_ID!); |
| 34 | + }); |
| 35 | + |
| 36 | + afterEach(async () => { |
| 37 | + await cleanupResources(context.api, TEST_PROJECT_ID!, createdResources); |
| 38 | + }); |
| 39 | + |
| 40 | + describe("create-dashboard tool", () => { |
| 41 | + const createTool = createDashboardTool(); |
| 42 | + |
| 43 | + it("should create a dashboard with minimal fields", async () => { |
| 44 | + const params = { |
| 45 | + data: { |
| 46 | + name: generateUniqueKey("Test Dashboard"), |
| 47 | + description: "Integration test dashboard", |
| 48 | + }, |
| 49 | + }; |
| 50 | + |
| 51 | + const result = await createTool.handler(context, params); |
| 52 | + const dashboardData = parseToolResponse(result); |
| 53 | + |
| 54 | + expect(dashboardData.id).toBeDefined(); |
| 55 | + expect(dashboardData.name).toBe(params.data.name); |
| 56 | + expect(dashboardData.url).toContain("/dashboard/"); |
| 57 | + |
| 58 | + createdResources.dashboards.push(dashboardData.id); |
| 59 | + }); |
| 60 | + |
| 61 | + it("should create a dashboard with tags", async () => { |
| 62 | + const params = { |
| 63 | + data: { |
| 64 | + name: generateUniqueKey("Tagged Dashboard"), |
| 65 | + description: "Dashboard with tags", |
| 66 | + tags: ["test", "integration"], |
| 67 | + }, |
| 68 | + }; |
| 69 | + |
| 70 | + const result = await createTool.handler(context, params); |
| 71 | + const dashboardData = parseToolResponse(result); |
| 72 | + |
| 73 | + expect(dashboardData.id).toBeDefined(); |
| 74 | + expect(dashboardData.name).toBe(params.data.name); |
| 75 | + |
| 76 | + createdResources.dashboards.push(dashboardData.id); |
| 77 | + }); |
| 78 | + }); |
| 79 | + |
| 80 | + describe("update-dashboard tool", () => { |
| 81 | + const createTool = createDashboardTool(); |
| 82 | + const updateTool = updateDashboardTool(); |
| 83 | + |
| 84 | + it("should update dashboard name and description", async () => { |
| 85 | + const createParams = { |
| 86 | + data: { |
| 87 | + name: generateUniqueKey("Original Dashboard"), |
| 88 | + description: "Original description", |
| 89 | + }, |
| 90 | + }; |
| 91 | + |
| 92 | + const createResult = await createTool.handler(context, createParams); |
| 93 | + const createdDashboard = parseToolResponse(createResult); |
| 94 | + createdResources.dashboards.push(createdDashboard.id); |
| 95 | + |
| 96 | + const updateParams = { |
| 97 | + dashboardId: createdDashboard.id, |
| 98 | + data: { |
| 99 | + name: "Updated Dashboard Name", |
| 100 | + description: "Updated description", |
| 101 | + }, |
| 102 | + }; |
| 103 | + |
| 104 | + const updateResult = await updateTool.handler(context, updateParams); |
| 105 | + const updatedDashboard = parseToolResponse(updateResult); |
| 106 | + |
| 107 | + expect(updatedDashboard.id).toBe(createdDashboard.id); |
| 108 | + expect(updatedDashboard.name).toBe(updateParams.data.name); |
| 109 | + }); |
| 110 | + }); |
| 111 | + |
| 112 | + describe("get-all-dashboards tool", () => { |
| 113 | + const getAllTool = getAllDashboardsTool(); |
| 114 | + |
| 115 | + it("should return dashboards with proper structure", async () => { |
| 116 | + const result = await getAllTool.handler(context, {}); |
| 117 | + const dashboards = parseToolResponse(result); |
| 118 | + |
| 119 | + expect(Array.isArray(dashboards)).toBe(true); |
| 120 | + if (dashboards.length > 0) { |
| 121 | + const dashboard = dashboards[0]; |
| 122 | + expect(dashboard).toHaveProperty("id"); |
| 123 | + expect(dashboard).toHaveProperty("name"); |
| 124 | + } |
| 125 | + }); |
| 126 | + }); |
| 127 | + |
| 128 | + describe("get-dashboard tool", () => { |
| 129 | + const createTool = createDashboardTool(); |
| 130 | + const getTool = getDashboardTool(); |
| 131 | + |
| 132 | + it("should get a specific dashboard by ID", async () => { |
| 133 | + const createParams = { |
| 134 | + data: { |
| 135 | + name: generateUniqueKey("Get Test Dashboard"), |
| 136 | + description: "Test dashboard for get operation", |
| 137 | + }, |
| 138 | + }; |
| 139 | + |
| 140 | + const createResult = await createTool.handler(context, createParams); |
| 141 | + const createdDashboard = parseToolResponse(createResult); |
| 142 | + createdResources.dashboards.push(createdDashboard.id); |
| 143 | + |
| 144 | + const result = await getTool.handler(context, { dashboardId: createdDashboard.id }); |
| 145 | + const retrievedDashboard = parseToolResponse(result); |
| 146 | + |
| 147 | + expect(retrievedDashboard.id).toBe(createdDashboard.id); |
| 148 | + expect(retrievedDashboard.name).toBe(createParams.data.name); |
| 149 | + }); |
| 150 | + }); |
| 151 | + |
| 152 | + describe("delete-dashboard tool", () => { |
| 153 | + const createTool = createDashboardTool(); |
| 154 | + const deleteTool = deleteDashboardTool(); |
| 155 | + |
| 156 | + it("should delete a dashboard", async () => { |
| 157 | + const createParams = { |
| 158 | + data: { |
| 159 | + name: generateUniqueKey("Delete Test Dashboard"), |
| 160 | + description: "Test dashboard for deletion", |
| 161 | + }, |
| 162 | + }; |
| 163 | + |
| 164 | + const createResult = await createTool.handler(context, createParams); |
| 165 | + const createdDashboard = parseToolResponse(createResult); |
| 166 | + |
| 167 | + const deleteResult = await deleteTool.handler(context, { |
| 168 | + dashboardId: createdDashboard.id, |
| 169 | + }); |
| 170 | + const deleteResponse = parseToolResponse(deleteResult); |
| 171 | + |
| 172 | + expect(deleteResponse.success).toBe(true); |
| 173 | + expect(deleteResponse.message).toContain("deleted successfully"); |
| 174 | + }); |
| 175 | + }); |
| 176 | + |
| 177 | + describe("Dashboard workflow", () => { |
| 178 | + it("should support full CRUD workflow", async () => { |
| 179 | + const createTool = createDashboardTool(); |
| 180 | + const updateTool = updateDashboardTool(); |
| 181 | + const getTool = getDashboardTool(); |
| 182 | + const deleteTool = deleteDashboardTool(); |
| 183 | + |
| 184 | + const createParams = { |
| 185 | + data: { |
| 186 | + name: generateUniqueKey("Workflow Test Dashboard"), |
| 187 | + description: "Testing full workflow", |
| 188 | + }, |
| 189 | + }; |
| 190 | + |
| 191 | + const createResult = await createTool.handler(context, createParams); |
| 192 | + const createdDashboard = parseToolResponse(createResult); |
| 193 | + |
| 194 | + const getResult = await getTool.handler(context, { dashboardId: createdDashboard.id }); |
| 195 | + const retrievedDashboard = parseToolResponse(getResult); |
| 196 | + expect(retrievedDashboard.id).toBe(createdDashboard.id); |
| 197 | + |
| 198 | + const updateParams = { |
| 199 | + dashboardId: createdDashboard.id, |
| 200 | + data: { |
| 201 | + name: "Updated Workflow Dashboard", |
| 202 | + description: "Updated workflow description", |
| 203 | + }, |
| 204 | + }; |
| 205 | + |
| 206 | + const updateResult = await updateTool.handler(context, updateParams); |
| 207 | + const updatedDashboard = parseToolResponse(updateResult); |
| 208 | + expect(updatedDashboard.name).toBe(updateParams.data.name); |
| 209 | + |
| 210 | + const deleteResult = await deleteTool.handler(context, { |
| 211 | + dashboardId: createdDashboard.id, |
| 212 | + }); |
| 213 | + const deleteResponse = parseToolResponse(deleteResult); |
| 214 | + expect(deleteResponse.success).toBe(true); |
| 215 | + }); |
| 216 | + }); |
| 217 | +}); |
0 commit comments