Skip to content

Commit

Permalink
Supplement modular azure core basic test case (#2236)
Browse files Browse the repository at this point in the history
* Supplement test case

* test core-client-fix

* Update packages/typespec-ts/test/modularIntegration/azureCore.spec.ts

* update @azure-rest/core-client version to 1.2.0

* revert build client change

* Update packages/typespec-ts/test/modularIntegration/azureCore.spec.ts

* update @azure-rest/core-client version to 1.3.0

* fix ut

---------

Co-authored-by: qiaozha <qiaozha@microsoft.com>
Co-authored-by: Qiaoqiao Zhang <55688292+qiaozha@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 18, 2024
1 parent 3783e0b commit cbe71a7
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 12 deletions.
19 changes: 17 additions & 2 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/typespec-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@azure-tools/cadl-ranch-expect": "^0.13.2",
"@azure-tools/cadl-ranch": "^0.12.4",
"chalk": "^4.0.0",
"@azure-rest/core-client": "^1.2.0",
"@azure-rest/core-client": "^1.3.0",
"@azure/core-auth": "^1.6.0",
"cross-env": "^7.0.3",
"@azure/core-paging": "^1.5.0",
Expand Down Expand Up @@ -114,4 +114,4 @@
"url": "https://github.com/Azure/autorest.typescript/issues"
},
"homepage": "https://github.com/Azure/autorest.typescript/tree/main/packages/typespec-ts/"
}
}
10 changes: 8 additions & 2 deletions packages/typespec-ts/test/integration/extensibleEnums.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ describe("ExtensibleEnums Rest Client", () => {
const result = await client
.path("/type/enum/extensible/string/known-value")
.put({
body: JSON.stringify("Monday")
body: "Monday",
headers: {
"content-type": "text/plain"
}
});
assert.strictEqual(result.status, "204");
} catch (err) {
Expand All @@ -51,7 +54,10 @@ describe("ExtensibleEnums Rest Client", () => {
const result = await client
.path("/type/enum/extensible/string/unknown-value")
.put({
body: JSON.stringify("Weekend")
body: "Weekend",
headers: {
"content-type": "text/plain"
}
});
assert.strictEqual(result.status, "204");
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions packages/typespec-ts/test/integration/scalar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("Scalar Client", () => {
try {
const result = await client
.path("/type/scalar/string")
.put({ body: JSON.stringify("test") });
.put({ body: "test", headers: { "content-type": "text/plain" } });
assert.strictEqual(result.status, "204");
} catch (err) {
assert.fail(err as string);
Expand Down Expand Up @@ -71,7 +71,7 @@ describe("Scalar Client", () => {
try {
const result = await client
.path("/type/scalar/unknown")
.put({ body: JSON.stringify("test") });
.put({ body: "test", headers: { "content-type": "text/plain" } });
assert.strictEqual(result.status, "204");
} catch (err) {
assert.fail(err as string);
Expand Down
56 changes: 56 additions & 0 deletions packages/typespec-ts/test/modularIntegration/azureCore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,60 @@ describe("BasicClient Classical Client", () => {
assert.strictEqual(items.length, 1);
assert.strictEqual(items[0]?.name, "Madge");
});

it("should export a user", async () => {
try {
const user = await client.exportOperation(1, "json");
assert.strictEqual(user?.id, 1);
assert.strictEqual(user?.name, "Madge");
assert.strictEqual(user?.etag, "11bdc430-65e8-45ad-81d9-8ffa60d55b59");
} catch (err) {
assert.fail(err as string);
}
});

it("should create or replace a user", async () => {
try {
const user = await client.createOrReplace(
1,
{
name: "Madge",
id: 1,
etag: "11bdc430-65e8-45ad-81d9-8ffa60d55b59"
},
{
requestOptions: { headers: { "content-type": "application/json" } }
}
);
assert.strictEqual(user?.id, 1);
assert.strictEqual(user?.name, "Madge");
assert.strictEqual(user?.etag, "11bdc430-65e8-45ad-81d9-8ffa60d55b59");
} catch (err) {
assert.fail(err as string);
}
});

it("should create or update a user", async () => {
try {
const user = await client.createOrUpdate(1, {
name: "Madge",
id: 1,
etag: "11bdc430-65e8-45ad-81d9-8ffa60d55b59"
});
assert.strictEqual(user?.id, 1);
assert.strictEqual(user?.name, "Madge");
assert.strictEqual(user?.etag, "11bdc430-65e8-45ad-81d9-8ffa60d55b59");
} catch (err) {
assert.fail(err as string);
}
});

it("should delete a user", async () => {
try {
const user = await client.deleteOperation(1);
assert.isUndefined(user);
} catch (err) {
assert.fail(err as string);
}
});
});
32 changes: 28 additions & 4 deletions packages/typespec-ts/test/modularIntegration/scalar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ describe("Scalar Client", () => {

it("should get string value", async () => {
try {
const result = await client.string.get();
const result = await client.string.get({
requestOptions: {
headers: {
accept: "text/plain"
}
}
});
assert.strictEqual(result, "test");
} catch (err) {
assert.fail(err as string);
Expand All @@ -23,7 +29,13 @@ describe("Scalar Client", () => {

it("should put string value", async () => {
try {
const result = await client.string.put(JSON.stringify("test"));
const result = await client.string.put("test", {
requestOptions: {
headers: {
"content-type": "text/plain"
}
}
});
assert.isUndefined(result);
} catch (err) {
assert.fail(err as string);
Expand All @@ -50,7 +62,13 @@ describe("Scalar Client", () => {

it("should get unknown value", async () => {
try {
const result = await client.unknown.get();
const result = await client.unknown.get({
requestOptions: {
headers: {
accept: "text/plain"
}
}
});
assert.strictEqual(result, "test");
} catch (err) {
assert.fail(err as string);
Expand All @@ -59,7 +77,13 @@ describe("Scalar Client", () => {

it("should put unknown value", async () => {
try {
const result = await client.unknown.put(JSON.stringify("test"));
const result = await client.unknown.put("test", {
requestOptions: {
headers: {
"content-type": "text/plain"
}
}
});
assert.isUndefined(result);
} catch (err) {
assert.fail(err as string);
Expand Down

0 comments on commit cbe71a7

Please sign in to comment.