Skip to content

Commit 508e798

Browse files
test(voice): declare transport cases with effect each
1 parent 4c1e984 commit 508e798

1 file changed

Lines changed: 24 additions & 30 deletions

File tree

‎packages/client-runtime/src/voice-input/environment.test.ts‎

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,9 @@ const prepared = (
3030
wsBaseUrl: "ws://localhost",
3131
}),
3232
});
33-
for (const url of [
34-
"http://remote.example",
35-
"http://127.0.0.1.evil.example",
36-
"http://192.168.1.1",
37-
]) {
38-
it.effect(`does not send audio or credentials to ${url}`, () =>
33+
it.effect.each(["http://remote.example", "http://127.0.0.1.evil.example", "http://192.168.1.1"])(
34+
"does not send audio or credentials to %s",
35+
(url) =>
3936
Effect.gen(function* () {
4037
const fetch = vi.fn(async () => Response.json({ text: "hello" }));
4138
const result = yield* transcribeEnvironmentPcm(
@@ -52,34 +49,31 @@ for (const url of [
5249
});
5350
expect(fetch).not.toHaveBeenCalled();
5451
}),
55-
);
56-
}
57-
for (const url of [
52+
);
53+
it.effect.each([
5854
"https://remote.example",
5955
"http://localhost:3000",
6056
"http://127.0.0.1:3000",
6157
"http://[::1]:3000",
62-
]) {
63-
it.effect(`allows protected or loopback transport ${url}`, () =>
64-
Effect.gen(function* () {
65-
const fetch = vi.fn(async () => Response.json({ text: "hello" }));
66-
expect(
67-
yield* transcribeEnvironmentPcm(
68-
prepared(url),
69-
new Uint8Array(4),
70-
DEFAULT_SPEECH_TRANSCRIPTION_OPTIONS,
71-
).pipe(
72-
Effect.provide(FetchHttpClient.layer),
73-
Effect.provideService(FetchHttpClient.Fetch, fetch),
74-
),
75-
).toEqual({ text: "hello" });
76-
expect(fetch).toHaveBeenCalledWith(
77-
expect.anything(),
78-
expect.objectContaining({ redirect: "error", credentials: "include" }),
79-
);
80-
}),
81-
);
82-
}
58+
])("allows protected or loopback transport %s", (url) =>
59+
Effect.gen(function* () {
60+
const fetch = vi.fn(async () => Response.json({ text: "hello" }));
61+
expect(
62+
yield* transcribeEnvironmentPcm(
63+
prepared(url),
64+
new Uint8Array(4),
65+
DEFAULT_SPEECH_TRANSCRIPTION_OPTIONS,
66+
).pipe(
67+
Effect.provide(FetchHttpClient.layer),
68+
Effect.provideService(FetchHttpClient.Fetch, fetch),
69+
),
70+
).toEqual({ text: "hello" });
71+
expect(fetch).toHaveBeenCalledWith(
72+
expect.anything(),
73+
expect.objectContaining({ redirect: "error", credentials: "include" }),
74+
);
75+
}),
76+
);
8377

8478
it.effect("does not send browser cookies with bearer-authenticated voice requests", () =>
8579
Effect.gen(function* () {

0 commit comments

Comments
 (0)