Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
slinkydeveloper committed Dec 20, 2023
1 parent 4c0c467 commit 3b4bde0
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 46 deletions.
11 changes: 9 additions & 2 deletions test/awakeable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
outputMessage,
startMessage,
suspensionMessage,
END_MESSAGE,
} from "./protoutils";
import { TestGreeter, TestResponse } from "../src/generated/proto/test";
import { ProtocolMode } from "../src/generated/proto/discovery";
Expand Down Expand Up @@ -74,6 +75,7 @@ describe("AwakeableGreeter", () => {
expect(result).toStrictEqual([
awakeableMessage(),
outputMessage(greetResponse(`Hello Francesco for ${getAwakeableId(1)}`)),
END_MESSAGE,
]);
});

Expand All @@ -87,6 +89,7 @@ describe("AwakeableGreeter", () => {
expect(result).toStrictEqual([
awakeableMessage(),
outputMessage(greetResponse(`Hello for ${getAwakeableId(1)}`)),
END_MESSAGE,
]);
});

Expand All @@ -102,6 +105,7 @@ describe("AwakeableGreeter", () => {
outputMessage(
greetResponse(`Hello [object Object] for ${getAwakeableId(1)}`)
),
END_MESSAGE,
]);
});

Expand All @@ -117,9 +121,10 @@ describe("AwakeableGreeter", () => {
),
]).run();

expect(result.length).toStrictEqual(2);
expect(result.length).toStrictEqual(3);
expect(result[0]).toStrictEqual(awakeableMessage());
checkTerminalError(result[1], "Something went wrong");
expect(result[2]).toStrictEqual(END_MESSAGE);
});

it("handles replay with value", async () => {
Expand All @@ -131,6 +136,7 @@ describe("AwakeableGreeter", () => {

expect(result).toStrictEqual([
outputMessage(greetResponse(`Hello Francesco for ${getAwakeableId(1)}`)),
END_MESSAGE,
]);
});

Expand All @@ -141,8 +147,9 @@ describe("AwakeableGreeter", () => {
awakeableMessage(undefined, failure("Something went wrong")),
]).run();

expect(result.length).toStrictEqual(1);
expect(result.length).toStrictEqual(2);
checkTerminalError(result[0], "Something went wrong");
expect(result[1]).toStrictEqual(END_MESSAGE);
});

it("fails on journal mismatch. Completed with CompleteAwakeable during replay.", async () => {
Expand Down
14 changes: 12 additions & 2 deletions test/complete_awakeable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
outputMessage,
startMessage,
rejectAwakeableMessage,
END_MESSAGE,
} from "./protoutils";
import { describe, expect } from "@jest/globals";
import { TestDriver } from "./testdriver";
Expand Down Expand Up @@ -49,6 +50,7 @@ describe("ResolveAwakeableGreeter", () => {
expect(result).toStrictEqual([
resolveAwakeableMessage(getAwakeableId(1), "hello"),
outputMessage(greetResponse("Hello")),
END_MESSAGE,
]);
});

Expand All @@ -61,6 +63,7 @@ describe("ResolveAwakeableGreeter", () => {
expect(result).toStrictEqual([
resolveAwakeableMessage(getAwakeableId(1), ""),
outputMessage(greetResponse("Hello")),
END_MESSAGE,
]);
});

Expand All @@ -71,7 +74,10 @@ describe("ResolveAwakeableGreeter", () => {
resolveAwakeableMessage(getAwakeableId(1), "hello"),
]).run();

expect(result).toStrictEqual([outputMessage(greetResponse("Hello"))]);
expect(result).toStrictEqual([
outputMessage(greetResponse("Hello")),
END_MESSAGE,
]);
});

it("handles replay with value empty string", async () => {
Expand All @@ -81,7 +87,10 @@ describe("ResolveAwakeableGreeter", () => {
resolveAwakeableMessage(getAwakeableId(1), ""),
]).run();

expect(result).toStrictEqual([outputMessage(greetResponse("Hello"))]);
expect(result).toStrictEqual([
outputMessage(greetResponse("Hello")),
END_MESSAGE,
]);
});

it("fails on journal mismatch. Completed with invoke during replay.", async () => {
Expand Down Expand Up @@ -138,6 +147,7 @@ describe("RejectAwakeableGreeter", () => {
expect(result).toStrictEqual([
rejectAwakeableMessage(getAwakeableId(1), "my bad error"),
outputMessage(greetResponse("Hello")),
END_MESSAGE,
]);
});
});
15 changes: 14 additions & 1 deletion test/eager_state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { TestDriver } from "./testdriver";
import {
clearStateMessage,
completionMessage,
END_MESSAGE,
getStateMessage,
greetRequest,
greetResponse,
Expand Down Expand Up @@ -55,6 +56,7 @@ describe("GetEmpty", () => {
expect(result).toStrictEqual([
getStateMessage("STATE", undefined, true),
outputMessage(greetResponse("true")),
END_MESSAGE,
]);
});

Expand All @@ -78,7 +80,10 @@ describe("GetEmpty", () => {
ProtocolMode.BIDI_STREAM
).run();

expect(result).toStrictEqual([outputMessage(greetResponse("true"))]);
expect(result).toStrictEqual([
outputMessage(greetResponse("true")),
END_MESSAGE,
]);
});
});

