Skip to content

Commit

Permalink
add spector test for jsonl
Browse files Browse the repository at this point in the history
  • Loading branch information
tadelesh committed Mar 3, 2025
1 parent 737af9e commit aad4898
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/http-specs/spec-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -3537,6 +3537,18 @@ Verify that the name "with" works. Send this parameter to pass with value `ok`.

Verify that the name "yield" works. Send this parameter to pass with value `ok`.

### Streaming_Jsonl_Basic_receive

- Endpoint: `get /streaming/jsonl/basic/receive`

Basic case of jsonl streaming for response.

### Streaming_Jsonl_Basic_send

- Endpoint: `post /streaming/jsonl/basic/send`

Basic case of jsonl streaming for request.

### Type_Array_BooleanValue_get

- Endpoint: `get /type/array/boolean`
Expand Down
33 changes: 33 additions & 0 deletions packages/http-specs/specs/streaming/jsonl/main.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import "@typespec/http";
import "@typespec/http/streams";
import "@typespec/spector";

using TypeSpec.Http;
using TypeSpec.Http.Streams;
using Spector;

@doc("Test of jsonl streaming.")
@scenarioService("/streaming/jsonl")
namespace Streaming.Jsonl;

@route("basic")
namespace Basic {
@scenario
@scenarioDoc("""
Basic case of jsonl streaming for request.
""")
@route("send")
@post
op send(stream: JsonlStream<Info>): NoContentResponse;

@scenario
@scenarioDoc("""
Basic case of jsonl streaming for response.
""")
@route("receive")
op receive(): JsonlStream<Info>;

model Info {
desc: string;
}
}
39 changes: 39 additions & 0 deletions packages/http-specs/specs/streaming/jsonl/mockapi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { MockRequest, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};

Scenarios.Streaming_Jsonl_Basic_send = passOnSuccess({
uri: "/streaming/jsonl/send",
method: "post",
request: {
headers: {
"Content-Type": "application/jsonl",
},
body: '{"desc": "one"}\n{"desc": "two"}\n{"desc": "three"}',
},
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsHeader("content-type", "application/jsonl");
req.expect.rawBodyEquals('{"desc": "one"}\n{"desc": "two"}\n{"desc": "three"}');
return {
status: 204,
};
},
kind: "MockApiDefinition",
});

Scenarios.Streaming_Jsonl_Basic_receive = passOnSuccess({
uri: "/streaming/jsonl/receive",
method: "get",
request: {},
response: {
status: 200,
body: {
rawContent: '{"desc": "one"}\n{"desc": "two"}\n{"desc": "three"}',
contentType: "application/jsonl",
},
},
kind: "MockApiDefinition",
});

0 comments on commit aad4898

Please sign in to comment.