-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rlc coverage cases for payload media type in cadl-ranch (#2265)
* add rlc payload media type * rege code and remove .only in test case * update test case
- Loading branch information
Showing
9 changed files
with
242 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
55 changes: 55 additions & 0 deletions
55
packages/typespec-ts/test/integration/generated/payload/media-type/src/clientDefinitions.ts
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,55 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { | ||
StringBodySendAsTextParameters, | ||
StringBodyGetAsTextParameters, | ||
StringBodySendAsJsonParameters, | ||
StringBodyGetAsJsonParameters, | ||
} from "./parameters.js"; | ||
import { | ||
StringBodySendAsText200Response, | ||
StringBodyGetAsText200Response, | ||
StringBodySendAsJson200Response, | ||
StringBodyGetAsJson200Response, | ||
} from "./responses.js"; | ||
import { Client, StreamableMethod } from "@azure-rest/core-client"; | ||
|
||
export interface SendAsText { | ||
post( | ||
options: StringBodySendAsTextParameters, | ||
): StreamableMethod<StringBodySendAsText200Response>; | ||
} | ||
|
||
export interface GetAsText { | ||
get( | ||
options?: StringBodyGetAsTextParameters, | ||
): StreamableMethod<StringBodyGetAsText200Response>; | ||
} | ||
|
||
export interface SendAsJson { | ||
post( | ||
options: StringBodySendAsJsonParameters, | ||
): StreamableMethod<StringBodySendAsJson200Response>; | ||
} | ||
|
||
export interface GetAsJson { | ||
get( | ||
options?: StringBodyGetAsJsonParameters, | ||
): StreamableMethod<StringBodyGetAsJson200Response>; | ||
} | ||
|
||
export interface Routes { | ||
/** Resource for '/payload/media-type/string-body/sendAsText' has methods for the following verbs: post */ | ||
(path: "/payload/media-type/string-body/sendAsText"): SendAsText; | ||
/** Resource for '/payload/media-type/string-body/getAsText' has methods for the following verbs: get */ | ||
(path: "/payload/media-type/string-body/getAsText"): GetAsText; | ||
/** Resource for '/payload/media-type/string-body/sendAsJson' has methods for the following verbs: post */ | ||
(path: "/payload/media-type/string-body/sendAsJson"): SendAsJson; | ||
/** Resource for '/payload/media-type/string-body/getAsJson' has methods for the following verbs: get */ | ||
(path: "/payload/media-type/string-body/getAsJson"): GetAsJson; | ||
} | ||
|
||
export type MediaTypeClient = Client & { | ||
path: Routes; | ||
}; |
11 changes: 11 additions & 0 deletions
11
packages/typespec-ts/test/integration/generated/payload/media-type/src/index.ts
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,11 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import MediaTypeClient from "./mediaTypeClient.js"; | ||
|
||
export * from "./mediaTypeClient.js"; | ||
export * from "./parameters.js"; | ||
export * from "./responses.js"; | ||
export * from "./clientDefinitions.js"; | ||
|
||
export default MediaTypeClient; |
5 changes: 5 additions & 0 deletions
5
packages/typespec-ts/test/integration/generated/payload/media-type/src/logger.ts
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 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { createClientLogger } from "@azure/logger"; | ||
export const logger = createClientLogger("payload-media-type"); |
36 changes: 36 additions & 0 deletions
36
packages/typespec-ts/test/integration/generated/payload/media-type/src/mediaTypeClient.ts
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,36 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { getClient, ClientOptions } from "@azure-rest/core-client"; | ||
import { logger } from "./logger.js"; | ||
import { MediaTypeClient } from "./clientDefinitions.js"; | ||
|
||
/** | ||
* Initialize a new instance of `MediaTypeClient` | ||
* @param options - the parameter for all optional parameters | ||
*/ | ||
export default function createClient( | ||
options: ClientOptions = {}, | ||
): MediaTypeClient { | ||
const endpointUrl = | ||
options.endpoint ?? options.baseUrl ?? `http://localhost:3000`; | ||
const userAgentInfo = `azsdk-js-payload-media-type-rest/1.0.0-beta.1`; | ||
const userAgentPrefix = | ||
options.userAgentOptions && options.userAgentOptions.userAgentPrefix | ||
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}` | ||
: `${userAgentInfo}`; | ||
options = { | ||
...options, | ||
userAgentOptions: { | ||
userAgentPrefix, | ||
}, | ||
loggingOptions: { | ||
logger: options.loggingOptions?.logger ?? logger.info, | ||
}, | ||
}; | ||
|
||
const client = getClient(endpointUrl, options) as MediaTypeClient; | ||
|
||
client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); | ||
return client; | ||
} |
32 changes: 32 additions & 0 deletions
32
packages/typespec-ts/test/integration/generated/payload/media-type/src/parameters.ts
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,32 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { RequestParameters } from "@azure-rest/core-client"; | ||
|
||
export interface StringBodySendAsTextBodyParam { | ||
body: string; | ||
} | ||
|
||
export interface StringBodySendAsTextMediaTypesParam { | ||
contentType: "text/plain"; | ||
} | ||
|
||
export type StringBodySendAsTextParameters = | ||
StringBodySendAsTextMediaTypesParam & | ||
StringBodySendAsTextBodyParam & | ||
RequestParameters; | ||
export type StringBodyGetAsTextParameters = RequestParameters; | ||
|
||
export interface StringBodySendAsJsonBodyParam { | ||
body: string; | ||
} | ||
|
||
export interface StringBodySendAsJsonMediaTypesParam { | ||
contentType: "application/json"; | ||
} | ||
|
||
export type StringBodySendAsJsonParameters = | ||
StringBodySendAsJsonMediaTypesParam & | ||
StringBodySendAsJsonBodyParam & | ||
RequestParameters; | ||
export type StringBodyGetAsJsonParameters = RequestParameters; |
26 changes: 26 additions & 0 deletions
26
packages/typespec-ts/test/integration/generated/payload/media-type/src/responses.ts
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,26 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { HttpResponse } from "@azure-rest/core-client"; | ||
|
||
/** The request has succeeded. */ | ||
export interface StringBodySendAsText200Response extends HttpResponse { | ||
status: "200"; | ||
} | ||
|
||
/** The request has succeeded. */ | ||
export interface StringBodyGetAsText200Response extends HttpResponse { | ||
status: "200"; | ||
body: string; | ||
} | ||
|
||
/** The request has succeeded. */ | ||
export interface StringBodySendAsJson200Response extends HttpResponse { | ||
status: "200"; | ||
} | ||
|
||
/** The request has succeeded. */ | ||
export interface StringBodyGetAsJson200Response extends HttpResponse { | ||
status: "200"; | ||
body: string; | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/typespec-ts/test/integration/generated/payload/media-type/tspconfig.yaml
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,13 @@ | ||
emit: | ||
- "@azure-tools/typespec-ts" | ||
options: | ||
"@azure-tools/typespec-ts": | ||
"emitter-output-dir": "{project-root}" | ||
generateMetadata: false | ||
generateTest: false | ||
addCredentials: false | ||
azureSdkForJs: false | ||
isTypeSpecTest: true | ||
enableOperationGroup: true | ||
packageDetails: | ||
name: "@msinternal/payload-media-type" |
60 changes: 60 additions & 0 deletions
60
packages/typespec-ts/test/integration/payloadMediaType.spec.ts
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,60 @@ | ||
import { assert } from "chai"; | ||
import MediaTypeClientFactory, { | ||
MediaTypeClient | ||
} from "./generated/payload/media-type/src/index.js"; | ||
|
||
describe("MediaType Client", () => { | ||
let client: MediaTypeClient; | ||
|
||
beforeEach(() => { | ||
client = MediaTypeClientFactory({ | ||
allowInsecureConnection: true | ||
}); | ||
}); | ||
|
||
it("should getAsText", async () => { | ||
try { | ||
const result = await client | ||
.path("/payload/media-type/string-body/getAsText") | ||
.get({ accept: "text/plain" }); | ||
assert.strictEqual(result.status, "200"); | ||
assert.strictEqual(result.body, "{cat}"); | ||
} catch (err) { | ||
assert.fail(err as string); | ||
} | ||
}); | ||
|
||
it("should sendAsText", async () => { | ||
try { | ||
const result = await client | ||
.path("/payload/media-type/string-body/sendAsText") | ||
.post({ body: "{cat}", contentType: "text/plain" }); | ||
assert.strictEqual(result.status, "200"); | ||
} catch (err) { | ||
assert.fail(err as string); | ||
} | ||
}); | ||
|
||
it("should sendAsJson", async () => { | ||
try { | ||
const result = await client | ||
.path("/payload/media-type/string-body/sendAsJson") | ||
.post({ body: "foo", contentType: "application/json" }); | ||
assert.strictEqual(result.status, "200"); | ||
} catch (err) { | ||
assert.fail(err as string); | ||
} | ||
}); | ||
|
||
it("should getAsJson", async () => { | ||
try { | ||
const result = await client | ||
.path("/payload/media-type/string-body/getAsJson") | ||
.get({ accept: "application/json" }); | ||
assert.strictEqual(result.status, "200"); | ||
assert.strictEqual(result.body, "foo"); | ||
} catch (err) { | ||
assert.fail(err as string); | ||
} | ||
}); | ||
}); |