Expand All @@ -103,6 +108,7 @@ describe("Get", () => {
expect(result).toStrictEqual([
getStateMessage("STATE", "One"),
outputMessage(greetResponse("One")),
END_MESSAGE,
]);
});

Expand All @@ -116,6 +122,7 @@ describe("Get", () => {
expect(result).toStrictEqual([
getStateMessage("STATE", "One"),
outputMessage(greetResponse("One")),
END_MESSAGE,
]);
});

Expand Down Expand Up @@ -158,6 +165,7 @@ describe("GetAppendAndGet", () => {
setStateMessage("STATE", "OneTwo"),
getStateMessage("STATE", "OneTwo"),
outputMessage(greetResponse("OneTwo")),
END_MESSAGE,
]);
});

Expand All @@ -173,6 +181,7 @@ describe("GetAppendAndGet", () => {
setStateMessage("STATE", "OneTwo"),
getStateMessage("STATE", "OneTwo"),
outputMessage(greetResponse("OneTwo")),
END_MESSAGE,
]);
});
});
Expand Down Expand Up @@ -202,6 +211,7 @@ describe("GetClearAndGet", () => {
clearStateMessage("STATE"),
getStateMessage("STATE", undefined, true),
outputMessage(greetResponse("One-nothing")),
END_MESSAGE,
]);
});

Expand All @@ -217,6 +227,7 @@ describe("GetClearAndGet", () => {
clearStateMessage("STATE"),
getStateMessage("STATE", undefined, true),
outputMessage(greetResponse("One-nothing")),
END_MESSAGE,
]);
});
});
Expand Down Expand Up @@ -249,6 +260,7 @@ describe("MultipleGet", () => {
getStateMessage("STATE", "One"),
getStateMessage("STATE", "One"),
outputMessage(greetResponse("One - One - One")),
END_MESSAGE,
]);
});

Expand All @@ -264,6 +276,7 @@ describe("MultipleGet", () => {
getStateMessage("STATE", "One"),
getStateMessage("STATE", "One"),
outputMessage(greetResponse("One - One - One")),
END_MESSAGE,
]);
});
});
11 changes: 10 additions & 1 deletion test/get_and_set_state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
checkJournalMismatchError,
clearStateMessage,
completionMessage,
END_MESSAGE,
getStateMessage,
greetRequest,
greetResponse,
Expand Down Expand Up @@ -57,6 +58,7 @@ describe("GetAndSetGreeter", () => {
getStateMessage("STATE"),
setStateMessage("STATE", "Till"),
outputMessage(greetResponse("Hello Pete")),
END_MESSAGE,
]);
});

Expand All @@ -83,6 +85,7 @@ describe("GetAndSetGreeter", () => {

expect(result).toStrictEqual([
outputMessage(greetResponse("Hello Francesco")),
END_MESSAGE,
]);
});

Expand Down Expand Up @@ -185,6 +188,7 @@ describe("ClearState", () => {
setStateMessage("STATE", "Till"),
clearStateMessage("STATE"),
outputMessage(greetResponse("Hello Francesco")),
END_MESSAGE,
]);
});

Expand All @@ -199,6 +203,7 @@ describe("ClearState", () => {

expect(result).toStrictEqual([
outputMessage(greetResponse("Hello Francesco")),
END_MESSAGE,
]);
});

Expand Down Expand Up @@ -272,7 +277,10 @@ describe("GetAndSetEnumGreeter", () => {
getStateMessage("STATE", OrderStatus.ORDERED),
]).run();

expect(result).toStrictEqual([outputMessage(greetResponse("Hello 1 - 0"))]);
expect(result).toStrictEqual([
outputMessage(greetResponse("Hello 1 - 0")),
END_MESSAGE,
]);
});

it("handles replays with value. First empty state, then enum state.", async () => {
Expand All @@ -286,6 +294,7 @@ describe("GetAndSetEnumGreeter", () => {

expect(result).toStrictEqual([
outputMessage(greetResponse("Hello null - 0")),
END_MESSAGE,
]);
});
});
Loading

0 comments on commit 3b4bde0

Please sign in to comment.