|
1 | 1 | import { describe, test, expect, vi } from "vitest";
|
2 | 2 | import { setupDriverTest } from "../utils";
|
3 | 3 | import { ActorError } from "@/client/mod";
|
4 |
| -import { COUNTER_APP_PATH, type CounterApp } from "../test-apps"; |
| 4 | +import { |
| 5 | + COUNTER_APP_PATH, |
| 6 | + ACTION_INPUTS_APP_PATH, |
| 7 | + type CounterApp, |
| 8 | + type ActionInputsApp, |
| 9 | +} from "../test-apps"; |
5 | 10 | import { DriverTestConfig } from "../mod";
|
6 | 11 |
|
7 | 12 | export function runManagerDriverTests(driverTestConfig: DriverTestConfig) {
|
@@ -135,6 +140,96 @@ export function runManagerDriverTests(driverTestConfig: DriverTestConfig) {
|
135 | 140 | expect(count).toBe(10);
|
136 | 141 | });
|
137 | 142 |
|
| 143 | + test("passes input to actor during creation", async (c) => { |
| 144 | + const { client } = await setupDriverTest<ActionInputsApp>( |
| 145 | + c, |
| 146 | + driverTestConfig, |
| 147 | + ACTION_INPUTS_APP_PATH, |
| 148 | + ); |
| 149 | + |
| 150 | + // Test data to pass as input |
| 151 | + const testInput = { |
| 152 | + name: "test-actor", |
| 153 | + value: 42, |
| 154 | + nested: { foo: "bar" }, |
| 155 | + }; |
| 156 | + |
| 157 | + // Create actor with input |
| 158 | + const actor = await client.inputActor.create(undefined, { |
| 159 | + input: testInput, |
| 160 | + }); |
| 161 | + |
| 162 | + // Verify both createState and onCreate received the input |
| 163 | + const inputs = await actor.getInputs(); |
| 164 | + |
| 165 | + // Input should be available in createState |
| 166 | + expect(inputs.initialInput).toEqual(testInput); |
| 167 | + |
| 168 | + // Input should also be available in onCreate lifecycle hook |
| 169 | + expect(inputs.onCreateInput).toEqual(testInput); |
| 170 | + }); |
| 171 | + |
| 172 | + test("input is undefined when not provided", async (c) => { |
| 173 | + const { client } = await setupDriverTest<ActionInputsApp>( |
| 174 | + c, |
| 175 | + driverTestConfig, |
| 176 | + ACTION_INPUTS_APP_PATH, |
| 177 | + ); |
| 178 | + |
| 179 | + // Create actor without providing input |
| 180 | + const actor = await client.inputActor.create(); |
| 181 | + |
| 182 | + // Get inputs and verify they're undefined |
| 183 | + const inputs = await actor.getInputs(); |
| 184 | + |
| 185 | + // Should be undefined in createState |
| 186 | + expect(inputs.initialInput).toBeUndefined(); |
| 187 | + |
| 188 | + // Should be undefined in onCreate lifecycle hook too |
| 189 | + expect(inputs.onCreateInput).toBeUndefined(); |
| 190 | + }); |
| 191 | + |
| 192 | + test("getOrCreate passes input to actor during creation", async (c) => { |
| 193 | + const { client } = await setupDriverTest<ActionInputsApp>( |
| 194 | + c, |
| 195 | + driverTestConfig, |
| 196 | + ACTION_INPUTS_APP_PATH, |
| 197 | + ); |
| 198 | + |
| 199 | + // Create a unique key for this test |
| 200 | + const uniqueKey = [`input-test-${crypto.randomUUID()}`]; |
| 201 | + |
| 202 | + // Test data to pass as input |
| 203 | + const testInput = { |
| 204 | + name: "getorcreate-test", |
| 205 | + value: 100, |
| 206 | + nested: { baz: "qux" }, |
| 207 | + }; |
| 208 | + |
| 209 | + // Use getOrCreate with input |
| 210 | + const actor = client.inputActor.getOrCreate(uniqueKey, { |
| 211 | + createWithInput: testInput, |
| 212 | + }); |
| 213 | + |
| 214 | + // Verify both createState and onCreate received the input |
| 215 | + const inputs = await actor.getInputs(); |
| 216 | + |
| 217 | + // Input should be available in createState |
| 218 | + expect(inputs.initialInput).toEqual(testInput); |
| 219 | + |
| 220 | + // Input should also be available in onCreate lifecycle hook |
| 221 | + expect(inputs.onCreateInput).toEqual(testInput); |
| 222 | + |
| 223 | + // Verify that calling getOrCreate again with the same key |
| 224 | + // returns the existing actor and doesn't create a new one |
| 225 | + const existingActor = client.inputActor.getOrCreate(uniqueKey); |
| 226 | + const existingInputs = await existingActor.getInputs(); |
| 227 | + |
| 228 | + // Should still have the original inputs |
| 229 | + expect(existingInputs.initialInput).toEqual(testInput); |
| 230 | + expect(existingInputs.onCreateInput).toEqual(testInput); |
| 231 | + }); |
| 232 | + |
138 | 233 | // TODO: Correctly test region for each provider
|
139 | 234 | //test("creates and retrieves actors with region", async (c) => {
|
140 | 235 | // const { client } = await setupDriverTest<CounterApp>(c,
|
|
0 commit comments