diff --git a/src/orchestrations/DurableOrchestrationStatus.ts b/src/orchestrations/DurableOrchestrationStatus.ts index 6e407dce..031e132f 100644 --- a/src/orchestrations/DurableOrchestrationStatus.ts +++ b/src/orchestrations/DurableOrchestrationStatus.ts @@ -10,7 +10,7 @@ export class DurableOrchestrationStatus implements types.DurableOrchestrationSta public readonly output: unknown; public readonly runtimeStatus: OrchestrationRuntimeStatus; public readonly customStatus?: unknown; - public readonly history?: Array; + public readonly historyEvents?: Array; /** @hidden */ constructor(init: unknown) { @@ -30,7 +30,7 @@ export class DurableOrchestrationStatus implements types.DurableOrchestrationSta this.output = init.output; this.runtimeStatus = init.runtimeStatus as OrchestrationRuntimeStatus; this.customStatus = init.customStatus; - this.history = init.history; + this.historyEvents = init.historyEvents; } private isDurableOrchestrationStatusInit(obj: unknown): obj is DurableOrchestrationStatusInit { @@ -49,7 +49,7 @@ export class DurableOrchestrationStatus implements types.DurableOrchestrationSta } } -interface DurableOrchestrationStatusInit { +export interface DurableOrchestrationStatusInit { name: string; instanceId: string; createdTime: string | Date; @@ -58,5 +58,5 @@ interface DurableOrchestrationStatusInit { output: unknown; runtimeStatus: string; customStatus?: unknown; - history?: Array; + historyEvents?: Array; } diff --git a/test/unit/durableclient-spec.ts b/test/unit/durableclient-spec.ts index 7db2e845..513ba4cf 100644 --- a/test/unit/durableclient-spec.ts +++ b/test/unit/durableclient-spec.ts @@ -5,7 +5,10 @@ import nock = require("nock"); import url = require("url"); import { HttpManagementPayload } from "../../src/http/HttpManagementPayload"; import { OrchestrationRuntimeStatus } from "../../src/orchestrations/OrchestrationRuntimeStatus"; -import { DurableOrchestrationStatus } from "../../src/orchestrations/DurableOrchestrationStatus"; +import { + DurableOrchestrationStatus, + DurableOrchestrationStatusInit, +} from "../../src/orchestrations/DurableOrchestrationStatus"; import { EntityId } from "../../src/entities/EntityId"; import { EntityStateResponse } from "../../src/entities/EntityStateResponse"; import { OrchestrationClientInputData } from "../../src/durableClient/OrchestrationClientInputData"; @@ -194,22 +197,55 @@ describe("Durable client RPC endpoint", () => { expect(result).to.be.an("object"); }); - it("uses the RPC endpoint (with all query params)", async () => { - const input = JSON.parse(durableClientBindingInputJson) as OrchestrationClientInputData; - const client = new DurableClient(input); - - // The getStatus() method should do a GET to http://127.0.0.1:17071/durabletask/instances/abc123?showInput=true&showHistory=true&showHistoryOutput=true - const instanceId = "abc123"; - const expectedUrl = new URL(`${testRpcOrigin}/durabletask/instances/${instanceId}`); - - const scope = nock(expectedUrl.origin) - .get(expectedUrl.pathname) - .query({ - showInput: true, + describe("with query params", () => { + it("uses the RPC endpoint (with all query params)", async () => { + const input = JSON.parse( + durableClientBindingInputJson + ) as OrchestrationClientInputData; + const client = new DurableClient(input); + + // The getStatus() method should do a GET to http://127.0.0.1:17071/durabletask/instances/abc123?showInput=true&showHistory=true&showHistoryOutput=true + const instanceId = "abc123"; + const expectedUrl = new URL(`${testRpcOrigin}/durabletask/instances/${instanceId}`); + + const scope = nock(expectedUrl.origin) + .get(expectedUrl.pathname) + .query({ + showInput: true, + showHistory: true, + showHistoryOutput: true, + }) + .reply(202, { + name: "testOrchestration", + instanceId: "testInstanceId", + input: null, + output: null, + createdTime: "2020-01-01T05:00:00Z", + lastUpdatedTime: "2020-01-01T05:00:00Z", + runtimeStatus: "Pending", + historyEvents: [], + }); + + const result = await client.getStatus(instanceId, { showHistory: true, showHistoryOutput: true, - }) - .reply(202, { + showInput: true, + }); + expect(scope.isDone()).to.be.equal(true); + expect(result).to.be.an("object"); + }); + + it("should return 'historyEvents' property on response when query param 'showHistory' is true", async () => { + const input = JSON.parse( + durableClientBindingInputJson + ) as OrchestrationClientInputData; + const client = new DurableClient(input); + + // The getStatus() method should do a GET to http://127.0.0.1:17071/durabletask/instances/abc123?showInput=true&showHistory=true&showHistoryOutput=true + const instanceId = "abc123"; + const expectedUrl = new URL(`${testRpcOrigin}/durabletask/instances/${instanceId}`); + + const mockResponse: DurableOrchestrationStatusInit = { name: "testOrchestration", instanceId: "testInstanceId", input: null, @@ -217,16 +253,25 @@ describe("Durable client RPC endpoint", () => { createdTime: "2020-01-01T05:00:00Z", lastUpdatedTime: "2020-01-01T05:00:00Z", runtimeStatus: "Pending", - history: [], + historyEvents: [], + }; + + const scope = nock(expectedUrl.origin) + .get(expectedUrl.pathname) + .query({ showHistory: true }) + .reply(202, mockResponse); + + const result = await client.getStatus(instanceId, { + showHistory: true, }); - const result = await client.getStatus(instanceId, { - showHistory: true, - showHistoryOutput: true, - showInput: true, + expect(scope.isDone()).to.be.equal(true); + // historyEvents is undefined when showHistory query is not passed + expect( + Array.isArray(result.historyEvents), + "historyEvents to be an array" + ).to.equal(true); }); - expect(scope.isDone()).to.be.equal(true); - expect(result).to.be.an("object"); }); });