Skip to content

Commit a3293b4

Browse files
Consolidate clientDefaultValue tests into single file
- Merge body parameter test into clientDefaultValue.md - Remove separate bodyClientDefaultValue.md file - All parameter types (query, header, body) now tested in one file - All 451 modular + 309 RLC unit tests passing Co-authored-by: JialinHuang803 <139532647+JialinHuang803@users.noreply.github.com>
1 parent 745e753 commit a3293b4

File tree

2 files changed

+40
-73
lines changed

2 files changed

+40
-73
lines changed

packages/typespec-ts/test/modularUnit/scenarios/operations/bodyClientDefaultValue.md

Lines changed: 0 additions & 72 deletions
This file was deleted.

packages/typespec-ts/test/modularUnit/scenarios/operations/clientDefaultValue.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ interface Operations {
2929
@query
3030
limit?: int32
3131
): Configuration;
32+
33+
@post
34+
@route("/create")
35+
create(
36+
@body
37+
@Azure.ClientGenerator.Core.Legacy.clientDefaultValue("default-body")
38+
body?: string
39+
): string;
3240
}
3341
```
3442

@@ -46,14 +54,45 @@ The generated operation should apply default values for query and header paramet
4654
import { TestingContext as Client } from "./index.js";
4755
import { Configuration, configurationDeserializer } from "../models/models.js";
4856
import { expandUrlTemplate } from "../static-helpers/urlTemplate.js";
49-
import { TestQueryOptionalParams } from "./options.js";
57+
import { CreateOptionalParams, TestQueryOptionalParams } from "./options.js";
5058
import {
5159
StreamableMethod,
5260
PathUncheckedResponse,
5361
createRestError,
5462
operationOptionsToRequestParameters,
5563
} from "@azure-rest/core-client";
5664

65+
export function _createSend(
66+
context: Client,
67+
options: CreateOptionalParams = { requestOptions: {} },
68+
): StreamableMethod {
69+
return context
70+
.path("/api/create")
71+
.post({
72+
...operationOptionsToRequestParameters(options),
73+
contentType: "text/plain",
74+
headers: { accept: "text/plain", ...options.requestOptions?.headers },
75+
body: options["body"] ?? "default-body",
76+
});
77+
}
78+
79+
export async function _createDeserialize(result: PathUncheckedResponse): Promise<string> {
80+
const expectedStatuses = ["200"];
81+
if (!expectedStatuses.includes(result.status)) {
82+
throw createRestError(result);
83+
}
84+
85+
return result.body;
86+
}
87+
88+
export async function create(
89+
context: Client,
90+
options: CreateOptionalParams = { requestOptions: {} },
91+
): Promise<string> {
92+
const result = await _createSend(context, options);
93+
return _createDeserialize(result);
94+
}
95+
5796
export function _testQuerySend(
5897
context: Client,
5998
options: TestQueryOptionalParams = { requestOptions: {} },

0 commit comments

Comments
 (0)