Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update DurableOrchestrationStatus to reference correct history data key from init argument #621

Open
wants to merge 3 commits into
base: v3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/orchestrations/DurableOrchestrationStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown>;
public readonly historyEvents?: Array<unknown>;

/** @hidden */
constructor(init: unknown) {
Expand All @@ -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 {
Expand All @@ -49,7 +49,7 @@ export class DurableOrchestrationStatus implements types.DurableOrchestrationSta
}
}

interface DurableOrchestrationStatusInit {
export interface DurableOrchestrationStatusInit {
name: string;
instanceId: string;
createdTime: string | Date;
Expand All @@ -58,5 +58,5 @@ interface DurableOrchestrationStatusInit {
output: unknown;
runtimeStatus: string;
customStatus?: unknown;
history?: Array<unknown>;
historyEvents?: Array<unknown>;
}
89 changes: 67 additions & 22 deletions test/unit/durableclient-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -194,39 +197,81 @@ 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,
output: null,
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");
});
});

Expand Down