|
| 1 | +import { PipelineAPI, ExecutionAPI, DuneClient } from "../../src"; |
| 2 | +import log from "loglevel"; |
| 3 | +import { QueryEngine } from "../../src/types/requestArgs"; |
| 4 | + |
| 5 | +log.setLevel("silent", true); |
| 6 | + |
| 7 | +const API_KEY = process.env.DUNE_API_KEY!; |
| 8 | + |
| 9 | +describe("PipelineAPI: pipeline execution and status", () => { |
| 10 | + let client: DuneClient; |
| 11 | + let pipelineAPI: PipelineAPI; |
| 12 | + let executionAPI: ExecutionAPI; |
| 13 | + let testQueryId: number; |
| 14 | + |
| 15 | + beforeAll(() => { |
| 16 | + client = new DuneClient(API_KEY); |
| 17 | + pipelineAPI = client.pipeline; |
| 18 | + executionAPI = client.exec; |
| 19 | + testQueryId = 6090403; |
| 20 | + }); |
| 21 | + |
| 22 | + beforeEach((done) => { |
| 23 | + setTimeout(done, 1000); |
| 24 | + }); |
| 25 | + |
| 26 | + it("executes a query pipeline successfully", async () => { |
| 27 | + const response = await executionAPI.executeQueryPipeline(testQueryId, { |
| 28 | + performance: QueryEngine.Medium, |
| 29 | + }); |
| 30 | + |
| 31 | + expect(response.pipeline_execution_id).toBeDefined(); |
| 32 | + expect(typeof response.pipeline_execution_id).toBe("string"); |
| 33 | + expect(response.pipeline_execution_id.length).toBeGreaterThan(0); |
| 34 | + }); |
| 35 | + |
| 36 | + it("executes query pipeline with default performance", async () => { |
| 37 | + const response = await executionAPI.executeQueryPipeline(testQueryId); |
| 38 | + |
| 39 | + expect(response.pipeline_execution_id).toBeDefined(); |
| 40 | + expect(typeof response.pipeline_execution_id).toBe("string"); |
| 41 | + }); |
| 42 | + |
| 43 | + it("gets pipeline status after execution", async () => { |
| 44 | + const executionResponse = await executionAPI.executeQueryPipeline(testQueryId, { |
| 45 | + performance: QueryEngine.Medium, |
| 46 | + }); |
| 47 | + |
| 48 | + const pipelineExecutionId = executionResponse.pipeline_execution_id; |
| 49 | + expect(pipelineExecutionId).toBeDefined(); |
| 50 | + |
| 51 | + const statusResponse = await pipelineAPI.getPipelineStatus(pipelineExecutionId); |
| 52 | + |
| 53 | + expect(statusResponse.status).toBeDefined(); |
| 54 | + expect(statusResponse.node_executions).toBeDefined(); |
| 55 | + expect(Array.isArray(statusResponse.node_executions)).toBe(true); |
| 56 | + expect(statusResponse.node_executions.length).toBeGreaterThan(0); |
| 57 | + |
| 58 | + const firstNode = statusResponse.node_executions[0]; |
| 59 | + expect(firstNode.id).toBeDefined(); |
| 60 | + expect(firstNode.query_execution_status).toBeDefined(); |
| 61 | + expect(firstNode.query_execution_status.status).toBeDefined(); |
| 62 | + expect(firstNode.query_execution_status.query_id).toBe(testQueryId); |
| 63 | + }); |
| 64 | + |
| 65 | + it("verifies pipeline status response structure", async () => { |
| 66 | + const executionResponse = await executionAPI.executeQueryPipeline(testQueryId); |
| 67 | + const pipelineExecutionId = executionResponse.pipeline_execution_id; |
| 68 | + |
| 69 | + const statusResponse = await pipelineAPI.getPipelineStatus(pipelineExecutionId); |
| 70 | + |
| 71 | + expect(statusResponse).toHaveProperty("status"); |
| 72 | + expect(statusResponse).toHaveProperty("node_executions"); |
| 73 | + expect(typeof statusResponse.status).toBe("string"); |
| 74 | + |
| 75 | + if (statusResponse.node_executions.length > 0) { |
| 76 | + const node = statusResponse.node_executions[0]; |
| 77 | + expect(node).toHaveProperty("id"); |
| 78 | + expect(node).toHaveProperty("query_execution_status"); |
| 79 | + expect(node.query_execution_status).toHaveProperty("status"); |
| 80 | + expect(node.query_execution_status).toHaveProperty("query_id"); |
| 81 | + } |
| 82 | + }); |
| 83 | +}); |
0 commit comments