Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supplement test case #2666

Merged
merged 10 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/typespec-ts/test/commands/cadl-ranch-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,10 @@ export const modularTsps = [
{
outputPath: "type/model/flatten",
inputPath: "type/model/flatten"
},
{
outputPath: "type/model/visibility",
v-jiaodi marked this conversation as resolved.
Show resolved Hide resolved
inputPath: "type/model/visibility"
}
];

Expand Down
16 changes: 16 additions & 0 deletions packages/typespec-ts/test/integration/arrayItemTypes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ const testedTypes: TypeDetail[] = [
{
type: "nullable-float",
defaultValue: [1.25, null, 3.0]
},
{
type: "nullable-boolean",
defaultValue: [true, null, false]
},
{
type: "nullable-int32",
defaultValue: [1, null, 3]
},
{
type: "nullable-string",
defaultValue: ["hello", null, "world"]
},
{
type: "nullable-model",
defaultValue: [{ property: "hello" }, null, { property: "world" }]
}
];
describe("Array Item-Types Client", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const testedTypes: TypeDetail[] = [
{
type: "collections/model",
defaultValue: [{ property: "hello" }, { property: "world" }]
},
{
type: "collections/string",
defaultValue: ["hello", "world"]
}
];
describe("ModelsPropertyNullableClient Rest Client", () => {
Expand Down
72 changes: 72 additions & 0 deletions packages/typespec-ts/test/integration/modelVisibility.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import VisibilityClientFactory, {
VisibilityClient
} from "./generated/type/model/visibility/src/index.js";
import { assert } from "chai";
describe("Visibility Rest Client", () => {
let client: VisibilityClient;

beforeEach(() => {
client = VisibilityClientFactory({
allowInsecureConnection: true
});
});
function genData(keys: string[]): Record<string, any> {
const ret: Record<string, any> = {};
const fullData: Record<string, any> = {
readProp: "abc",
queryProp: 123,
createProp: ["foo", "bar"],
updateProp: [1, 2],
deleteProp: true
};
for (const k of keys) {
if (k in fullData) {
ret[k] = fullData[k];
}
}
return ret;
}

it("should query with head model", async () => {
const result = await client
.path("/type/model/visibility")
.head({ body: genData(["queryProp"]) as any });
assert.strictEqual(result.status, "200");
});

it("should get model visibility", async () => {
const result = await client
.path("/type/model/visibility")
.get({ body: genData(["queryProp"]) as any });
assert.strictEqual(result.status, "200");
assert.strictEqual(result.body.readProp, "abc");
});

it("should put model visibility", async () => {
const result = await client
.path("/type/model/visibility")
.put({ body: genData(["createProp", "updateProp"]) as any });
assert.strictEqual(result.status, "204");
});

it("should patch model visibility", async () => {
const result = await client
.path("/type/model/visibility")
.patch({ body: genData(["updateProp"]) as any });
assert.strictEqual(result.status, "204");
});

it("should post model visibility", async () => {
const result = await client
.path("/type/model/visibility")
.post({ body: genData(["createProp"]) as any });
assert.strictEqual(result.status, "204");
});

it("should delete model visibility", async () => {
const result = await client
.path("/type/model/visibility")
.delete({ body: genData(["deleteProp"]) as any });
assert.strictEqual(result.status, "204");
});
});
202 changes: 74 additions & 128 deletions packages/typespec-ts/test/integration/scalar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,172 +16,118 @@ describe("Scalar Client", () => {
});

it("should get string value", async () => {
try {
const result = await client.path("/type/scalar/string").get();
assert.strictEqual(result.status, "200");
assert.strictEqual(result.body, "test");
} catch (err) {
assert.fail(err as string);
}
const result = await client.path("/type/scalar/string").get();
assert.strictEqual(result.status, "200");
assert.strictEqual(result.body, "test");
});

it("should put string value", async () => {
try {
const result = await client
.path("/type/scalar/string")
.put({ body: "test", headers: { "content-type": "text/plain" } });
assert.strictEqual(result.status, "204");
} catch (err) {
assert.fail(err as string);
}
const result = await client
.path("/type/scalar/string")
.put({ body: "test", headers: { "content-type": "text/plain" } });
assert.strictEqual(result.status, "204");
});

it("should get boolean value", async () => {
try {
const result = await client.path("/type/scalar/boolean").get();
assert.strictEqual(result.status, "200");
assert.strictEqual(result.body, true);
} catch (err) {
assert.fail(err as string);
}
const result = await client.path("/type/scalar/boolean").get();
assert.strictEqual(result.status, "200");
assert.strictEqual(result.body, true);
});

it("should put boolean value", async () => {
try {
const result = await client
.path("/type/scalar/boolean")
.put({ body: true });
assert.strictEqual(result.status, "204");
} catch (err) {
assert.fail(err as string);
}
const result = await client
.path("/type/scalar/boolean")
.put({ body: true });
assert.strictEqual(result.status, "204");
});

it("should get unknown value", async () => {
try {
const result = await client.path("/type/scalar/unknown").get();
assert.strictEqual(result.status, "200");
assert.strictEqual(result.body, "test");
} catch (err) {
assert.fail(err as string);
}
const result = await client.path("/type/scalar/unknown").get();
assert.strictEqual(result.status, "200");
assert.strictEqual(result.body, "test");
});

it("should put unknown value", async () => {
try {
const result = await client
.path("/type/scalar/unknown")
.put({ body: "test", headers: { "content-type": "text/plain" } });
assert.strictEqual(result.status, "204");
} catch (err) {
assert.fail(err as string);
}
const result = await client
.path("/type/scalar/unknown")
.put({ body: "test", headers: { "content-type": "text/plain" } });
assert.strictEqual(result.status, "204");
});

it("should get decimal response body", async () => {
try {
const result = await client
.path("/type/scalar/decimal/response_body")
.get();
assert.strictEqual(result.status, "200");
assert.strictEqual(result.body, 0.33333);
} catch (err) {
assert.fail(err as string);
}
const result = await client
.path("/type/scalar/decimal/response_body")
.get();
assert.strictEqual(result.status, "200");
assert.strictEqual(result.body, 0.33333);
});

it("should put decimal request body", async () => {
try {
const result = await client
.path("/type/scalar/decimal/resquest_body")
.put({ body: 0.33333 });
assert.strictEqual(result.status, "204");
} catch (err) {
assert.fail(err as string);
}
const result = await client
.path("/type/scalar/decimal/resquest_body")
.put({ body: 0.33333 });
assert.strictEqual(result.status, "204");
});

it("should get decimal request parameter", async () => {
try {
const result = await client
.path("/type/scalar/decimal/request_parameter")
.get({ queryParameters: { value: 0.33333 } });
assert.strictEqual(result.status, "204");
} catch (err) {
assert.fail(err as string);
}
const result = await client
.path("/type/scalar/decimal/request_parameter")
.get({ queryParameters: { value: 0.33333 } });
assert.strictEqual(result.status, "204");
});

it("should get decimal128 response body", async () => {
try {
const result = await client
.path("/type/scalar/decimal128/response_body")
.get();
assert.strictEqual(result.status, "200");
assert.strictEqual(result.body, 0.33333);
} catch (err) {
assert.fail(err as string);
}
const result = await client
.path("/type/scalar/decimal128/response_body")
.get();
assert.strictEqual(result.status, "200");
assert.strictEqual(result.body, 0.33333);
});

it("should put decimal128 request body", async () => {
try {
const result = await client
.path("/type/scalar/decimal128/resquest_body")
.put({ body: 0.33333 });
assert.strictEqual(result.status, "204");
} catch (err) {
assert.fail(err as string);
}
const result = await client
.path("/type/scalar/decimal128/resquest_body")
.put({ body: 0.33333 });
assert.strictEqual(result.status, "204");
});

it("should get decimal128 request parameter", async () => {
try {
const result = await client
.path("/type/scalar/decimal128/request_parameter")
.get({ queryParameters: { value: 0.33333 } });
assert.strictEqual(result.status, "204");
} catch (err) {
assert.fail(err as string);
}
const result = await client
.path("/type/scalar/decimal128/request_parameter")
.get({ queryParameters: { value: 0.33333 } });
assert.strictEqual(result.status, "204");
});

it("should fail to post decimal verify", async () => {
try {
// prepare the verification
const getResult = await client
.path("/type/scalar/decimal/prepare_verify")
.get();
// do any calculation based on numbers
let total = 0;
getResult.body.forEach((decimal: number) => {
total += decimal;
});
const result = await client
.path("/type/scalar/decimal/verify")
.post({ body: total });
assert.strictEqual(result.status, "400");
} catch (err) {
assert.fail(err as string);
}
// prepare the verification
const getResult = await client
.path("/type/scalar/decimal/prepare_verify")
.get();
// do any calculation based on numbers
let total = 0;
getResult.body.forEach((decimal: number) => {
total += decimal;
});
total = Number(total.toFixed(1));
const result = await client
.path("/type/scalar/decimal/verify")
.post({ body: total });
assert.strictEqual(result.status, "204");
});

it("should fail to post decimal128 verify", async () => {
try {
const getResult = await client
.path("/type/scalar/decimal128/prepare_verify")
.get();
// do any calculation based on numbers
let total = 0;
getResult.body.forEach((decimal: number) => {
total += decimal;
});
const result = await client
.path("/type/scalar/decimal128/verify")
.post({ body: total });
assert.strictEqual(result.status, "400");
} catch (err) {
assert.fail(err as string);
}
const getResult = await client
.path("/type/scalar/decimal128/prepare_verify")
.get();
// do any calculation based on numbers
let total = 0;
getResult.body.forEach((decimal: number) => {
total += decimal;
});
total = Number(total.toFixed(1));
const result = await client
.path("/type/scalar/decimal128/verify")
.post({ body: total });
assert.strictEqual(result.status, "204");
});
});
Loading
Loading