Skip to content

Commit f373da9

Browse files
v-jiaodiMaryGao
andauthored
Add integration test cases for Client Location (#3330)
* upgrade tcgc and azure-http-specs * add case for azure generator core client lacation * revert * revert * revert * fix --------- Co-authored-by: Mary Gao <yanmeigao1210@gmail.com>
1 parent d055aed commit f373da9

10 files changed

Lines changed: 330 additions & 1 deletion

File tree

packages/typespec-ts/src/utils/clientUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export function getModularClientOptions(
8585
) {
8686
const [hierarchy, client] = clientMap;
8787
const clientOptions: ModularClientOptions = {
88-
rlcClientName: `${client.name.replace("Client", "")}Context`
88+
rlcClientName: `${client.name.replace(/Client$/, "")}Context`
8989
};
9090
clientOptions.subfolder = hierarchy.join("/");
9191
return clientOptions;
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { assert } from "chai";
2+
import ClientLocationClientFactory, {
3+
ClientLocationClient
4+
} from "./generated/azure/client-generator-core/client-location/src/index.js";
5+
6+
describe("Azure Client Generator Core Client Location", () => {
7+
let client: ClientLocationClient;
8+
9+
beforeEach(() => {
10+
client = ClientLocationClientFactory({
11+
allowInsecureConnection: true
12+
});
13+
});
14+
15+
describe("Move to Existing Sub Client", () => {
16+
it("should get user", async () => {
17+
const response = await client
18+
.path("/azure/client-generator-core/client-location/user")
19+
.get();
20+
21+
assert.strictEqual(response.status, "204");
22+
});
23+
24+
it("should delete user", async () => {
25+
const response = await client
26+
.path("/azure/client-generator-core/client-location/user")
27+
.delete();
28+
29+
assert.strictEqual(response.status, "204");
30+
});
31+
32+
it("should get admin info", async () => {
33+
const response = await client
34+
.path("/azure/client-generator-core/client-location/admin")
35+
.get();
36+
37+
assert.strictEqual(response.status, "204");
38+
});
39+
});
40+
41+
describe("Move to New Sub Client", () => {
42+
it("should list products", async () => {
43+
const response = await client
44+
.path("/azure/client-generator-core/client-location/products")
45+
.get();
46+
47+
assert.strictEqual(response.status, "204");
48+
});
49+
50+
it("should archive product", async () => {
51+
const response = await client
52+
.path("/azure/client-generator-core/client-location/products/archive")
53+
.post();
54+
55+
assert.strictEqual(response.status, "204");
56+
});
57+
});
58+
59+
describe("Move to Root Client", () => {
60+
it("should get resource", async () => {
61+
const response = await client
62+
.path("/azure/client-generator-core/client-location/resource")
63+
.get();
64+
65+
assert.strictEqual(response.status, "204");
66+
});
67+
68+
it("should get health status", async () => {
69+
const response = await client
70+
.path("/azure/client-generator-core/client-location/health")
71+
.get();
72+
73+
assert.strictEqual(response.status, "204");
74+
});
75+
});
76+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
!/src
3+
/src/**
4+
!/src/index.d.ts
5+
!/.gitignore
6+
!/tspconfig.yaml
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import type { Client } from '@azure-rest/core-client';
2+
import type { ClientOptions } from '@azure-rest/core-client';
3+
import type { HttpResponse } from '@azure-rest/core-client';
4+
import type { RequestParameters } from '@azure-rest/core-client';
5+
import type { StreamableMethod } from '@azure-rest/core-client';
6+
7+
export declare interface ArchiveProduct {
8+
post(options?: ArchiveProductParameters): StreamableMethod<ArchiveProduct204Response>;
9+
}
10+
11+
export declare interface ArchiveProduct204Response extends HttpResponse {
12+
status: "204";
13+
}
14+
15+
export declare type ArchiveProductParameters = RequestParameters;
16+
17+
export declare type ClientLocationClient = Client & {
18+
path: Routes;
19+
};
20+
21+
export declare interface ClientLocationClientOptions extends ClientOptions {
22+
}
23+
24+
declare function createClient(options?: ClientLocationClientOptions): ClientLocationClient;
25+
export default createClient;
26+
27+
export declare interface DeleteUser204Response extends HttpResponse {
28+
status: "204";
29+
}
30+
31+
export declare type DeleteUserParameters = RequestParameters;
32+
33+
export declare interface GetAdminInfo {
34+
get(options?: GetAdminInfoParameters): StreamableMethod<GetAdminInfo204Response>;
35+
}
36+
37+
export declare interface GetAdminInfo204Response extends HttpResponse {
38+
status: "204";
39+
}
40+
41+
export declare type GetAdminInfoParameters = RequestParameters;
42+
43+
export declare interface GetHealthStatus {
44+
get(options?: GetHealthStatusParameters): StreamableMethod<GetHealthStatus204Response>;
45+
}
46+
47+
export declare interface GetHealthStatus204Response extends HttpResponse {
48+
status: "204";
49+
}
50+
51+
export declare type GetHealthStatusParameters = RequestParameters;
52+
53+
export declare interface GetResource {
54+
get(options?: GetResourceParameters): StreamableMethod<GetResource204Response>;
55+
}
56+
57+
export declare interface GetResource204Response extends HttpResponse {
58+
status: "204";
59+
}
60+
61+
export declare type GetResourceParameters = RequestParameters;
62+
63+
export declare interface GetUser {
64+
get(options?: GetUserParameters): StreamableMethod<GetUser204Response>;
65+
delete(options?: DeleteUserParameters): StreamableMethod<DeleteUser204Response>;
66+
}
67+
68+
export declare interface GetUser204Response extends HttpResponse {
69+
status: "204";
70+
}
71+
72+
export declare type GetUserParameters = RequestParameters;
73+
74+
export declare interface ListProducts {
75+
get(options?: ListProductsParameters): StreamableMethod<ListProducts204Response>;
76+
}
77+
78+
export declare interface ListProducts204Response extends HttpResponse {
79+
status: "204";
80+
}
81+
82+
export declare type ListProductsParameters = RequestParameters;
83+
84+
export declare interface Routes {
85+
(path: "/azure/client-generator-core/client-location/admin"): GetAdminInfo;
86+
(path: "/azure/client-generator-core/client-location/user"): GetUser;
87+
(path: "/azure/client-generator-core/client-location/products"): ListProducts;
88+
(path: "/azure/client-generator-core/client-location/products/archive"): ArchiveProduct;
89+
(path: "/azure/client-generator-core/client-location/resource"): GetResource;
90+
(path: "/azure/client-generator-core/client-location/health"): GetHealthStatus;
91+
}
92+
93+
export { }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
emit:
2+
- "@azure-tools/typespec-ts"
3+
options:
4+
"@azure-tools/typespec-ts":
5+
emitter-output-dir: "{project-root}"
6+
add-credentials: false
7+
azure-sdk-for-js: false
8+
package-details:
9+
name: "@azure/client-generator-core-location"
10+
version: "1.0.0"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { ClientLocationClient } from "./generated/azure/client-generator-core/client-location/src/index.js";
2+
3+
describe("Azure ClientGeneratorCore Client Location", () => {
4+
let client: ClientLocationClient;
5+
6+
beforeEach(() => {
7+
client = new ClientLocationClient({
8+
endpoint: "http://localhost:3002",
9+
allowInsecureConnection: true
10+
});
11+
});
12+
13+
describe("Move to Existing Sub Client", () => {
14+
it("should get user via userOperations", async () => {
15+
await client.moveToExistingSubClient.userOperations.getUser();
16+
});
17+
18+
it("should delete user via adminOperations", async () => {
19+
await client.moveToExistingSubClient.adminOperations.deleteUser();
20+
});
21+
22+
it("should get admin info via adminOperations", async () => {
23+
await client.moveToExistingSubClient.adminOperations.getAdminInfo();
24+
});
25+
});
26+
27+
describe("Move to New Sub Client", () => {
28+
it("should list products via productOperations", async () => {
29+
await client.moveToNewSubClient.productOperations.listProducts();
30+
});
31+
32+
it("should archive product via archiveOperations", async () => {
33+
await client.archiveOperations.archiveProduct();
34+
});
35+
});
36+
37+
describe("Move to Root Client", () => {
38+
it("should get resource via resourceOperations", async () => {
39+
await client.moveToRootClient.resourceOperations.getResource();
40+
});
41+
42+
it("should get health status on root client", async () => {
43+
await client.getHealthStatus();
44+
});
45+
});
46+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
!/src
3+
/src/**
4+
!/src/index.d.ts
5+
!/.gitignore
6+
!/tspconfig.yaml
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { ClientOptions } from '@azure-rest/core-client';
2+
import { OperationOptions } from '@azure-rest/core-client';
3+
import { Pipeline } from '@azure/core-rest-pipeline';
4+
5+
export declare interface ArchiveOperationsArchiveProductOptionalParams extends OperationOptions {
6+
}
7+
8+
export declare interface ArchiveOperationsOperations {
9+
archiveProduct: (options?: ArchiveOperationsArchiveProductOptionalParams) => Promise<void>;
10+
}
11+
12+
export declare class ClientLocationClient {
13+
private _client;
14+
readonly pipeline: Pipeline;
15+
constructor(options?: ClientLocationClientOptionalParams);
16+
getHealthStatus(options?: GetHealthStatusOptionalParams): Promise<void>;
17+
readonly archiveOperations: ArchiveOperationsOperations;
18+
readonly moveToRootClient: MoveToRootClientOperations;
19+
readonly moveToNewSubClient: MoveToNewSubClientOperations;
20+
readonly moveToExistingSubClient: MoveToExistingSubClientOperations;
21+
}
22+
23+
export declare interface ClientLocationClientOptionalParams extends ClientOptions {
24+
}
25+
26+
export declare interface GetHealthStatusOptionalParams extends OperationOptions {
27+
}
28+
29+
export declare interface MoveToExistingSubClientAdminOperationsDeleteUserOptionalParams extends OperationOptions {
30+
}
31+
32+
export declare interface MoveToExistingSubClientAdminOperationsGetAdminInfoOptionalParams extends OperationOptions {
33+
}
34+
35+
export declare interface MoveToExistingSubClientAdminOperationsOperations {
36+
deleteUser: (options?: MoveToExistingSubClientAdminOperationsDeleteUserOptionalParams) => Promise<void>;
37+
getAdminInfo: (options?: MoveToExistingSubClientAdminOperationsGetAdminInfoOptionalParams) => Promise<void>;
38+
}
39+
40+
export declare interface MoveToExistingSubClientOperations {
41+
userOperations: MoveToExistingSubClientUserOperationsOperations;
42+
adminOperations: MoveToExistingSubClientAdminOperationsOperations;
43+
}
44+
45+
export declare interface MoveToExistingSubClientUserOperationsGetUserOptionalParams extends OperationOptions {
46+
}
47+
48+
export declare interface MoveToExistingSubClientUserOperationsOperations {
49+
getUser: (options?: MoveToExistingSubClientUserOperationsGetUserOptionalParams) => Promise<void>;
50+
}
51+
52+
export declare interface MoveToNewSubClientOperations {
53+
productOperations: MoveToNewSubClientProductOperationsOperations;
54+
}
55+
56+
export declare interface MoveToNewSubClientProductOperationsListProductsOptionalParams extends OperationOptions {
57+
}
58+
59+
export declare interface MoveToNewSubClientProductOperationsOperations {
60+
listProducts: (options?: MoveToNewSubClientProductOperationsListProductsOptionalParams) => Promise<void>;
61+
}
62+
63+
export declare interface MoveToRootClientOperations {
64+
resourceOperations: MoveToRootClientResourceOperationsOperations;
65+
}
66+
67+
export declare interface MoveToRootClientResourceOperationsGetResourceOptionalParams extends OperationOptions {
68+
}
69+
70+
export declare interface MoveToRootClientResourceOperationsOperations {
71+
getResource: (options?: MoveToRootClientResourceOperationsGetResourceOptionalParams) => Promise<void>;
72+
}
73+
74+
export { }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
emit:
2+
- "@azure-tools/typespec-ts"
3+
options:
4+
"@azure-tools/typespec-ts":
5+
emitter-output-dir: "{project-root}"
6+
add-credentials: false
7+
azure-sdk-for-js: false
8+
is-modular-library: true
9+
package-details:
10+
name: "@azure/client-generator-core-location"

packages/typespec-ts/test/commands/cadl-ranch-list.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ export const azureRlcTsps = [
327327
{
328328
outputPath: "azure/client-generator-core/deserialize-empty-string-as-null",
329329
inputPath: "azure/client-generator-core/deserialize-empty-string-as-null"
330+
},
331+
{
332+
outputPath: "azure/client-generator-core/client-location",
333+
inputPath: "azure/client-generator-core/client-location"
330334
}
331335
];
332336

@@ -847,6 +851,10 @@ export const azureModularTsps = [
847851
{
848852
outputPath: "azure/client-generator-core/deserialize-empty-string-as-null",
849853
inputPath: "azure/client-generator-core/deserialize-empty-string-as-null"
854+
},
855+
{
856+
outputPath: "azure/client-generator-core/client-location",
857+
inputPath: "azure/client-generator-core/client-location"
850858
}
851859
];
852860

0 commit comments

Comments
 (0)