-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
specs, add test for encode integer as string (#656)
- Loading branch information
1 parent
bdf1466
commit cdb4a5f
Showing
4 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@azure-tools/cadl-ranch-specs": patch | ||
--- | ||
|
||
Add test case for encode integer as string. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import "@typespec/http"; | ||
import "@azure-tools/cadl-ranch-expect"; | ||
import "@azure-tools/typespec-client-generator-core"; | ||
|
||
using TypeSpec.Http; | ||
using Azure.ClientGenerator.Core; | ||
|
||
@doc("Test for encode decorator on integer.") | ||
@supportedBy("dpg") | ||
@scenarioService("/encode/numeric") | ||
namespace Encode.Numeric; | ||
|
||
@operationGroup | ||
@route("/property") | ||
namespace Property { | ||
@route("/safeint") | ||
@scenario | ||
@scenarioDoc(""" | ||
Test operation with request and response model contains property of safeint type with string encode. | ||
Expected request body: | ||
```json | ||
{ | ||
"value": "10000000000" | ||
} | ||
``` | ||
Expected response body: | ||
```json | ||
{ | ||
"value": "10000000000" | ||
} | ||
``` | ||
""") | ||
@post | ||
op safeintAsString(@body body: SafeintAsStringProperty): SafeintAsStringProperty; | ||
|
||
model SafeintAsStringProperty { | ||
@encode(string) | ||
value: safeint; | ||
} | ||
|
||
@route("/uint32") | ||
@scenario | ||
@scenarioDoc(""" | ||
Test operation with request and response model contains property of uint32 type with string encode. | ||
Expected request body: | ||
```json | ||
{ | ||
"value": "1" | ||
} | ||
``` | ||
Expected response body: | ||
```json | ||
{ | ||
"value": "1" | ||
} | ||
``` | ||
""") | ||
@post | ||
op uint32AsStringOptional(@body body: Uint32AsStringProperty): Uint32AsStringProperty; | ||
|
||
model Uint32AsStringProperty { | ||
@encode(string) | ||
value?: uint32; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { passOnSuccess, mockapi, json, MockApi } from "@azure-tools/cadl-ranch-api"; | ||
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; | ||
|
||
export const Scenarios: Record<string, ScenarioMockApi> = {}; | ||
|
||
function createPropertyMockApis(route: string, value: string): MockApi { | ||
const url = `/encode/numeric/property/${route}`; | ||
return mockapi.post(url, (req) => { | ||
req.expect.coercedBodyEquals({ value: value }); | ||
return { | ||
status: 200, | ||
body: json({ value: value }), | ||
}; | ||
}); | ||
} | ||
|
||
Scenarios.Encode_Numeric_Property_safeintAsString = passOnSuccess(createPropertyMockApis("safeint", "10000000000")); | ||
|
||
Scenarios.Encode_Numeric_Property_uint32AsStringOptional = passOnSuccess(createPropertyMockApis("uint32", "1")); |