From 78d167e3f4da3fb35d7b2e1e0536efd2a9e29481 Mon Sep 17 00:00:00 2001 From: "Jiao Di (MSFT)" <80496810+v-jiaodi@users.noreply.github.com> Date: Fri, 15 Nov 2024 10:59:02 +0800 Subject: [PATCH] Uprade cadl ranch version to v0.16.1 (#2907) * uprade cadl ranch version to v0.16.1 * disable rlc versioning removed test case * update test case * remove try catch in test case --- common/config/rush/pnpm-lock.yaml | 122 +- packages/typespec-ts/package.json | 6 +- .../test/commands/cadl-ranch-list.js | 9 +- .../test/integration/arrayItemTypes.spec.ts | 40 +- .../test/integration/authApiKey.spec.ts | 31 +- .../test/integration/authCustomHttp.spec.ts | 40 +- .../test/integration/authOauth2.spec.ts | 27 +- .../test/integration/authUnion.spec.ts | 20 +- .../integration/azureArmResources.spec.ts | 4 +- .../azureClientGeneratorCoreAccess.spec.ts | 171 +- .../test/integration/azurecore.spec.ts | 134 +- .../test/integration/azurecorescalar.spec.ts | 74 +- .../test/integration/azurecoretraits.spec.ts | 62 +- .../test/integration/bodyParameters.spec.ts | 72 +- .../test/integration/clientNaming.spec.ts | 140 +- .../integration/clientRequestIdHeader.spec.ts | 58 +- .../test/integration/clientStructure.spec.ts | 72 +- .../test/integration/dictionary.spec.ts | 40 +- .../test/integration/emptyModel.spec.ts | 36 +- .../test/integration/encodeBytes.spec.ts | 380 ++-- .../test/integration/encodeDatetime.spec.ts | 368 ++-- .../test/integration/encodeDuration.spec.ts | 366 ++-- .../test/integration/extensibleEnums.spec.ts | 72 +- .../test/integration/fixedEnums.spec.ts | 50 +- .../test/integration/lroCore.spec.ts | 112 +- .../test/integration/lroRpc.spec.ts | 34 +- .../test/integration/modelInheritance.spec.ts | 112 +- .../modelInheritanceEnumDiscriminator.spec.ts | 124 +- .../modelInheritanceNotDiscriminated.spec.ts | 40 +- .../modelInheritanceRecursive.spec.ts | 24 +- ...odelInheritanceSingleDiscriminator.spec.ts | 98 +- .../modelPropertyAdditional.spec.ts | 1644 +++++++---------- .../integration/modelPropertyNullable.spec.ts | 90 +- .../integration/modelPropertyOptional.spec.ts | 968 ++++------ .../integration/modelPropertyType.spec.ts | 44 +- .../test/integration/modelUsage.spec.ts | 36 +- .../test/integration/payloadMediaType.spec.ts | 56 +- .../test/integration/payloadPageable.spec.ts | 102 +- .../integration/repeatableHeaders.spec.ts | 24 +- .../test/integration/scalar.spec.ts | 200 +- .../serializationEncodeNameJson.spec.ts | 30 +- .../test/integration/server.spec.ts | 120 +- .../serverEndpointNotDefined.spec.ts | 12 +- .../test/integration/specialWords.spec.ts | 1544 ++++++---------- .../test/integration/spreadParameters.spec.ts | 224 +-- .../test/integration/unionBody.spec.ts | 24 +- .../test/integration/unions.spec.ts | 330 ++-- .../integration/versioningRemoved.spec.ts | 50 +- .../modularIntegration/arrayItemTypes.spec.ts | 196 +- .../modularIntegration/authApiKey.spec.ts | 24 +- .../modularIntegration/authHttpCustom.spec.ts | 24 +- .../modularIntegration/authOauth2.spec.ts | 8 +- .../test/modularIntegration/authUnion.spec.ts | 40 +- .../azureArmResources.spec.ts | 4 +- .../azureClientGeneratorCoreAccess.spec.ts | 76 +- .../azureCoreTraits.spec.ts | 62 +- .../azurecorescalar.spec.ts | 44 +- .../basicParameters.spec.ts | 16 +- .../bodyOptionality.spec.ts | 32 +- .../modularIntegration/clientNaming.spec.ts | 108 +- .../clientStructureDefault.spec.ts | 72 +- .../clientStructureMultiClient.spec.ts | 48 +- .../clientStructureRenamed.spec.ts | 48 +- .../clientStructureTwoGroup.spec.ts | 48 +- .../collectionFormat.spec.ts | 56 +- .../customClientRequestId.spec.ts | 62 +- .../modularIntegration/encodeBytes.spec.ts | 290 ++- .../modularIntegration/encodeDatetime.spec.ts | 270 +-- .../modularIntegration/encodeDuration.spec.ts | 148 +- .../extensibleEnums.spec.ts | 40 +- .../modularIntegration/fixedEnums.spec.ts | 20 +- .../versioning/removed/src/index.d.ts | 13 +- .../headersRepeatability.spec.ts | 16 +- .../test/modularIntegration/lroRpc.spec.ts | 12 +- .../modularIntegration/lroStardard.spec.ts | 82 +- .../modelInheritanceEnumDiscriminator.spec.ts | 68 +- ...odelInheritanceNestedDiscriminator.spec.ts | 68 +- .../modelInheritanceNotDiscriminated.spec.ts | 24 +- .../modelInheritanceRecursive.spec.ts | 16 +- ...odelInheritanceSingleDiscriminator.spec.ts | 58 +- .../modelPropertyAdditional.spec.ts | 1215 +++++------- .../modelPropertyType.spec.ts | 488 +++-- .../modularIntegration/modelsEmpty.spec.ts | 28 +- .../payloadMediaType.spec.ts | 38 +- .../payloadPageable.spec.ts | 20 +- .../test/modularIntegration/scalar.spec.ts | 136 +- .../serializationEncodeNameJson.spec.ts | 16 +- .../test/modularIntegration/server.spec.ts | 96 +- .../serverEndpointNotDefined.spec.ts | 8 +- .../modularIntegration/specialWords.spec.ts | 1044 +++-------- .../spreadParameters.spec.ts | 140 +- .../test/modularIntegration/unions.spec.ts | 233 +-- .../test/modularIntegration/usage.spec.ts | 64 +- .../versioningRemoved.spec.ts | 42 +- 94 files changed, 5195 insertions(+), 8902 deletions(-) diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index fdf161c3e5..014d1e7a6a 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -231,10 +231,10 @@ importers: ../../packages/typespec-ts: specifiers: '@azure-rest/core-client': ^2.3.1 - '@azure-tools/cadl-ranch': ^0.15.0 + '@azure-tools/cadl-ranch': ^0.16.1 '@azure-tools/cadl-ranch-api': ^0.5.0 - '@azure-tools/cadl-ranch-expect': ^0.15.5 - '@azure-tools/cadl-ranch-specs': ^0.38.0 + '@azure-tools/cadl-ranch-expect': ^0.15.6 + '@azure-tools/cadl-ranch-specs': ^0.39.2 '@azure-tools/rlc-common': workspace:^0.34.0 '@azure-tools/typespec-autorest': '>=0.48.0 <1.0.0' '@azure-tools/typespec-azure-core': '>=0.48.0 <1.0.0' @@ -290,10 +290,10 @@ importers: tslib: 2.6.2 devDependencies: '@azure-rest/core-client': 2.3.1 - '@azure-tools/cadl-ranch': 0.15.0_maorf56vredk4k7ivyf3kw4p7i + '@azure-tools/cadl-ranch': 0.16.1_maorf56vredk4k7ivyf3kw4p7i '@azure-tools/cadl-ranch-api': 0.5.0 '@azure-tools/cadl-ranch-expect': 0.15.6_f5giq3reeireto67b6daw62k5y - '@azure-tools/cadl-ranch-specs': 0.38.0_uv4m3qq5ivkac27hpehot5vivy + '@azure-tools/cadl-ranch-specs': 0.39.2_fm5bpb4bfczzprftnu3bq22rpm '@azure-tools/typespec-autorest': 0.48.0_ox3wjptpcck6ih5jxiqdmkmsau '@azure-tools/typespec-azure-core': 0.48.0_aaegv3jydxpwng7gbukr25tg2m '@azure-tools/typespec-azure-resource-manager': 0.48.0_xptzwysxh7uiycxgwx225suwku @@ -442,7 +442,7 @@ packages: - supports-color dev: true - /@azure-tools/cadl-ranch-expect/0.15.6_3nr3pl3bbvepagmvirvhh4urmy: + /@azure-tools/cadl-ranch-expect/0.15.6_f5giq3reeireto67b6daw62k5y: resolution: {integrity: sha512-t601oyRwiSy/Nbbro5A7OHZSKsVGxGRJMPnd4X80dYetTBinUHXS2+cVx+fVQlUmb/4Ru/qNOvG0jtTJY9/XHw==} engines: {node: '>=16.0.0'} peerDependencies: @@ -451,40 +451,25 @@ packages: '@typespec/rest': ~0.62.0 '@typespec/versioning': ~0.62.0 dependencies: - '@typespec/compiler': 0.61.2 - '@typespec/http': 0.61.0_@typespec+compiler@0.61.2 - '@typespec/rest': 0.61.0_rd6g2np7ypwc24nhrvozahtdfy + '@typespec/compiler': 0.62.0 + '@typespec/http': 0.62.0_@typespec+compiler@0.62.0 + '@typespec/rest': 0.62.0_ehpjn7t5lr2snllrxt4bmumehe '@typespec/versioning': 0.62.0_@typespec+compiler@0.62.0 dev: true - /@azure-tools/cadl-ranch-expect/0.15.6_f5giq3reeireto67b6daw62k5y: - resolution: {integrity: sha512-t601oyRwiSy/Nbbro5A7OHZSKsVGxGRJMPnd4X80dYetTBinUHXS2+cVx+fVQlUmb/4Ru/qNOvG0jtTJY9/XHw==} + /@azure-tools/cadl-ranch-specs/0.39.2_fm5bpb4bfczzprftnu3bq22rpm: + resolution: {integrity: sha512-1Y0zMxND6El7QOH2CPCzs9tmq2XOngnZQ/4nsqKvMEa5HMz8ua7zNQGiNdCa+2eo/F1KbfWMXMeCWTSvJoTqSg==} engines: {node: '>=16.0.0'} peerDependencies: + '@azure-tools/cadl-ranch-expect': ~0.15.6 + '@azure-tools/typespec-azure-core': ~0.48.0 '@typespec/compiler': ~0.62.0 '@typespec/http': ~0.62.0 '@typespec/rest': ~0.62.0 '@typespec/versioning': ~0.62.0 + '@typespec/xml': ~0.62.0 dependencies: - '@typespec/compiler': 0.62.0 - '@typespec/http': 0.62.0_@typespec+compiler@0.62.0 - '@typespec/rest': 0.62.0_ehpjn7t5lr2snllrxt4bmumehe - '@typespec/versioning': 0.62.0_@typespec+compiler@0.62.0 - dev: true - - /@azure-tools/cadl-ranch-specs/0.38.0_uv4m3qq5ivkac27hpehot5vivy: - resolution: {integrity: sha512-AbOpERFpxYGmfFcSxDQl7ZeBy6FHEWFgqqw8FBRaugtVbeAj9BfUOPfc/OSEGNQmEIrzZJpH1N974JqhmKtKYg==} - engines: {node: '>=16.0.0'} - peerDependencies: - '@azure-tools/cadl-ranch-expect': ~0.15.5 - '@azure-tools/typespec-azure-core': ~0.47.0 - '@typespec/compiler': ~0.61.0 - '@typespec/http': ~0.61.0 - '@typespec/rest': ~0.61.0 - '@typespec/versioning': ~0.61.0 - '@typespec/xml': ~0.61.0 - dependencies: - '@azure-tools/cadl-ranch': 0.15.0_maorf56vredk4k7ivyf3kw4p7i + '@azure-tools/cadl-ranch': 0.16.1_maorf56vredk4k7ivyf3kw4p7i '@azure-tools/cadl-ranch-api': 0.5.0 '@azure-tools/cadl-ranch-expect': 0.15.6_f5giq3reeireto67b6daw62k5y '@azure-tools/typespec-azure-core': 0.48.0_aaegv3jydxpwng7gbukr25tg2m @@ -492,7 +477,7 @@ packages: '@typespec/http': 0.62.0_@typespec+compiler@0.62.0 '@typespec/rest': 0.62.0_ehpjn7t5lr2snllrxt4bmumehe '@typespec/versioning': 0.62.0_@typespec+compiler@0.62.0 - '@typespec/xml': 0.61.0_@typespec+compiler@0.62.0 + '@typespec/xml': 0.62.0_@typespec+compiler@0.62.0 transitivePeerDependencies: - '@types/express' - '@typespec/streams' @@ -500,19 +485,19 @@ packages: - supports-color dev: true - /@azure-tools/cadl-ranch/0.15.0_maorf56vredk4k7ivyf3kw4p7i: - resolution: {integrity: sha512-RU8AktXgCW7tuZF5yE2JCQdqY51qp5YJ8bvF82/M1tNwkN8GTxSXde3rBMyYnXJRd/DQUxaCqFMbwX1MgFBWFA==} + /@azure-tools/cadl-ranch/0.16.1_maorf56vredk4k7ivyf3kw4p7i: + resolution: {integrity: sha512-4tyd+2GDsZjkcsiB14T2m5imkPCokJkFLKrPe0mINb5Z6DVVzk/2BkhId//zk9KinpYL0ThG9ewM1ZeJ0jnoeg==} engines: {node: '>=16.0.0'} hasBin: true dependencies: '@azure-tools/cadl-ranch-api': 0.5.0 '@azure-tools/cadl-ranch-coverage-sdk': 0.9.0 - '@azure-tools/cadl-ranch-expect': 0.15.6_3nr3pl3bbvepagmvirvhh4urmy + '@azure-tools/cadl-ranch-expect': 0.15.6_f5giq3reeireto67b6daw62k5y '@azure/identity': 4.4.1 '@types/js-yaml': 4.0.6 - '@typespec/compiler': 0.61.2 - '@typespec/http': 0.61.0_@typespec+compiler@0.61.2 - '@typespec/rest': 0.61.0_rd6g2np7ypwc24nhrvozahtdfy + '@typespec/compiler': 0.62.0 + '@typespec/http': 0.62.0_@typespec+compiler@0.62.0 + '@typespec/rest': 0.62.0_ehpjn7t5lr2snllrxt4bmumehe ajv: 8.17.1 axios: 1.7.7 body-parser: 1.20.3 @@ -914,14 +899,6 @@ packages: - supports-color dev: true - /@babel/code-frame/7.24.7: - resolution: {integrity: sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==} - engines: {node: '>=6.9.0'} - dependencies: - '@babel/highlight': 7.25.9 - picocolors: 1.1.0 - dev: true - /@babel/code-frame/7.25.9: resolution: {integrity: sha512-z88xeGxnzehn2sqZ8UdGQEvYErF1odv2CftxInpSYJt6uHuPe9YjahKZITGs3l5LeI9d2ROG+obuDAoSlqbNfQ==} engines: {node: '>=6.9.0'} @@ -2425,27 +2402,6 @@ packages: eslint-visitor-keys: 3.4.3 dev: true - /@typespec/compiler/0.61.2: - resolution: {integrity: sha512-6QxYJd09VWssd/BvY+8eBxTVv085s1UNK63FdPrgT2lgI+j8VMMcpNR9m5l1zWlgGDM7sniA/Or8VCdVA6jerg==} - engines: {node: '>=18.0.0'} - hasBin: true - dependencies: - '@babel/code-frame': 7.24.7 - ajv: 8.17.1 - change-case: 5.4.4 - globby: 14.0.2 - mustache: 4.2.0 - picocolors: 1.1.0 - prettier: 3.3.3 - prompts: 2.4.2 - semver: 7.6.3 - temporal-polyfill: 0.2.5 - vscode-languageserver: 9.0.1 - vscode-languageserver-textdocument: 1.0.12 - yaml: 2.5.1 - yargs: 17.7.2 - dev: true - /@typespec/compiler/0.62.0: resolution: {integrity: sha512-RfKJ/rF2Wjxu7dl74oJE8yEfSkeL7NopFlyJ4dW1JQXpRN2IOJYPxas12qZA6H9ZEIB8rBjyrHNxJSQbvn/UDQ==} engines: {node: '>=18.0.0'} @@ -2466,19 +2422,6 @@ packages: yaml: 2.5.1 yargs: 17.7.2 - /@typespec/http/0.61.0_@typespec+compiler@0.61.2: - resolution: {integrity: sha512-7+AYHkzkc+p652GY9BcEbXY4OZa1fTr03MVmZeafvmbQbXfyzUU9eJld13M3v6NaUWqXWZ7nBNMISyKiXp/kSw==} - engines: {node: '>=18.0.0'} - peerDependencies: - '@typespec/compiler': ~0.61.0 - '@typespec/streams': ~0.61.0 - peerDependenciesMeta: - '@typespec/streams': - optional: true - dependencies: - '@typespec/compiler': 0.61.2 - dev: true - /@typespec/http/0.62.0_@typespec+compiler@0.62.0: resolution: {integrity: sha512-6H9y9e32lb2s76MMy29ITCwSZNG42sa/qWthiByUvfbTEXMpu5a1fQHNj7RXg+xmDKmVIHv3gAfjGPAWfXhkaQ==} engines: {node: '>=18.0.0'} @@ -2525,17 +2468,6 @@ packages: - openapi-types dev: false - /@typespec/rest/0.61.0_rd6g2np7ypwc24nhrvozahtdfy: - resolution: {integrity: sha512-L9Oyor+l42p6S8GE+UvaZTi+dcu6WubGZKmaBRpX8mCZGsa69EgIK8DQoyxrfMcxAO4I5U0sfkzCKwCVFtRr9g==} - engines: {node: '>=18.0.0'} - peerDependencies: - '@typespec/compiler': ~0.61.0 - '@typespec/http': ~0.61.0 - dependencies: - '@typespec/compiler': 0.61.2 - '@typespec/http': 0.61.0_@typespec+compiler@0.61.2 - dev: true - /@typespec/rest/0.62.0_ehpjn7t5lr2snllrxt4bmumehe: resolution: {integrity: sha512-ci5UjelEKFwsPTdpgysoUoDCcw02EnbG4GBuYJdR5mRrFCBZMxrbro+OJLgSN3g/TORSsWlW7dEOWLfbyrmlZQ==} engines: {node: '>=18.0.0'} @@ -2565,11 +2497,11 @@ packages: dependencies: '@typespec/compiler': 0.62.0 - /@typespec/xml/0.61.0_@typespec+compiler@0.62.0: - resolution: {integrity: sha512-LnMYyzB7f6C8rBZmQwhKyJOJ8mUTFls6aVKXw4EAaO2+HPsm73GN16lj1bt2ffbWR3izCGnz911K2wGtUrtSpA==} + /@typespec/xml/0.62.0_@typespec+compiler@0.62.0: + resolution: {integrity: sha512-DexGTQHB75fncDcYfs5CIbNwO6NOhjwCaaNoHYAsVVzs4T8qwzw6WQdEEMzZRbgsxwnllFkxKwGhLtRMQdv/cQ==} engines: {node: '>=18.0.0'} peerDependencies: - '@typespec/compiler': ~0.61.0 + '@typespec/compiler': ~0.62.0 dependencies: '@typespec/compiler': 0.62.0 dev: true @@ -5498,8 +5430,8 @@ packages: /is-weakset/2.0.2: resolution: {integrity: sha512-t2yVvttHkQktwnNNmBQ98AhENLdPUTDTE21uPqAQ0ARwQfGeQKRVS0NNurH7bTf7RrvcVn1OOge45CnBeHCSmg==} dependencies: - call-bind: 1.0.2 - get-intrinsic: 1.2.1 + call-bind: 1.0.7 + get-intrinsic: 1.2.4 dev: true /is-wsl/2.2.0: diff --git a/packages/typespec-ts/package.json b/packages/typespec-ts/package.json index 7d83b05512..a22e8702b9 100644 --- a/packages/typespec-ts/package.json +++ b/packages/typespec-ts/package.json @@ -63,9 +63,9 @@ "license": "MIT", "devDependencies": { "@azure-rest/core-client": "^2.3.1", - "@azure-tools/cadl-ranch-expect": "^0.15.5", - "@azure-tools/cadl-ranch-specs": "^0.38.0", - "@azure-tools/cadl-ranch": "^0.15.0", + "@azure-tools/cadl-ranch-expect": "^0.15.6", + "@azure-tools/cadl-ranch-specs": "^0.39.2", + "@azure-tools/cadl-ranch": "^0.16.1", "@azure-tools/cadl-ranch-api": "^0.5.0", "@azure-tools/typespec-autorest": ">=0.48.0 <1.0.0", "@azure-tools/typespec-azure-core": ">=0.48.0 <1.0.0", diff --git a/packages/typespec-ts/test/commands/cadl-ranch-list.js b/packages/typespec-ts/test/commands/cadl-ranch-list.js index 814855a6a7..1664efa44c 100644 --- a/packages/typespec-ts/test/commands/cadl-ranch-list.js +++ b/packages/typespec-ts/test/commands/cadl-ranch-list.js @@ -251,10 +251,11 @@ export const rlcTsps = [ outputPath: "versioning/madeOptional", inputPath: "versioning/madeOptional" }, - { - outputPath: "versioning/removed", - inputPath: "versioning/removed" - }, + // disable it as https://github.com/Azure/autorest.typescript/issues/2902 + // { + // outputPath: "versioning/removed", + // inputPath: "versioning/removed" + // }, { outputPath: "versioning/renamedFrom", inputPath: "versioning/renamedFrom" diff --git a/packages/typespec-ts/test/integration/arrayItemTypes.spec.ts b/packages/typespec-ts/test/integration/arrayItemTypes.spec.ts index 1cf2ac95cf..780418596e 100644 --- a/packages/typespec-ts/test/integration/arrayItemTypes.spec.ts +++ b/packages/typespec-ts/test/integration/arrayItemTypes.spec.ts @@ -79,34 +79,26 @@ describe("Array Item-Types Client", () => { matrix([testedTypes], async (params: TypeDetail) => { it(`should get a ${params.type} value`, async () => { - try { - const result = await client - .path(`/type/array/${params.type}` as any) - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, params.defaultValue); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/type/array/${params.type}` as any) + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, params.defaultValue); }); it(`should put a ${params.type} value`, async () => { - try { - let property; - if (params.convertedToFn) { - property = params.convertedToFn(params.defaultValue); - } else { - property = params.defaultValue; - } - const result = await client - .path(`/type/array/${params.type}` as any) - .put({ - body: property - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); + let property; + if (params.convertedToFn) { + property = params.convertedToFn(params.defaultValue); + } else { + property = params.defaultValue; } + const result = await client + .path(`/type/array/${params.type}` as any) + .put({ + body: property + }); + assert.strictEqual(result.status, "204"); }); }); }); diff --git a/packages/typespec-ts/test/integration/authApiKey.spec.ts b/packages/typespec-ts/test/integration/authApiKey.spec.ts index ec76a71647..2935664a15 100644 --- a/packages/typespec-ts/test/integration/authApiKey.spec.ts +++ b/packages/typespec-ts/test/integration/authApiKey.spec.ts @@ -3,35 +3,34 @@ import ApiKeyClientFactory, { } from "./generated/authentication/api-key/src/index.js"; import { assert } from "chai"; describe("AuthApiKeyClient Rest Client", () => { - let client: AuthApiKeyClient; + let validKeyClient: AuthApiKeyClient; + let invalidKeyClient: AuthApiKeyClient; beforeEach(() => { - client = ApiKeyClientFactory( + validKeyClient = ApiKeyClientFactory( { key: "valid-key" }, { allowInsecureConnection: true } ); + invalidKeyClient = ApiKeyClientFactory( + { + key: "invalid-key" + }, + { allowInsecureConnection: true } + ); }); it("should return 204 when the apiKey is valid", async () => { - try { - const result = await client.path("/authentication/api-key/valid").get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await validKeyClient.path("/authentication/api-key/valid").get(); + assert.strictEqual(result.status, "204"); }); it("should return 403 when the apiKey is invalid", async () => { - try { - const result = await client.path("/authentication/api-key/invalid").get(); - assert.strictEqual(result.status, "403"); - if (result.status === "403") { - assert.strictEqual(result.body.error, "invalid-api-key"); - } - } catch (err) { - assert.fail(err as string); + const result = await invalidKeyClient.path("/authentication/api-key/invalid").get(); + assert.strictEqual(result.status, "403"); + if (result.status === "403") { + assert.strictEqual(result.body.error, "invalid-api-key"); } }); }); diff --git a/packages/typespec-ts/test/integration/authCustomHttp.spec.ts b/packages/typespec-ts/test/integration/authCustomHttp.spec.ts index 239c5b0fe9..2ec1be69d1 100644 --- a/packages/typespec-ts/test/integration/authCustomHttp.spec.ts +++ b/packages/typespec-ts/test/integration/authCustomHttp.spec.ts @@ -3,40 +3,38 @@ import AuthHttpCustomClientFactory, { } from "./generated/authentication/http/custom/src/index.js"; import { assert } from "chai"; describe("AuthHttpCustomClient Rest Client", () => { - let client: AuthHttpCustomClient; + let validKeyClient: AuthHttpCustomClient; + let invalidKeyClient: AuthHttpCustomClient; beforeEach(() => { - client = AuthHttpCustomClientFactory( + validKeyClient = AuthHttpCustomClientFactory( { key: "valid-key" }, { allowInsecureConnection: true } ); + invalidKeyClient = AuthHttpCustomClientFactory( + { + key: "invalid-key" + }, + { allowInsecureConnection: true } + ); }); it("should return 204 when the apiKey is valid", async () => { - try { - const result = await client - .path("/authentication/http/custom/valid") - .get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - console.log(err); - assert.fail(err as string); - } + const result = await validKeyClient + .path("/authentication/http/custom/valid") + .get(); + assert.strictEqual(result.status, "204"); }); it("should return 403 when the apiKey is invalid", async () => { - try { - const result = await client - .path("/authentication/http/custom/invalid") - .get(); - assert.strictEqual(result.status, "403"); - if (result.status === "403") { - assert.strictEqual(result.body.error, "invalid-api-key"); - } - } catch (err) { - assert.fail(err as string); + const result = await invalidKeyClient + .path("/authentication/http/custom/invalid") + .get(); + assert.strictEqual(result.status, "403"); + if (result.status === "403") { + assert.strictEqual(result.body.error, "invalid-api-key"); } }); }); diff --git a/packages/typespec-ts/test/integration/authOauth2.spec.ts b/packages/typespec-ts/test/integration/authOauth2.spec.ts index 88c3bf4025..276d04ed66 100644 --- a/packages/typespec-ts/test/integration/authOauth2.spec.ts +++ b/packages/typespec-ts/test/integration/authOauth2.spec.ts @@ -38,26 +38,19 @@ describe("AuthOauth2Client Rest Client", () => { }); it("should return 204 when the token is valid", async () => { - try { - const result = await client.path("/authentication/oauth2/valid").get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/authentication/oauth2/valid").get(); + assert.strictEqual(result.status, "204"); + }); it("should return 403 when the token is invalid", async () => { - try { - client.pipeline.removePolicy({ - name: bearerTokenAuthenticationPolicyName - }); - const result = await client.path("/authentication/oauth2/invalid").get(); - assert.strictEqual(result.status, "403"); - if (result.status === "403") { - assert.strictEqual(result.body.error, "invalid-grant"); - } - } catch (err) { - assert.fail(err as string); + client.pipeline.removePolicy({ + name: bearerTokenAuthenticationPolicyName + }); + const result = await client.path("/authentication/oauth2/invalid").get(); + assert.strictEqual(result.status, "403"); + if (result.status === "403") { + assert.strictEqual(result.body.error, "invalid-grant"); } }); }); diff --git a/packages/typespec-ts/test/integration/authUnion.spec.ts b/packages/typespec-ts/test/integration/authUnion.spec.ts index 7a4ef951f2..7e609ca854 100644 --- a/packages/typespec-ts/test/integration/authUnion.spec.ts +++ b/packages/typespec-ts/test/integration/authUnion.spec.ts @@ -48,23 +48,15 @@ describe("AuthUnionClient Rest Client", () => { it("should return 204 when the token is valid", async () => { prepareToken(); - try { - const result = await client - .path("/authentication/union/validtoken") - .get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/authentication/union/validtoken") + .get(); + assert.strictEqual(result.status, "204"); }); it("should return 204 when the key is valid", async () => { prepareKey(); - try { - const result = await client.path("/authentication/union/validkey").get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/authentication/union/validkey").get(); + assert.strictEqual(result.status, "204"); }); }); diff --git a/packages/typespec-ts/test/integration/azureArmResources.spec.ts b/packages/typespec-ts/test/integration/azureArmResources.spec.ts index 6233cb6e39..f1f91b5504 100644 --- a/packages/typespec-ts/test/integration/azureArmResources.spec.ts +++ b/packages/typespec-ts/test/integration/azureArmResources.spec.ts @@ -130,7 +130,7 @@ describe("Azure Arm Resources Rest Client", () => { ) .patch({ body: { - location: "eastus2", + location: "eastus", properties: { description: "valid2" } @@ -146,7 +146,7 @@ describe("Azure Arm Resources Rest Client", () => { assert.strictEqual(result.body.id, validSingletonResource.id); assert.strictEqual(result.body.name, validSingletonResource.name); assert.strictEqual(result.body.type, validSingletonResource.type); - assert.strictEqual(result.body.location, "eastus2"); + assert.strictEqual(result.body.location, "eastus"); assert.strictEqual(result.body.properties?.description, "valid2"); }); diff --git a/packages/typespec-ts/test/integration/azureClientGeneratorCoreAccess.spec.ts b/packages/typespec-ts/test/integration/azureClientGeneratorCoreAccess.spec.ts index 38e9ccd7cc..1db5198e50 100644 --- a/packages/typespec-ts/test/integration/azureClientGeneratorCoreAccess.spec.ts +++ b/packages/typespec-ts/test/integration/azureClientGeneratorCoreAccess.spec.ts @@ -16,132 +16,97 @@ describe("Access Client", () => { }); it("should get no decorator in public operation", async () => { - try { - const result = await client - .path( - "/azure/client-generator-core/access/publicOperation/noDecoratorInPublic" - ) - .get({ queryParameters: { name: "myname" } }); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.name, "myname"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/azure/client-generator-core/access/publicOperation/noDecoratorInPublic" + ) + .get({ queryParameters: { name: "sample" } }); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.name, "sample"); + }); it("should get public decorator in public operation", async () => { - try { - const result = await client - .path( - "/azure/client-generator-core/access/publicOperation/publicDecoratorInPublic" - ) - .get({ queryParameters: { name: "myname" } }); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.name, "myname"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/azure/client-generator-core/access/publicOperation/publicDecoratorInPublic" + ) + .get({ queryParameters: { name: "sample" } }); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.name, "sample"); }); it("should get no decorator in internal operation", async () => { - try { - const result = await client - .path( - "/azure/client-generator-core/access/internalOperation/noDecoratorInInternal" - ) - .get({ queryParameters: { name: "myname" } }); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.name, "myname"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/azure/client-generator-core/access/internalOperation/noDecoratorInInternal" + ) + .get({ queryParameters: { name: "sample" } }); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.name, "sample"); }); it("should get internal decorator in internal operation", async () => { - try { - const result = await client - .path( - "/azure/client-generator-core/access/internalOperation/internalDecoratorInInternal" - ) - .get({ queryParameters: { name: "myname" } }); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.name, "myname"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/azure/client-generator-core/access/internalOperation/internalDecoratorInInternal" + ) + .get({ queryParameters: { name: "sample" } }); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.name, "sample"); }); it("should get public decorator in internal operation", async () => { - try { - const result = await client - .path( - "/azure/client-generator-core/access/internalOperation/publicDecoratorInInternal" - ) - .get({ queryParameters: { name: "myname" } }); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.name, "myname"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/azure/client-generator-core/access/internalOperation/publicDecoratorInInternal" + ) + .get({ queryParameters: { name: "sample" } }); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.name, "sample"); }); it("should get public shared model in operation", async () => { - try { - const result = await client - .path( - "/azure/client-generator-core/access/sharedModelInOperation/public" - ) - .get({ queryParameters: { name: "myname" } }); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.name, "myname"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/azure/client-generator-core/access/sharedModelInOperation/public" + ) + .get({ queryParameters: { name: "sample" } }); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.name, "sample"); }); it("should get internal shared model in operation", async () => { - try { - const result = await client - .path( - "/azure/client-generator-core/access/sharedModelInOperation/internal" - ) - .get({ queryParameters: { name: "myname" } }); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.name, "myname"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/azure/client-generator-core/access/sharedModelInOperation/internal" + ) + .get({ queryParameters: { name: "sample" } }); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.name, "sample"); }); it("should get relative model in operation", async () => { - try { - const result = await client - .path( - "/azure/client-generator-core/access/relativeModelInOperation/operation" - ) - .get({ - queryParameters: { name: "Madge", inner: { name: "Madge" } } - }); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.name, "Madge"); - assert.strictEqual(result.body.inner.name, "Madge"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/azure/client-generator-core/access/relativeModelInOperation/operation" + ) + .get({ + queryParameters: { name: "Madge", inner: { name: "Madge" } } + }); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.name, "Madge"); + assert.strictEqual(result.body.inner.name, "Madge"); }); it("should get relative model in discriminator", async () => { - try { - const result = await client - .path( - "/azure/client-generator-core/access/relativeModelInOperation/discriminator" - ) - .get({ queryParameters: { name: "Madge", kind: "real" } }); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.name, "Madge"); - assert.strictEqual(result.body.kind, "real"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/azure/client-generator-core/access/relativeModelInOperation/discriminator" + ) + .get({ queryParameters: { name: "Madge", kind: "real" } }); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.name, "Madge"); + assert.strictEqual(result.body.kind, "real"); }); }); diff --git a/packages/typespec-ts/test/integration/azurecore.spec.ts b/packages/typespec-ts/test/integration/azurecore.spec.ts index f49199f258..126605dbe4 100644 --- a/packages/typespec-ts/test/integration/azurecore.spec.ts +++ b/packages/typespec-ts/test/integration/azurecore.spec.ts @@ -35,68 +35,52 @@ describe("Azure Core Rest Client", () => { }; const expectBody = { users: [validUser, validUser2] }; it("should put user", async () => { - try { - const result = await client.path("/azure/core/basic/users/{id}", 1).put({ - body: { - name: "Madge" - }, - contentType: "application/json" - }); - if (isUnexpected(result)) { - throw Error("Unexpected status code"); - } - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, validUser); - } catch (err) { - assert.fail(err as string); + const result = await client.path("/azure/core/basic/users/{id}", 1).put({ + body: { + name: "Madge" + }, + contentType: "application/json" + }); + if (isUnexpected(result)) { + throw Error("Unexpected status code"); } + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, validUser); }); it("should patch user", async () => { - try { - const result = await client - .path("/azure/core/basic/users/{id}", 1) - .patch({ - contentType: "application/merge-patch+json", - body: { - name: "Madge" - } - }); - if (isUnexpected(result)) { - throw Error("Unexpected status code"); - } - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, validUser); - } catch (err) { - assert.fail(err as string); + const result = await client + .path("/azure/core/basic/users/{id}", 1) + .patch({ + contentType: "application/merge-patch+json", + body: { + name: "Madge" + } + }); + if (isUnexpected(result)) { + throw Error("Unexpected status code"); } + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, validUser); }); it("should get user", async () => { - try { - const result = await client.path("/azure/core/basic/users/{id}", 1).get(); - if (isUnexpected(result)) { - throw Error("Unexpected status code"); - } - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, validUser); - } catch (err) { - assert.fail(err as string); + const result = await client.path("/azure/core/basic/users/{id}", 1).get(); + if (isUnexpected(result)) { + throw Error("Unexpected status code"); } + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, validUser); }); it("should delete user", async () => { - try { - const result = await client - .path("/azure/core/basic/users/{id}", 1) - .delete(); - if (isUnexpected(result)) { - throw Error("Unexpected status code"); - } - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); + const result = await client + .path("/azure/core/basic/users/{id}", 1) + .delete(); + if (isUnexpected(result)) { + throw Error("Unexpected status code"); } + assert.strictEqual(result.status, "204"); }); it("should list users", async () => { @@ -138,40 +122,32 @@ describe("Azure Core Rest Client", () => { }); it("should export a user", async () => { - try { - const result = await client - .path("/azure/core/basic/users/{id}:export", 1) - .post({ - queryParameters: { - format: "json" - } - }); - if (isUnexpected(result)) { - throw Error("Unexpected status code"); - } - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, validUser); - } catch (err) { - assert.fail(err as string); + const result = await client + .path("/azure/core/basic/users/{id}:export", 1) + .post({ + queryParameters: { + format: "json" + } + }); + if (isUnexpected(result)) { + throw Error("Unexpected status code"); } + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, validUser); }); it("should export all users", async () => { - try { - const result = await client - .path("/azure/core/basic/users:exportallusers") - .post({ - queryParameters: { - format: "json" - } - }); - if (isUnexpected(result)) { - throw Error("Unexpected status code"); - } - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, expectBody); - } catch (err) { - assert.fail(err as string); + const result = await client + .path("/azure/core/basic/users:exportallusers") + .post({ + queryParameters: { + format: "json" + } + }); + if (isUnexpected(result)) { + throw Error("Unexpected status code"); } + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, expectBody); }); }); diff --git a/packages/typespec-ts/test/integration/azurecorescalar.spec.ts b/packages/typespec-ts/test/integration/azurecorescalar.spec.ts index 5394d7d094..ccc13a85b6 100644 --- a/packages/typespec-ts/test/integration/azurecorescalar.spec.ts +++ b/packages/typespec-ts/test/integration/azurecorescalar.spec.ts @@ -12,64 +12,44 @@ describe("Azure Core Saclar Rest Client", () => { }); it("should get an Azure Location value", async () => { - try { - const result = await client - .path("/azure/core/scalar/azureLocation") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body, "eastus"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/azure/core/scalar/azureLocation") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body, "eastus"); }); it("should put an Azure Location value", async () => { - try { - const result = await client.path("/azure/core/scalar/azureLocation").put({ - body: "eastus", - headers: { - "content-type": "text/plain" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/azure/core/scalar/azureLocation").put({ + body: "eastus", + headers: { + "content-type": "text/plain" + } + }); + assert.strictEqual(result.status, "204"); }); it("should post an Azure Location value", async () => { - try { - const result = await client - .path("/azure/core/scalar/azureLocation") - .post({ - body: { location: "eastus" } - }); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, { location: "eastus" }); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/azure/core/scalar/azureLocation") + .post({ + body: { location: "eastus" } + }); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, { location: "eastus" }); }); it("should post an Azure Location value with header", async () => { - try { - const result = await client - .path("/azure/core/scalar/azureLocation/header") - .post({ headers: { region: "eastus" } }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/azure/core/scalar/azureLocation/header") + .post({ headers: { region: "eastus" } }); + assert.strictEqual(result.status, "204"); }); it("should post an Azure Location with query", async () => { - try { - const result = await client - .path("/azure/core/scalar/azureLocation/query") - .post({ queryParameters: { region: "eastus" } }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/azure/core/scalar/azureLocation/query") + .post({ queryParameters: { region: "eastus" } }); + assert.strictEqual(result.status, "204"); }); }); diff --git a/packages/typespec-ts/test/integration/azurecoretraits.spec.ts b/packages/typespec-ts/test/integration/azurecoretraits.spec.ts index 47e4cc6afb..dba7bfaa90 100644 --- a/packages/typespec-ts/test/integration/azurecoretraits.spec.ts +++ b/packages/typespec-ts/test/integration/azurecoretraits.spec.ts @@ -16,46 +16,38 @@ describe("Azure Core Traits Rest Client", () => { }); it("should get user traits", async () => { - try { - const result = await client.path("/azure/core/traits/user/{id}", 1).get({ - headers: { - foo: "123", - "If-Match": '"valid"', - "If-None-Match": '"invalid"', - "If-Modified-Since": "Thu, 26 Aug 2021 14:38:00 GMT", - "If-Unmodified-Since": "Fri, 26 Aug 2022 14:38:00 GMT" - } - }); - if (isUnexpected(result)) { - throw Error("Unexpected status code"); + const result = await client.path("/azure/core/traits/user/{id}", 1).get({ + headers: { + foo: "123", + "If-Match": '"valid"', + "If-None-Match": '"invalid"', + "If-Modified-Since": "Thu, 26 Aug 2021 14:38:00 GMT", + "If-Unmodified-Since": "Fri, 26 Aug 2022 14:38:00 GMT" } - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.name, "Madge"); - } catch (err) { - assert.fail(err as string); + }); + if (isUnexpected(result)) { + throw Error("Unexpected status code"); } + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.name, "Madge"); }); it("should post user traits", async () => { - try { - const result = await client - .path("/azure/core/traits/user/{id}:repeatableAction", 1) - .post({ - headers: { - "Repeatability-Request-ID": "86aede1f-96fa-4e7f-b1e1-bf8a947cb804", - "Repeatability-First-Sent": "Mon, 27 Nov 2023 11:58:00 GMT" - }, - body: { - userActionValue: "test" - } - }); - if (isUnexpected(result)) { - throw Error("Unexpected status code"); - } - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.userActionResult, "test"); - } catch (err) { - assert.fail(err as string); + const result = await client + .path("/azure/core/traits/user/{id}:repeatableAction", 1) + .post({ + headers: { + "Repeatability-Request-ID": "86aede1f-96fa-4e7f-b1e1-bf8a947cb804", + "Repeatability-First-Sent": "Mon, 27 Nov 2023 11:58:00 GMT" + }, + body: { + userActionValue: "test" + } + }); + if (isUnexpected(result)) { + throw Error("Unexpected status code"); } + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.userActionResult, "test"); }); }); diff --git a/packages/typespec-ts/test/integration/bodyParameters.spec.ts b/packages/typespec-ts/test/integration/bodyParameters.spec.ts index 7efa0e2699..6b6f9503c8 100644 --- a/packages/typespec-ts/test/integration/bodyParameters.spec.ts +++ b/packages/typespec-ts/test/integration/bodyParameters.spec.ts @@ -10,58 +10,42 @@ describe("BodyOptionalityClient Rest Client", () => { }); it("should support required-explicit body", async () => { - try { - const result = await client - .path("/parameters/body-optionality/required-explicit") - .post({ - body: { - name: "foo" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/parameters/body-optionality/required-explicit") + .post({ + body: { + name: "foo" + } + }); + assert.strictEqual(result.status, "204"); }); it("should support optional-explicit body", async () => { - try { - const result = await client - .path("/parameters/body-optionality/optional-explicit/set") - .post({ - body: { - name: "foo" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/parameters/body-optionality/optional-explicit/set") + .post({ + body: { + name: "foo" + } + }); + assert.strictEqual(result.status, "204"); }); it("should support optional-explicit omitted body", async () => { - try { - const result = await client - .path("/parameters/body-optionality/optional-explicit/omit") - .post(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/parameters/body-optionality/optional-explicit/omit") + .post(); + assert.strictEqual(result.status, "204"); }); it("should support required-implicit body", async () => { - try { - const result = await client - .path("/parameters/body-optionality/required-implicit") - .post({ - body: { - name: "foo" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/parameters/body-optionality/required-implicit") + .post({ + body: { + name: "foo" + } + }); + assert.strictEqual(result.status, "204"); }); }); diff --git a/packages/typespec-ts/test/integration/clientNaming.spec.ts b/packages/typespec-ts/test/integration/clientNaming.spec.ts index 602feef16a..73a5cc651e 100644 --- a/packages/typespec-ts/test/integration/clientNaming.spec.ts +++ b/packages/typespec-ts/test/integration/clientNaming.spec.ts @@ -15,127 +15,83 @@ describe("ClientEncodedNameClient Rest Client", () => { }); it("should work with property client", async () => { - try { - const result = await client.path("/client/naming/property/client").post({ - body: { defaultName: true } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/client/naming/property/client").post({ + body: { defaultName: true } + }); + assert.strictEqual(result.status, "204"); }); it("should work with property language", async () => { - try { - const result = await client - .path("/client/naming/property/language") - .post({ - body: { defaultName: true } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/client/naming/property/language") + .post({ + body: { defaultName: true } + }); + assert.strictEqual(result.status, "204"); }); it("should work with property compatible-with-encoded-name", async () => { - try { - const result = await client - .path("/client/naming/property/compatible-with-encoded-name") - .post({ - body: { wireName: true } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/client/naming/property/compatible-with-encoded-name") + .post({ + body: { wireName: true } + }); + assert.strictEqual(result.status, "204"); }); it("should work with operation", async () => { - try { - const result = await client.path("/client/naming/operation").post(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/client/naming/operation").post(); + assert.strictEqual(result.status, "204"); }); it("should work with parameter", async () => { - try { - const result = await client.path("/client/naming/parameter").post({ - queryParameters: { defaultName: "true" } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/client/naming/parameter").post({ + queryParameters: { defaultName: "true" } + }); + assert.strictEqual(result.status, "204"); }); it("should post header request ", async () => { - try { - const result = await client.path("/client/naming/header").post({ - headers: { "default-name": "true" } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/client/naming/header").post({ + headers: { "default-name": "true" } + }); + assert.strictEqual(result.status, "204"); }); it("should get header response", async () => { - try { - const result = await client.path("/client/naming/header").get(); - assert.strictEqual(result.headers["default-name"], "true"); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/client/naming/header").get(); + assert.strictEqual(result.headers["default-name"], "true"); + assert.strictEqual(result.status, "204"); }); it("should work with model client", async () => { - try { - const result = await client.path("/client/naming/model/client").post({ - body: { defaultName: true } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/client/naming/model/client").post({ + body: { defaultName: true } + }); + assert.strictEqual(result.status, "204"); }); it("should work with model language", async () => { - try { - const result = await client.path("/client/naming/model/language").post({ - body: { defaultName: true } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/client/naming/model/language").post({ + body: { defaultName: true } + }); + assert.strictEqual(result.status, "204"); }); it("should work with union enum name", async () => { - try { - const result = await client - .path("/client/naming/union-enum/union-enum-name") - .post({ body: "value1", headers: { "content-type": "text/plain" } }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/client/naming/union-enum/union-enum-name") + .post({ body: "value1", headers: { "content-type": "text/plain" } }); + assert.strictEqual(result.status, "204"); }); it("should work with union enum member name", async () => { - try { - const result = await client - .path("/client/naming/union-enum/union-enum-member-name") - .post({ - body: "value1", - headers: { "content-type": "text/plain" } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/client/naming/union-enum/union-enum-member-name") + .post({ + body: "value1", + headers: { "content-type": "text/plain" } + }); + assert.strictEqual(result.status, "204"); }); }); diff --git a/packages/typespec-ts/test/integration/clientRequestIdHeader.spec.ts b/packages/typespec-ts/test/integration/clientRequestIdHeader.spec.ts index 6672aa7999..bb9bfb5ddd 100644 --- a/packages/typespec-ts/test/integration/clientRequestIdHeader.spec.ts +++ b/packages/typespec-ts/test/integration/clientRequestIdHeader.spec.ts @@ -15,35 +15,27 @@ describe("ClientRequestIdClient", () => { }); it("should append client-request-id header and value if no any input", async () => { - try { - const result = await client - .path("/azure/special-headers/x-ms-client-request-id/") - .get(); - assert.isNotNull(result.request.headers.get("client-request-id")); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/azure/special-headers/x-ms-client-request-id/") + .get(); + assert.isNotNull(result.request.headers.get("client-request-id")); + assert.strictEqual(result.status, "204"); }); it("should set client-request-id header and value if input is provided", async () => { - try { - const overrideReqId = "86aede1f-96fa-4e7f-b1e1-bf8a947cb804"; - const result = await client - .path("/azure/special-headers/x-ms-client-request-id/") - .get({ - headers: { - "client-request-id": overrideReqId - } - }); - assert.strictEqual( - result.request.headers.get("client-request-id"), - overrideReqId - ); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const overrideReqId = "86aede1f-96fa-4e7f-b1e1-bf8a947cb804"; + const result = await client + .path("/azure/special-headers/x-ms-client-request-id/") + .get({ + headers: { + "client-request-id": overrideReqId + } + }); + assert.strictEqual( + result.request.headers.get("client-request-id"), + overrideReqId + ); + assert.strictEqual(result.status, "204"); }); it("should custom the header name in client options", async () => { @@ -57,14 +49,10 @@ describe("ClientRequestIdClient", () => { clientRequestIdHeaderName: headerName } }); - try { - const result = await client - .path("/azure/special-headers/x-ms-client-request-id/") - .get(); - assert.strictEqual(result.status, "400"); - assert.isNotNull(result.request.headers.get(headerName)); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/azure/special-headers/x-ms-client-request-id/") + .get(); + assert.strictEqual(result.status, "400"); + assert.isNotNull(result.request.headers.get(headerName)); }); }); diff --git a/packages/typespec-ts/test/integration/clientStructure.spec.ts b/packages/typespec-ts/test/integration/clientStructure.spec.ts index f4ec69fdd9..560284417d 100644 --- a/packages/typespec-ts/test/integration/clientStructure.spec.ts +++ b/packages/typespec-ts/test/integration/clientStructure.spec.ts @@ -60,94 +60,58 @@ describe("ClientStructureClient Rest Client", () => { it("should call operation one correctly", async () => { for (const client of clientArray) { - try { - const result = await client.path("/one").post(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/one").post(); + assert.strictEqual(result.status, "204"); } }); it("should call operation two correctly", async () => { for (const client of clientArray) { - try { - const result = await client.path("/two").post(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/two").post(); + assert.strictEqual(result.status, "204"); } }); it("should call operation three correctly", async () => { for (const client of clientArray) { - try { - const result = await client.path("/three").post(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/three").post(); + assert.strictEqual(result.status, "204"); } }); it("should call operation four correctly", async () => { for (const client of clientArray) { - try { - const result = await client.path("/four").post(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/four").post(); + assert.strictEqual(result.status, "204"); } }); it("should call operation five correctly", async () => { for (const client of clientArray) { - try { - const result = await client.path("/five").post(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/five").post(); + assert.strictEqual(result.status, "204"); } }); it("should call operation six correctly", async () => { for (const client of clientArray) { - try { - const result = await client.path("/six").post(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/six").post(); + assert.strictEqual(result.status, "204"); } }); it("should call operation seven correctly", async () => { - try { - const result = await client0.path("/seven").post(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client0.path("/seven").post(); + assert.strictEqual(result.status, "204"); }); it("should call operation eight correctly", async () => { - try { - const result = await client0.path("/eight").post(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client0.path("/eight").post(); + assert.strictEqual(result.status, "204"); }); it("should call operation nine correctly", async () => { - try { - const result = await client0.path("/nine").post(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client0.path("/nine").post(); + assert.strictEqual(result.status, "204"); }); }); diff --git a/packages/typespec-ts/test/integration/dictionary.spec.ts b/packages/typespec-ts/test/integration/dictionary.spec.ts index 4cfc9d2f77..9501f7bffa 100644 --- a/packages/typespec-ts/test/integration/dictionary.spec.ts +++ b/packages/typespec-ts/test/integration/dictionary.spec.ts @@ -73,34 +73,26 @@ describe("Dictionary Client", () => { matrix([testedTypes], async (params: TypeDetail) => { it(`should get a ${params.type} value`, async () => { - try { - const result = await client - .path(`/type/dictionary/${params.type}` as any) - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, params.defaultValue); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/type/dictionary/${params.type}` as any) + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, params.defaultValue); }); it(`should put a ${params.type} value`, async () => { - try { - let property; - if (params.convertedToFn) { - property = params.convertedToFn(params.defaultValue); - } else { - property = params.defaultValue; - } - const result = await client - .path(`/type/dictionary/${params.type}` as any) - .put({ - body: property - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); + let property; + if (params.convertedToFn) { + property = params.convertedToFn(params.defaultValue); + } else { + property = params.defaultValue; } + const result = await client + .path(`/type/dictionary/${params.type}` as any) + .put({ + body: property + }); + assert.strictEqual(result.status, "204"); }); }); }); diff --git a/packages/typespec-ts/test/integration/emptyModel.spec.ts b/packages/typespec-ts/test/integration/emptyModel.spec.ts index c9fec29939..d0b2c4ca62 100644 --- a/packages/typespec-ts/test/integration/emptyModel.spec.ts +++ b/packages/typespec-ts/test/integration/emptyModel.spec.ts @@ -15,35 +15,23 @@ describe("TypeModelEmptyClient Rest Client", () => { }); it(`should put empty model`, async () => { - try { - const result = await client.path("/type/model/empty/alone").put({ - body: {} - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/type/model/empty/alone").put({ + body: {} + }); + assert.strictEqual(result.status, "204"); }); it(`should get empty model`, async () => { - try { - const result = await client.path("/type/model/empty/alone").get(); - assert.strictEqual(result.status, "200"); - assert.isEmpty(result.body); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/type/model/empty/alone").get(); + assert.strictEqual(result.status, "200"); + assert.isEmpty(result.body); }); it(`should post round-trip empty model`, async () => { - try { - const result = await client.path("/type/model/empty/round-trip").post({ - body: {} - }); - assert.strictEqual(result.status, "200"); - assert.isEmpty(result.body); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/type/model/empty/round-trip").post({ + body: {} + }); + assert.strictEqual(result.status, "200"); + assert.isEmpty(result.body); }); }); diff --git a/packages/typespec-ts/test/integration/encodeBytes.spec.ts b/packages/typespec-ts/test/integration/encodeBytes.spec.ts index 380c780b89..ef6634ee32 100644 --- a/packages/typespec-ts/test/integration/encodeBytes.spec.ts +++ b/packages/typespec-ts/test/integration/encodeBytes.spec.ts @@ -20,173 +20,125 @@ describe("EncodeDatetimeClient Rest Client", () => { describe("query", () => { it(`should get bytes`, async () => { - try { - const result = await client.path(`/encode/bytes/query/default`).get({ - queryParameters: { - value: "dGVzdA==" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path(`/encode/bytes/query/default`).get({ + queryParameters: { + value: "dGVzdA==" + } + }); + assert.strictEqual(result.status, "204"); }); it(`should get bytes base64 encoding`, async () => { - try { - const result = await client.path(`/encode/bytes/query/base64`).get({ - queryParameters: { - value: "dGVzdA==" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path(`/encode/bytes/query/base64`).get({ + queryParameters: { + value: "dGVzdA==" + } + }); + assert.strictEqual(result.status, "204"); }); it(`should get bytes base64url encoding`, async () => { - try { - const result = await client.path(`/encode/bytes/query/base64url`).get({ - queryParameters: { - value: "dGVzdA" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path(`/encode/bytes/query/base64url`).get({ + queryParameters: { + value: "dGVzdA" + } + }); + assert.strictEqual(result.status, "204"); }); it(`should get bytes base64url-array`, async () => { - try { - const result = await client - .path(`/encode/bytes/query/base64url-array`) - .get({ - queryParameters: { - value: ["dGVzdA", "dGVzdA"] - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/bytes/query/base64url-array`) + .get({ + queryParameters: { + value: ["dGVzdA", "dGVzdA"] + } + }); + assert.strictEqual(result.status, "204"); }); }); describe("property", () => { it(`should post bytes`, async () => { - try { - const result = await client - .path(`/encode/bytes/property/default`) - .post({ - body: { - value: "dGVzdA==" - } - }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } - }); - - it(`should post bytes base64 encoding`, async () => { - try { - const result = await client.path(`/encode/bytes/property/base64`).post({ + const result = await client + .path(`/encode/bytes/property/default`) + .post({ body: { value: "dGVzdA==" } }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + assert.strictEqual(result.status, "200"); + }); + + it(`should post bytes base64 encoding`, async () => { + const result = await client.path(`/encode/bytes/property/base64`).post({ + body: { + value: "dGVzdA==" + } + }); + assert.strictEqual(result.status, "200"); }); it(`should post bytes base64url encoding`, async () => { - try { - const result = await client - .path(`/encode/bytes/property/base64url`) - .post({ - body: { - value: "dGVzdA" - } - }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/bytes/property/base64url`) + .post({ + body: { + value: "dGVzdA" + } + }); + assert.strictEqual(result.status, "200"); }); it(`should post bytes base64url array`, async () => { - try { - const result = await client - .path(`/encode/bytes/property/base64url-array`) - .post({ - body: { - value: ["dGVzdA", "dGVzdA"] - } - }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/bytes/property/base64url-array`) + .post({ + body: { + value: ["dGVzdA", "dGVzdA"] + } + }); + assert.strictEqual(result.status, "200"); }); }); describe("header", () => { it(`should get bytes`, async () => { - try { - const result = await client.path(`/encode/bytes/header/default`).get({ - headers: { - value: "dGVzdA==" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path(`/encode/bytes/header/default`).get({ + headers: { + value: "dGVzdA==" + } + }); + assert.strictEqual(result.status, "204"); }); it(`should get bytes base64 encoding`, async () => { - try { - const result = await client.path(`/encode/bytes/header/base64`).get({ - headers: { - value: "dGVzdA==" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path(`/encode/bytes/header/base64`).get({ + headers: { + value: "dGVzdA==" + } + }); + assert.strictEqual(result.status, "204"); }); it(`should get bytes base64url encoding`, async () => { - try { - const result = await client.path(`/encode/bytes/header/base64url`).get({ - headers: { - value: "dGVzdA" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path(`/encode/bytes/header/base64url`).get({ + headers: { + value: "dGVzdA" + } + }); + assert.strictEqual(result.status, "204"); }); it(`should get bytes base64url-array`, async () => { - try { - const result = await client - .path(`/encode/bytes/header/base64url-array`) - .get({ - headers: { - value: buildCsvCollection(["dGVzdA", "dGVzdA"]) - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/bytes/header/base64url-array`) + .get({ + headers: { + value: buildCsvCollection(["dGVzdA", "dGVzdA"]) + } + }); + assert.strictEqual(result.status, "204"); }); }); @@ -195,73 +147,53 @@ describe("EncodeDatetimeClient Rest Client", () => { resolve("../../packages/typespec-ts/temp/assets/image.png") ); it(`should post bytes`, async () => { - try { - const result = await client - .path(`/encode/bytes/body/request/default`) - .post({ - contentType: "application/json", - body: "dGVzdA==" - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/bytes/body/request/default`) + .post({ + contentType: "application/json", + body: "dGVzdA==" + }); + assert.strictEqual(result.status, "204"); }); it(`should post bytes base64 encoding`, async () => { - try { - const result = await client - .path(`/encode/bytes/body/request/base64`) - .post({ - contentType: "application/json", - body: "dGVzdA==" - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/bytes/body/request/base64`) + .post({ + contentType: "application/json", + body: "dGVzdA==" + }); + assert.strictEqual(result.status, "204"); }); it(`should post bytes base64url encoding`, async () => { - try { - const result = await client - .path(`/encode/bytes/body/request/base64url`) - .post({ - contentType: "application/json", - body: "dGVzdA" - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/bytes/body/request/base64url`) + .post({ + contentType: "application/json", + body: "dGVzdA" + }); + assert.strictEqual(result.status, "204"); }); it(`should post bytes with custom content type`, async () => { - try { - const result = await client - .path(`/encode/bytes/body/request/custom-content-type`) - .post({ - contentType: "image/png", - body: pngFile - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/bytes/body/request/custom-content-type`) + .post({ + contentType: "image/png", + body: pngFile + }); + assert.strictEqual(result.status, "204"); }).timeout(10000); it(`should post bytes with custom content type`, async () => { - try { - const result = await client - .path(`/encode/bytes/body/request/octet-stream`) - .post({ - contentType: "application/octet-stream", - body: pngFile - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/bytes/body/request/octet-stream`) + .post({ + contentType: "application/octet-stream", + body: pngFile + }); + assert.strictEqual(result.status, "204"); }); }); @@ -270,69 +202,47 @@ describe("EncodeDatetimeClient Rest Client", () => { resolve("../../packages/typespec-ts/temp/assets/image.png") ).toString(); it(`should get bytes with base64 encoding by default`, async () => { - try { - const result = await client - .path(`/encode/bytes/body/response/default`) - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body, "dGVzdA=="); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/bytes/body/response/default`) + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body, "dGVzdA=="); }); it(`should get bytes base64 encoding`, async () => { - try { - const result = await client - .path(`/encode/bytes/body/response/base64`) - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body, "dGVzdA=="); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/bytes/body/response/base64`) + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body, "dGVzdA=="); }); it(`should get bytes base64url encoding`, async () => { - try { - const result = await client - .path(`/encode/bytes/body/response/base64url`) - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body, "dGVzdA"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/bytes/body/response/base64url`) + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body, "dGVzdA"); }); it(`should get bytes with custom content type`, async () => { - try { - const result = await client - .path(`/encode/bytes/body/response/custom-content-type`) - .get({ - contentType: "image/png" - }); - // console.log(result.status, Buffer.from(result.body), pngFile); - assert.strictEqual(result.status, "200"); - assert.strictEqual(uint8ArrayToString(result.body, "utf-8"), pngFile); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/bytes/body/response/custom-content-type`) + .get({ + contentType: "image/png" + }); + assert.strictEqual(result.status, "200"); + assert.strictEqual(uint8ArrayToString(result.body, "utf-8"), pngFile); }); it(`should get bytes with octet-stream content type`, async () => { - try { - const result = await client - .path(`/encode/bytes/body/response/octet-stream`) - .get({ - contentType: "application/octet-stream" - }); - // console.log(result.status, Buffer.from(result.body), pngFile); - assert.strictEqual(result.status, "200"); - assert.strictEqual(uint8ArrayToString(result.body, "utf-8"), pngFile); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/bytes/body/response/octet-stream`) + .get({ + contentType: "application/octet-stream" + }); + assert.strictEqual(result.status, "200"); + assert.strictEqual(uint8ArrayToString(result.body, "utf-8"), pngFile); }); }); }); diff --git a/packages/typespec-ts/test/integration/encodeDatetime.spec.ts b/packages/typespec-ts/test/integration/encodeDatetime.spec.ts index f82c365be0..7d0106102c 100644 --- a/packages/typespec-ts/test/integration/encodeDatetime.spec.ts +++ b/packages/typespec-ts/test/integration/encodeDatetime.spec.ts @@ -17,288 +17,212 @@ describe("EncodeDatetimeClient Rest Client", () => { describe("query", () => { it(`should get default query`, async () => { - try { - const result = await client.path(`/encode/datetime/query/default`).get({ - queryParameters: { - value: "2022-08-26T18:38:00.000Z" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path(`/encode/datetime/query/default`).get({ + queryParameters: { + value: "2022-08-26T18:38:00.000Z" + } + }); + assert.strictEqual(result.status, "204"); }); it(`should get rfc3339 query`, async () => { - try { - const result = await client.path(`/encode/datetime/query/rfc3339`).get({ - queryParameters: { - value: "2022-08-26T18:38:00.000Z" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path(`/encode/datetime/query/rfc3339`).get({ + queryParameters: { + value: "2022-08-26T18:38:00.000Z" + } + }); + assert.strictEqual(result.status, "204"); }); it(`should get rfc7231 query`, async () => { - try { - const result = await client.path(`/encode/datetime/query/rfc7231`).get({ - queryParameters: { - value: "Fri, 26 Aug 2022 14:38:00 GMT" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path(`/encode/datetime/query/rfc7231`).get({ + queryParameters: { + value: "Fri, 26 Aug 2022 14:38:00 GMT" + } + }); + assert.strictEqual(result.status, "204"); }); it(`should get unix-timestamp query`, async () => { - try { - const result = await client - .path(`/encode/datetime/query/unix-timestamp`) - .get({ - queryParameters: { - value: 1686566864 - }, - skipUrlEncoding: true - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/datetime/query/unix-timestamp`) + .get({ + queryParameters: { + value: 1686566864 + }, + skipUrlEncoding: true + }); + assert.strictEqual(result.status, "204"); }); it(`should get unix-timestamp-array query`, async () => { - try { - const result = await client - .path(`/encode/datetime/query/unix-timestamp-array`) - .get({ - queryParameters: { - value: [1686566864, 1686734256] - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/datetime/query/unix-timestamp-array`) + .get({ + queryParameters: { + value: [1686566864, 1686734256] + } + }); + assert.strictEqual(result.status, "204"); }); }); describe("property", () => { it(`should post default property`, async () => { - try { - const result = await client - .path(`/encode/datetime/property/default`) - .post({ - body: { - value: "2022-08-26T18:38:00.000Z" - } - }); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.value, "2022-08-26T18:38:00.000Z"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/datetime/property/default`) + .post({ + body: { + value: "2022-08-26T18:38:00.000Z" + } + }); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.value, "2022-08-26T18:38:00.000Z"); }); it(`should post rfc3339 property`, async () => { - try { - const result = await client - .path(`/encode/datetime/property/rfc3339`) - .post({ - body: { - value: "2022-08-26T18:38:00.000Z" - } - }); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.value, "2022-08-26T18:38:00.000Z"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/datetime/property/rfc3339`) + .post({ + body: { + value: "2022-08-26T18:38:00.000Z" + } + }); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.value, "2022-08-26T18:38:00.000Z"); }); it(`should post rfc7231 property`, async () => { - try { - const result = await client - .path(`/encode/datetime/property/rfc7231`) - .post({ - body: { - value: "Fri, 26 Aug 2022 14:38:00 GMT" - } - }); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.value, "Fri, 26 Aug 2022 14:38:00 GMT"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/datetime/property/rfc7231`) + .post({ + body: { + value: "Fri, 26 Aug 2022 14:38:00 GMT" + } + }); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.value, "Fri, 26 Aug 2022 14:38:00 GMT"); }); it(`should post unix-timestamp property`, async () => { - try { - const result = await client - .path(`/encode/datetime/property/unix-timestamp`) - .post({ - body: { - value: 1686566864 - } - }); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.value, 1686566864); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/datetime/property/unix-timestamp`) + .post({ + body: { + value: 1686566864 + } + }); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.value, 1686566864); }); it(`should post unix-timestamp-array property`, async () => { - try { - const result = await client - .path(`/encode/datetime/property/unix-timestamp-array`) - .post({ - body: { - value: [1686566864, 1686734256] - } - }); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body.value, [1686566864, 1686734256]); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/datetime/property/unix-timestamp-array`) + .post({ + body: { + value: [1686566864, 1686734256] + } + }); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body.value, [1686566864, 1686734256]); }); }); describe("header", () => { it(`should get default header`, async () => { - try { - const result = await client - .path(`/encode/datetime/header/default`) - .get({ - headers: { - value: "Fri, 26 Aug 2022 14:38:00 GMT" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/datetime/header/default`) + .get({ + headers: { + value: "Fri, 26 Aug 2022 14:38:00 GMT" + } + }); + assert.strictEqual(result.status, "204"); }); it(`should get rfc3339 header`, async () => { - try { - const result = await client - .path(`/encode/datetime/header/rfc3339`) - .get({ - headers: { - value: "2022-08-26T18:38:00.000Z" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/datetime/header/rfc3339`) + .get({ + headers: { + value: "2022-08-26T18:38:00.000Z" + } + }); + assert.strictEqual(result.status, "204"); }); it(`should get rfc7231 header`, async () => { - try { - const result = await client - .path(`/encode/datetime/header/rfc7231`) - .get({ - headers: { - value: "Fri, 26 Aug 2022 14:38:00 GMT" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/datetime/header/rfc7231`) + .get({ + headers: { + value: "Fri, 26 Aug 2022 14:38:00 GMT" + } + }); + assert.strictEqual(result.status, "204"); }); it(`should get unix-timestamp header`, async () => { - try { - const result = await client - .path(`/encode/datetime/header/unix-timestamp`) - .get({ - headers: { - value: 1686566864 - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/datetime/header/unix-timestamp`) + .get({ + headers: { + value: 1686566864 + } + }); + assert.strictEqual(result.status, "204"); }); it(`should get unix-timestamp-array header`, async () => { - try { - const result = await client - .path(`/encode/datetime/header/unix-timestamp-array`) - .get({ - headers: { - value: buildCsvCollection([1686566864, 1686734256]) - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/datetime/header/unix-timestamp-array`) + .get({ + headers: { + value: buildCsvCollection([1686566864, 1686734256]) + } + }); + assert.strictEqual(result.status, "204"); }); }); describe("response header", () => { it(`should get default header`, async () => { - try { - const result = await client - .path(`/encode/datetime/responseheader/default`) - .get(); - assert.strictEqual(result.status, "204"); - assert.strictEqual( - result.headers.value, - "Fri, 26 Aug 2022 14:38:00 GMT" - ); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/datetime/responseheader/default`) + .get(); + assert.strictEqual(result.status, "204"); + assert.strictEqual( + result.headers.value, + "Fri, 26 Aug 2022 14:38:00 GMT" + ); }); it(`should get rfc3339 header`, async () => { - try { - const result = await client - .path(`/encode/datetime/responseheader/rfc3339`) - .get(); - assert.strictEqual(result.status, "204"); - assert.strictEqual(result.headers.value, "2022-08-26T18:38:00.000Z"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/datetime/responseheader/rfc3339`) + .get(); + assert.strictEqual(result.status, "204"); + assert.strictEqual(result.headers.value, "2022-08-26T18:38:00.000Z"); }); it(`should get rfc7231 header`, async () => { - try { - const result = await client - .path(`/encode/datetime/responseheader/rfc7231`) - .get(); - assert.strictEqual(result.status, "204"); - assert.strictEqual( - result.headers.value, - "Fri, 26 Aug 2022 14:38:00 GMT" - ); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/datetime/responseheader/rfc7231`) + .get(); + assert.strictEqual(result.status, "204"); + assert.strictEqual( + result.headers.value, + "Fri, 26 Aug 2022 14:38:00 GMT" + ); }); it(`should get unix-timestamp header`, async () => { - try { - const result = await client - .path(`/encode/datetime/responseheader/unix-timestamp`) - .get(); - assert.strictEqual(result.status, "204"); - assert.strictEqual(result.headers.value, "1686566864"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/datetime/responseheader/unix-timestamp`) + .get(); + assert.strictEqual(result.status, "204"); + assert.strictEqual(result.headers.value, "1686566864"); }); }); }); diff --git a/packages/typespec-ts/test/integration/encodeDuration.spec.ts b/packages/typespec-ts/test/integration/encodeDuration.spec.ts index 815327383b..c63b672682 100644 --- a/packages/typespec-ts/test/integration/encodeDuration.spec.ts +++ b/packages/typespec-ts/test/integration/encodeDuration.spec.ts @@ -17,280 +17,208 @@ describe("EncodeDurationClient Rest Client", () => { describe("property", () => { it(`should post default property`, async () => { - try { - const result = await client - .path(`/encode/duration/property/default`) - .post({ - body: { - value: "P40D" - } - }); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.value, "P40D"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/duration/property/default`) + .post({ + body: { + value: "P40D" + } + }); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.value, "P40D"); }); it(`should post float-seconds property`, async () => { - try { - const result = await client - .path(`/encode/duration/property/float-seconds`) - .post({ - body: { - value: 35.625 - } - }); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.value, 35.625); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/duration/property/float-seconds`) + .post({ + body: { + value: 35.625 + } + }); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.value, 35.625); }); it(`should post float64-seconds property`, async () => { - try { - const result = await client - .path(`/encode/duration/property/float64-seconds`) - .post({ - body: { - value: 35.625 - } - }); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.value, 35.625); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/duration/property/float64-seconds`) + .post({ + body: { + value: 35.625 + } + }); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.value, 35.625); }); it(`should post int32-seconds property`, async () => { - try { - const result = await client - .path(`/encode/duration/property/int32-seconds`) - .post({ - body: { - value: 36 - } - }); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.value, 36); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/duration/property/int32-seconds`) + .post({ + body: { + value: 36 + } + }); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.value, 36); }); it(`should post iso8601 property`, async () => { - try { - const result = await client - .path(`/encode/duration/property/iso8601`) - .post({ - body: { - value: "P40D" - } - }); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.value, "P40D"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/duration/property/iso8601`) + .post({ + body: { + value: "P40D" + } + }); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.value, "P40D"); }); it(`should post float-seconds-array property`, async () => { - try { - const result = await client - .path(`/encode/duration/property/float-seconds-array`) - .post({ - body: { - value: [35.625, 46.75] - } - }); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body.value, [35.625, 46.75]); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/duration/property/float-seconds-array`) + .post({ + body: { + value: [35.625, 46.75] + } + }); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body.value, [35.625, 46.75]); }); }); describe("query", () => { it(`should get default query`, async () => { - try { - const result = await client.path(`/encode/duration/query/default`).get({ - queryParameters: { - input: "P40D" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path(`/encode/duration/query/default`).get({ + queryParameters: { + input: "P40D" + } + }); + assert.strictEqual(result.status, "204"); }); it(`should get iso8601 query`, async () => { - try { - const result = await client.path(`/encode/duration/query/iso8601`).get({ - queryParameters: { - input: "P40D" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path(`/encode/duration/query/iso8601`).get({ + queryParameters: { + input: "P40D" + } + }); + assert.strictEqual(result.status, "204"); }); it(`should get int32-seconds query`, async () => { - try { - const result = await client - .path(`/encode/duration/query/int32-seconds`) - .get({ - queryParameters: { - input: 36 - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/duration/query/int32-seconds`) + .get({ + queryParameters: { + input: 36 + } + }); + assert.strictEqual(result.status, "204"); }); it(`should get int32-seconds-array query`, async () => { - try { - const result = await client - .path(`/encode/duration/query/int32-seconds-array`) - .get({ - queryParameters: { - input: [36, 47] - }, - skipUrlEncoding: true - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/duration/query/int32-seconds-array`) + .get({ + queryParameters: { + input: [36, 47] + }, + skipUrlEncoding: true + }); + assert.strictEqual(result.status, "204"); }); it(`should get float-seconds query`, async () => { - try { - const result = await client - .path(`/encode/duration/query/float-seconds`) - .get({ - queryParameters: { - input: 35.625 - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/duration/query/float-seconds`) + .get({ + queryParameters: { + input: 35.625 + } + }); + assert.strictEqual(result.status, "204"); }); it(`should get float64-seconds query`, async () => { - try { - const result = await client - .path(`/encode/duration/query/float64-seconds`) - .get({ - queryParameters: { - input: 35.625 - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/duration/query/float64-seconds`) + .get({ + queryParameters: { + input: 35.625 + } + }); + assert.strictEqual(result.status, "204"); }); }); describe("header", () => { it(`should get default header`, async () => { - try { - const result = await client - .path(`/encode/duration/header/default`) - .get({ - headers: { - duration: "P40D" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/duration/header/default`) + .get({ + headers: { + duration: "P40D" + } + }); + assert.strictEqual(result.status, "204"); }); it(`should get iso8601 header`, async () => { - try { - const result = await client - .path(`/encode/duration/header/iso8601`) - .get({ - headers: { - duration: "P40D" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/duration/header/iso8601`) + .get({ + headers: { + duration: "P40D" + } + }); + assert.strictEqual(result.status, "204"); }); it(`should get iso8601-array header`, async () => { - try { - const result = await client - .path(`/encode/duration/header/iso8601-array`) - .get({ - headers: { - duration: buildCsvCollection(["P40D", "P50D"]) - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/duration/header/iso8601-array`) + .get({ + headers: { + duration: buildCsvCollection(["P40D", "P50D"]) + } + }); + assert.strictEqual(result.status, "204"); }); it(`should get int32-seconds header`, async () => { - try { - const result = await client - .path(`/encode/duration/header/int32-seconds`) - .get({ - headers: { - duration: 36 - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/duration/header/int32-seconds`) + .get({ + headers: { + duration: 36 + } + }); + assert.strictEqual(result.status, "204"); }); it(`should get float-seconds header`, async () => { - try { - const result = await client - .path(`/encode/duration/header/float-seconds`) - .get({ - headers: { - duration: 35.625 - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/duration/header/float-seconds`) + .get({ + headers: { + duration: 35.625 + } + }); + assert.strictEqual(result.status, "204"); }); it(`should get float64-seconds header`, async () => { - try { - const result = await client - .path(`/encode/duration/header/float64-seconds`) - .get({ - headers: { - duration: 35.625 - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/encode/duration/header/float64-seconds`) + .get({ + headers: { + duration: 35.625 + } + }); + assert.strictEqual(result.status, "204"); }); }); }); diff --git a/packages/typespec-ts/test/integration/extensibleEnums.spec.ts b/packages/typespec-ts/test/integration/extensibleEnums.spec.ts index a5dbdbdb92..420dcc462a 100644 --- a/packages/typespec-ts/test/integration/extensibleEnums.spec.ts +++ b/packages/typespec-ts/test/integration/extensibleEnums.spec.ts @@ -10,58 +10,42 @@ describe("ExtensibleEnums Rest Client", () => { }); it("should get known value", async () => { - try { - const result = await client - .path("/type/enum/extensible/string/known-value") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body, "Monday"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/enum/extensible/string/known-value") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body, "Monday"); }); it("should put known value", async () => { - try { - const result = await client - .path("/type/enum/extensible/string/known-value") - .put({ - body: "Monday", - headers: { - "content-type": "text/plain" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/enum/extensible/string/known-value") + .put({ + body: "Monday", + headers: { + "content-type": "text/plain" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get unknown value", async () => { - try { - const result = await client - .path("/type/enum/extensible/string/unknown-value") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body, "Weekend"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/enum/extensible/string/unknown-value") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body, "Weekend"); }); it("should put unknown value", async () => { - try { - const result = await client - .path("/type/enum/extensible/string/unknown-value") - .put({ - body: "Weekend", - headers: { - "content-type": "text/plain" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/enum/extensible/string/unknown-value") + .put({ + body: "Weekend", + headers: { + "content-type": "text/plain" + } + }); + assert.strictEqual(result.status, "204"); }); }); diff --git a/packages/typespec-ts/test/integration/fixedEnums.spec.ts b/packages/typespec-ts/test/integration/fixedEnums.spec.ts index 50d5d8aa62..4acec614e7 100644 --- a/packages/typespec-ts/test/integration/fixedEnums.spec.ts +++ b/packages/typespec-ts/test/integration/fixedEnums.spec.ts @@ -15,42 +15,30 @@ describe("FixedEnums Rest Client", () => { }); it("should get known value", async () => { - try { - const result = await client - .path("/type/enum/fixed/string/known-value") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body, "Monday"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/enum/fixed/string/known-value") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body, "Monday"); }); it("should put known value", async () => { - try { - const result = await client - .path("/type/enum/fixed/string/known-value") - .put({ - body: "Monday", - contentType: "application/json" - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/enum/fixed/string/known-value") + .put({ + body: "Monday", + contentType: "application/json" + }); + assert.strictEqual(result.status, "204"); }); it("should put unknown value and receives 500", async () => { - try { - const result = await client - .path("/type/enum/fixed/string/unknown-value") - .put({ - body: "Weekend" as any, - contentType: "application/json" - }); - assert.strictEqual(result.status, "500"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/enum/fixed/string/unknown-value") + .put({ + body: "Weekend" as any, + contentType: "application/json" + }); + assert.strictEqual(result.status, "500"); }); }); diff --git a/packages/typespec-ts/test/integration/lroCore.spec.ts b/packages/typespec-ts/test/integration/lroCore.spec.ts index d1bff675de..789769f158 100644 --- a/packages/typespec-ts/test/integration/lroCore.spec.ts +++ b/packages/typespec-ts/test/integration/lroCore.spec.ts @@ -14,76 +14,64 @@ describe("AzureLroCoreClient Rest Client", () => { }); it("should put LRO response", async () => { - try { - const initialResponse = await client - .path("/azure/core/lro/standard/users/{name}", "madge") - .put({ - body: { - role: "contributor" - } - }); - const poller = await getLongRunningPoller(client, initialResponse); - const result = await poller.pollUntilDone(); - assert.equal(result.status, "200"); - assert.strictEqual(initialResponse.status, "201"); - if (isUnexpected(result)) { - throw Error("Unexpected status code"); - } - assert.equal(result.status, "200"); - if (result.status === "200") { - assert.equal(result.body.name, "madge"); - } - } catch (err) { - assert.fail(err as string); + const initialResponse = await client + .path("/azure/core/lro/standard/users/{name}", "madge") + .put({ + body: { + role: "contributor" + } + }); + const poller = await getLongRunningPoller(client, initialResponse); + const result = await poller.pollUntilDone(); + assert.equal(result.status, "200"); + assert.strictEqual(initialResponse.status, "201"); + if (isUnexpected(result)) { + throw Error("Unexpected status code"); + } + assert.equal(result.status, "200"); + if (result.status === "200") { + assert.equal(result.body.name, "madge"); } }); it("should delete LRO response", async () => { - try { - const initialResponse = await client - .path("/azure/core/lro/standard/users/{name}", "madge") - .delete({ - body: { - role: "contributor" - } - }); - const poller = await getLongRunningPoller(client, initialResponse); - const result = await poller.pollUntilDone(); - assert.equal(result.status, "200"); - assert.strictEqual(initialResponse.status, "202"); - if (isUnexpected(result)) { - throw Error("Unexpected status code"); - } - if (result.status === "200") { - assert.equal(result.body.status, "Succeeded"); - } - } catch (err) { - assert.fail(err as string); + const initialResponse = await client + .path("/azure/core/lro/standard/users/{name}", "madge") + .delete({ + body: { + role: "contributor" + } + }); + const poller = await getLongRunningPoller(client, initialResponse); + const result = await poller.pollUntilDone(); + assert.equal(result.status, "200"); + assert.strictEqual(initialResponse.status, "202"); + if (isUnexpected(result)) { + throw Error("Unexpected status code"); + } + if (result.status === "200") { + assert.equal(result.body.status, "Succeeded"); } }); it("should export LRO response", async () => { - try { - const initialResponse = await client - .path("/azure/core/lro/standard/users/{name}:export", "madge") - .post({ - queryParameters: { - format: "json" - } - }); - const poller = await getLongRunningPoller(client, initialResponse); - const result = await poller.pollUntilDone(); - assert.equal(result.status, "200"); - assert.strictEqual(initialResponse.status, "202"); - if (isUnexpected(result)) { - throw Error("Unexpected status code"); - } - assert.equal(result.status, "200", "final status code"); - if (result.status === "200") { - assert.equal(result.body.result?.name, "madge"); - } - } catch (err) { - assert.fail(err as string); + const initialResponse = await client + .path("/azure/core/lro/standard/users/{name}:export", "madge") + .post({ + queryParameters: { + format: "json" + } + }); + const poller = await getLongRunningPoller(client, initialResponse); + const result = await poller.pollUntilDone(); + assert.equal(result.status, "200"); + assert.strictEqual(initialResponse.status, "202"); + if (isUnexpected(result)) { + throw Error("Unexpected status code"); + } + assert.equal(result.status, "200", "final status code"); + if (result.status === "200") { + assert.equal(result.body.result?.name, "madge"); } }); }); diff --git a/packages/typespec-ts/test/integration/lroRpc.spec.ts b/packages/typespec-ts/test/integration/lroRpc.spec.ts index 5b7aeb12b0..e30d321d73 100644 --- a/packages/typespec-ts/test/integration/lroRpc.spec.ts +++ b/packages/typespec-ts/test/integration/lroRpc.spec.ts @@ -14,25 +14,21 @@ describe("RpcClient Rest Client", () => { }); it("should post LRO response", async () => { - try { - const initialResponse = await client - .path("/azure/core/lro/rpc/generations:submit") - .post({ - body: { prompt: "text" } - }); - const poller = await getLongRunningPoller(client, initialResponse); - const result = await poller.pollUntilDone(); - assert.equal(result.status, "200"); - assert.strictEqual(initialResponse.status, "202"); - if (isUnexpected(result)) { - throw Error("Unexpected status code"); - } - assert.equal(result.status, "200"); - if (result.status === "200") { - assert.equal(result.body.result?.data, "text data"); - } - } catch (err) { - assert.fail(err as string); + const initialResponse = await client + .path("/azure/core/lro/rpc/generations:submit") + .post({ + body: { prompt: "text" } + }); + const poller = await getLongRunningPoller(client, initialResponse); + const result = await poller.pollUntilDone(); + assert.equal(result.status, "200"); + assert.strictEqual(initialResponse.status, "202"); + if (isUnexpected(result)) { + throw Error("Unexpected status code"); + } + assert.equal(result.status, "200"); + if (result.status === "200") { + assert.equal(result.body.result?.data, "text data"); } }); }); diff --git a/packages/typespec-ts/test/integration/modelInheritance.spec.ts b/packages/typespec-ts/test/integration/modelInheritance.spec.ts index c79651ff9b..08bfe50d33 100644 --- a/packages/typespec-ts/test/integration/modelInheritance.spec.ts +++ b/packages/typespec-ts/test/integration/modelInheritance.spec.ts @@ -22,31 +22,23 @@ describe("NestedDiscriminatorClient Rest Client", () => { sharktype: "goblin" }; it("should get valid", async () => { - try { - const result = await client - .path("/type/model/inheritance/nested-discriminator/model") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.age, 1); - if (result.body.kind === "shark") { - assert.strictEqual((result.body as SharkOutput).sharktype, "goblin"); - } - } catch (err) { - assert.fail(err as string); + const result = await client + .path("/type/model/inheritance/nested-discriminator/model") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.age, 1); + if (result.body.kind === "shark") { + assert.strictEqual((result.body as SharkOutput).sharktype, "goblin"); } }); it("should put valid", async () => { - try { - const result = await client - .path("/type/model/inheritance/nested-discriminator/model") - .put({ - body: validBody - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/model/inheritance/nested-discriminator/model") + .put({ + body: validBody + }); + assert.strictEqual(result.status, "204"); }); const validRecursiveBody: Salmon = { @@ -107,64 +99,48 @@ describe("NestedDiscriminatorClient Rest Client", () => { } }; it("should get recursive body", async () => { - try { - const result = await client - .path("/type/model/inheritance/nested-discriminator/recursivemodel") - .get(); - assert.strictEqual(result.status, "200"); + const result = await client + .path("/type/model/inheritance/nested-discriminator/recursivemodel") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual( + JSON.stringify(result.body), + JSON.stringify(validRecursiveBody) + ); + if (result.body.kind === "salmon") { assert.strictEqual( - JSON.stringify(result.body), - JSON.stringify(validRecursiveBody) + (result.body as SalmonOutput).partner?.kind, + validRecursiveBody.partner?.kind ); - if (result.body.kind === "salmon") { - assert.strictEqual( - (result.body as SalmonOutput).partner?.kind, - validRecursiveBody.partner?.kind - ); - } - } catch (err) { - assert.fail(err as string); } }); it("should put recursive body", async () => { - try { - const result = await client - .path("/type/model/inheritance/nested-discriminator/recursivemodel") - .put({ - body: validRecursiveBody - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/model/inheritance/nested-discriminator/recursivemodel") + .put({ + body: validRecursiveBody + }); + assert.strictEqual(result.status, "204"); }); it("should get missing discriminator body", async () => { - try { - const result = await client - .path( - "/type/model/inheritance/nested-discriminator/missingdiscriminator" - ) - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.age, 1); - assert.isUndefined(result.body.kind); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/type/model/inheritance/nested-discriminator/missingdiscriminator" + ) + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.age, 1); + assert.isUndefined(result.body.kind); }); it("should get wrong discriminator body", async () => { - try { - const result = await client - .path("/type/model/inheritance/nested-discriminator/wrongdiscriminator") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.age, 1); - assert.strictEqual(result.body.kind, "wrongKind"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/model/inheritance/nested-discriminator/wrongdiscriminator") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.age, 1); + assert.strictEqual(result.body.kind, "wrongKind"); }); }); diff --git a/packages/typespec-ts/test/integration/modelInheritanceEnumDiscriminator.spec.ts b/packages/typespec-ts/test/integration/modelInheritanceEnumDiscriminator.spec.ts index f4d34f8fc4..36232ef497 100644 --- a/packages/typespec-ts/test/integration/modelInheritanceEnumDiscriminator.spec.ts +++ b/packages/typespec-ts/test/integration/modelInheritanceEnumDiscriminator.spec.ts @@ -23,104 +23,72 @@ describe("EnumDiscriminatorClient Rest Client", () => { kind: "cobra" }; it("should get extensible enum", async () => { - try { - const result = await client - .path("/type/model/inheritance/enum-discriminator/extensible-enum") - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, validBody); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/model/inheritance/enum-discriminator/extensible-enum") + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, validBody); }); it("should put extensible enum", async () => { - try { - const result = await client - .path("/type/model/inheritance/enum-discriminator/extensible-enum") - .put({ body: validBody }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/model/inheritance/enum-discriminator/extensible-enum") + .put({ body: validBody }); + assert.strictEqual(result.status, "204"); }); it("should get extensible enum if missing discriminator", async () => { - try { - const result = await client - .path( - "/type/model/inheritance/enum-discriminator/extensible-enum/missingdiscriminator" - ) - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, { weight: 10 } as any); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/type/model/inheritance/enum-discriminator/extensible-enum/missingdiscriminator" + ) + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, { weight: 10 } as any); }); it("should get extensible enum if wrong discriminator", async () => { - try { - const result = await client - .path( - "/type/model/inheritance/enum-discriminator/extensible-enum/wrongdiscriminator" - ) - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, { weight: 8, kind: "wrongKind" }); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/type/model/inheritance/enum-discriminator/extensible-enum/wrongdiscriminator" + ) + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, { weight: 8, kind: "wrongKind" }); }); it("should get fixed enum", async () => { - try { - const result = await client - .path("/type/model/inheritance/enum-discriminator/fixed-enum") - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, validFixedEnumBody); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/model/inheritance/enum-discriminator/fixed-enum") + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, validFixedEnumBody); }); it("should put fixed enum", async () => { - try { - const result = await client - .path("/type/model/inheritance/enum-discriminator/fixed-enum") - .put({ body: validFixedEnumBody }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/model/inheritance/enum-discriminator/fixed-enum") + .put({ body: validFixedEnumBody }); + assert.strictEqual(result.status, "204"); }); it("should get fixed enum if missing discriminator", async () => { - try { - const result = await client - .path( - "/type/model/inheritance/enum-discriminator/fixed-enum/missingdiscriminator" - ) - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, { length: 10 } as any); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/type/model/inheritance/enum-discriminator/fixed-enum/missingdiscriminator" + ) + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, { length: 10 } as any); }); it("should get fixed enum if wrong discriminator", async () => { - try { - const result = await client - .path( - "/type/model/inheritance/enum-discriminator/fixed-enum/wrongdiscriminator" - ) - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, { length: 8, kind: "wrongKind" }); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/type/model/inheritance/enum-discriminator/fixed-enum/wrongdiscriminator" + ) + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, { length: 8, kind: "wrongKind" }); }); }); diff --git a/packages/typespec-ts/test/integration/modelInheritanceNotDiscriminated.spec.ts b/packages/typespec-ts/test/integration/modelInheritanceNotDiscriminated.spec.ts index 5bfbcbcd6e..d988e87855 100644 --- a/packages/typespec-ts/test/integration/modelInheritanceNotDiscriminated.spec.ts +++ b/packages/typespec-ts/test/integration/modelInheritanceNotDiscriminated.spec.ts @@ -15,37 +15,25 @@ describe("NotDiscriminatedClient Rest Client", () => { const validBody: Siamese = { name: "abc", age: 32, smart: true }; it("should get valid", async () => { - try { - const result = await client - .path("/type/model/inheritance/not-discriminated/valid") - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, validBody); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/model/inheritance/not-discriminated/valid") + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, validBody); }); it("should put valid", async () => { - try { - const result = await client - .path("/type/model/inheritance/not-discriminated/valid") - .put({ body: validBody }); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, validBody); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/model/inheritance/not-discriminated/valid") + .put({ body: validBody }); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, validBody); }); it("should post valid", async () => { - try { - const result = await client - .path("/type/model/inheritance/not-discriminated/valid") - .post({ body: validBody }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/model/inheritance/not-discriminated/valid") + .post({ body: validBody }); + assert.strictEqual(result.status, "204"); }); }); diff --git a/packages/typespec-ts/test/integration/modelInheritanceRecursive.spec.ts b/packages/typespec-ts/test/integration/modelInheritanceRecursive.spec.ts index a064a21dda..71ce8eb367 100644 --- a/packages/typespec-ts/test/integration/modelInheritanceRecursive.spec.ts +++ b/packages/typespec-ts/test/integration/modelInheritanceRecursive.spec.ts @@ -30,24 +30,16 @@ describe("Recursive Client", () => { }); it("Inheritance Recursive put test", async () => { - try { - const result = await client - .path("/type/model/inheritance/recursive") - .put({ body }); - assert.equal(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/model/inheritance/recursive") + .put({ body }); + assert.equal(result.status, "204"); }); it("Inheritance Recursive get test", async () => { - try { - const result = await client - .path("/type/model/inheritance/recursive") - .get(); - assert.equal(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/model/inheritance/recursive") + .get(); + assert.equal(result.status, "200"); }); }); diff --git a/packages/typespec-ts/test/integration/modelInheritanceSingleDiscriminator.spec.ts b/packages/typespec-ts/test/integration/modelInheritanceSingleDiscriminator.spec.ts index 6b0c8ef626..12e54b7e41 100644 --- a/packages/typespec-ts/test/integration/modelInheritanceSingleDiscriminator.spec.ts +++ b/packages/typespec-ts/test/integration/modelInheritanceSingleDiscriminator.spec.ts @@ -39,86 +39,58 @@ describe("SingleDiscriminatorClient Rest Client", () => { } }; it("should get model with single discriminator", async () => { - try { - const result = await client - .path("/type/model/inheritance/single-discriminator/model") - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, validBody); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/model/inheritance/single-discriminator/model") + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, validBody); }); it("should put model with single discriminator", async () => { - try { - const result = await client - .path("/type/model/inheritance/single-discriminator/model") - .put({ body: validBody }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/model/inheritance/single-discriminator/model") + .put({ body: validBody }); + assert.strictEqual(result.status, "204"); }); it("should get recursive model with single discriminator", async () => { - try { - const result = await client - .path("/type/model/inheritance/single-discriminator/recursivemodel") - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, validRecursiveBody); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/model/inheritance/single-discriminator/recursivemodel") + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, validRecursiveBody); }); it("should put recursive model with single discriminator", async () => { - try { - const result = await client - .path("/type/model/inheritance/single-discriminator/recursivemodel") - .put({ body: validRecursiveBody }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/model/inheritance/single-discriminator/recursivemodel") + .put({ body: validRecursiveBody }); + assert.strictEqual(result.status, "204"); }); it("should get if missing discriminator", async () => { - try { - const result = await client - .path( - "/type/model/inheritance/single-discriminator/missingdiscriminator" - ) - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, { wingspan: 1 } as any); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/type/model/inheritance/single-discriminator/missingdiscriminator" + ) + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, { wingspan: 1 } as any); }); it("should get if wrong discriminator", async () => { - try { - const result = await client - .path("/type/model/inheritance/single-discriminator/wrongdiscriminator") - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, { wingspan: 1, kind: "wrongKind" } as any); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/model/inheritance/single-discriminator/wrongdiscriminator") + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, { wingspan: 1, kind: "wrongKind" } as any); }); it("should get legacy model", async () => { - try { - const result = await client - .path("/type/model/inheritance/single-discriminator/legacy-model") - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, { size: 20, kind: "t-rex" }); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/model/inheritance/single-discriminator/legacy-model") + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, { size: 20, kind: "t-rex" }); }); }); diff --git a/packages/typespec-ts/test/integration/modelPropertyAdditional.spec.ts b/packages/typespec-ts/test/integration/modelPropertyAdditional.spec.ts index a28518221f..e601933b61 100644 --- a/packages/typespec-ts/test/integration/modelPropertyAdditional.spec.ts +++ b/packages/typespec-ts/test/integration/modelPropertyAdditional.spec.ts @@ -15,1150 +15,894 @@ describe("ModelsPropertyAdditional Rest Client", () => { }); it("should get extends unknown additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/extendsRecordUnknown") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual( - result.body.name, - "ExtendsUnknownAdditionalProperties" - ); - assert.strictEqual(result.body["prop1"], 32); - assert.strictEqual(result.body["prop2"], true); - assert.strictEqual(result.body["prop3"], "abc"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/extendsRecordUnknown") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual( + result.body.name, + "ExtendsUnknownAdditionalProperties" + ); + assert.strictEqual(result.body["prop1"], 32); + assert.strictEqual(result.body["prop2"], true); + assert.strictEqual(result.body["prop3"], "abc"); }); it("should put extends unknown additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/extendsRecordUnknown") - .put({ - body: { - name: "ExtendsUnknownAdditionalProperties", - prop1: 32, - prop2: true, - prop3: "abc" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/extendsRecordUnknown") + .put({ + body: { + name: "ExtendsUnknownAdditionalProperties", + prop1: 32, + prop2: true, + prop3: "abc" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get extends unknown derived additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/extendsRecordUnknownDerived") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual( - result.body.name, - "ExtendsUnknownAdditionalProperties" - ); - assert.strictEqual(result.body["index"], 314); - assert.strictEqual(result.body["age"], 2.71875); - assert.strictEqual(result.body["prop1"], 32); - assert.strictEqual(result.body["prop2"], true); - assert.strictEqual(result.body["prop3"], "abc"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/extendsRecordUnknownDerived") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual( + result.body.name, + "ExtendsUnknownAdditionalProperties" + ); + assert.strictEqual(result.body["index"], 314); + assert.strictEqual(result.body["age"], 2.71875); + assert.strictEqual(result.body["prop1"], 32); + assert.strictEqual(result.body["prop2"], true); + assert.strictEqual(result.body["prop3"], "abc"); }); it("should put extends unknown derived additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/extendsRecordUnknownDerived") - .put({ - body: { - name: "ExtendsUnknownAdditionalProperties", - index: 314, - age: 2.71875, - prop1: 32, - prop2: true, - prop3: "abc" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/extendsRecordUnknownDerived") + .put({ + body: { + name: "ExtendsUnknownAdditionalProperties", + index: 314, + age: 2.71875, + prop1: 32, + prop2: true, + prop3: "abc" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get extends unknown discriminated additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/extendsUnknownDiscriminated") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.name, "Derived"); - assert.strictEqual(result.body["kind"], "derived"); - assert.strictEqual(result.body["index"], 314); - assert.strictEqual(result.body["age"], 2.71875); - assert.strictEqual(result.body["prop1"], 32); - assert.strictEqual(result.body["prop2"], true); - assert.strictEqual(result.body["prop3"], "abc"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/extendsUnknownDiscriminated") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.name, "Derived"); + assert.strictEqual(result.body["kind"], "derived"); + assert.strictEqual(result.body["index"], 314); + assert.strictEqual(result.body["age"], 2.71875); + assert.strictEqual(result.body["prop1"], 32); + assert.strictEqual(result.body["prop2"], true); + assert.strictEqual(result.body["prop3"], "abc"); }); it("should put extends unknown discriminated additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/extendsUnknownDiscriminated") - .put({ - body: { - kind: "derived", - name: "Derived", - index: 314, - age: 2.71875, - prop1: 32, - prop2: true, - prop3: "abc" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/extendsUnknownDiscriminated") + .put({ + body: { + kind: "derived", + name: "Derived", + index: 314, + age: 2.71875, + prop1: 32, + prop2: true, + prop3: "abc" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get is unknown additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/isRecordUnknown") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.name, "IsUnknownAdditionalProperties"); - assert.strictEqual(result.body["prop1"], 32); - assert.strictEqual(result.body["prop2"], true); - assert.strictEqual(result.body["prop3"], "abc"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/isRecordUnknown") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.name, "IsUnknownAdditionalProperties"); + assert.strictEqual(result.body["prop1"], 32); + assert.strictEqual(result.body["prop2"], true); + assert.strictEqual(result.body["prop3"], "abc"); }); it("should put is unknown additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/isRecordUnknown") - .put({ - body: { - name: "IsUnknownAdditionalProperties", - prop1: 32, - prop2: true, - prop3: "abc" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/isRecordUnknown") + .put({ + body: { + name: "IsUnknownAdditionalProperties", + prop1: 32, + prop2: true, + prop3: "abc" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get is unknown derived additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/isRecordUnknownDerived") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.name, "IsUnknownAdditionalProperties"); - assert.strictEqual(result.body["index"], 314); - assert.strictEqual(result.body["age"], 2.71875); - assert.strictEqual(result.body["prop1"], 32); - assert.strictEqual(result.body["prop2"], true); - assert.strictEqual(result.body["prop3"], "abc"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/isRecordUnknownDerived") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.name, "IsUnknownAdditionalProperties"); + assert.strictEqual(result.body["index"], 314); + assert.strictEqual(result.body["age"], 2.71875); + assert.strictEqual(result.body["prop1"], 32); + assert.strictEqual(result.body["prop2"], true); + assert.strictEqual(result.body["prop3"], "abc"); }); it("should put is unknown derived additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/isRecordUnknownDerived") - .put({ - body: { - name: "IsUnknownAdditionalProperties", - index: 314, - age: 2.71875, - prop1: 32, - prop2: true, - prop3: "abc" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/isRecordUnknownDerived") + .put({ + body: { + name: "IsUnknownAdditionalProperties", + index: 314, + age: 2.71875, + prop1: 32, + prop2: true, + prop3: "abc" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get is unknown discriminated additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/isUnknownDiscriminated") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.name, "Derived"); - assert.strictEqual(result.body["kind"], "derived"); - assert.strictEqual(result.body["index"], 314); - assert.strictEqual(result.body["age"], 2.71875); - assert.strictEqual(result.body["prop1"], 32); - assert.strictEqual(result.body["prop2"], true); - assert.strictEqual(result.body["prop3"], "abc"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/isUnknownDiscriminated") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.name, "Derived"); + assert.strictEqual(result.body["kind"], "derived"); + assert.strictEqual(result.body["index"], 314); + assert.strictEqual(result.body["age"], 2.71875); + assert.strictEqual(result.body["prop1"], 32); + assert.strictEqual(result.body["prop2"], true); + assert.strictEqual(result.body["prop3"], "abc"); }); it("should put is unknown discriminated additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/isUnknownDiscriminated") - .put({ - body: { - kind: "derived", - name: "Derived", - index: 314, - age: 2.71875, - prop1: 32, - prop2: true, - prop3: "abc" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/isUnknownDiscriminated") + .put({ + body: { + kind: "derived", + name: "Derived", + index: 314, + age: 2.71875, + prop1: 32, + prop2: true, + prop3: "abc" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get extends string additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/extendsRecordString") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.name, "ExtendsStringAdditionalProperties"); - assert.strictEqual(result.body["prop"], "abc"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/extendsRecordString") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.name, "ExtendsStringAdditionalProperties"); + assert.strictEqual(result.body["prop"], "abc"); }); it("should put extends string additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/extendsRecordString") - .put({ - body: { - name: "ExtendsStringAdditionalProperties", - prop: "abc" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/extendsRecordString") + .put({ + body: { + name: "ExtendsStringAdditionalProperties", + prop: "abc" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get is string additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/isRecordstring") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.name, "IsStringAdditionalProperties"); - assert.strictEqual(result.body["prop"], "abc"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/isRecordstring") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.name, "IsStringAdditionalProperties"); + assert.strictEqual(result.body["prop"], "abc"); }); it("should put is string additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/isRecordstring") - .put({ - body: { - name: "IsStringAdditionalProperties", - prop: "abc" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/isRecordstring") + .put({ + body: { + name: "IsStringAdditionalProperties", + prop: "abc" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get extends float additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/extendsRecordFloat") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.id, 43.125); - assert.strictEqual(result.body["prop"], 43.125); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/extendsRecordFloat") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.id, 43.125); + assert.strictEqual(result.body["prop"], 43.125); }); it("should put extends float additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/extendsRecordFloat") - .put({ - body: { - id: 43.125, - prop: 43.125 - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/extendsRecordFloat") + .put({ + body: { + id: 43.125, + prop: 43.125 + } + }); + assert.strictEqual(result.status, "204"); }); it("should get is float additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/isRecordFloat") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.id, 43.125); - assert.strictEqual(result.body["prop"], 43.125); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/isRecordFloat") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.id, 43.125); + assert.strictEqual(result.body["prop"], 43.125); }); it("should put is float additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/isRecordFloat") - .put({ - body: { - id: 43.125, - prop: 43.125 - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/isRecordFloat") + .put({ + body: { + id: 43.125, + prop: 43.125 + } + }); + assert.strictEqual(result.status, "204"); }); it("should get extends model additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/extendsRecordModel") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body["prop"]?.state, "ok"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/extendsRecordModel") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body["prop"]?.state, "ok"); }); it("should put extends model additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/extendsRecordModel") - .put({ - body: { - prop: { state: "ok" }, - knownProp: { state: "ok" } - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/extendsRecordModel") + .put({ + body: { + prop: { state: "ok" }, + knownProp: { state: "ok" } + } + }); + assert.strictEqual(result.status, "204"); }); it("should get is model additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/isRecordModel") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body["prop"]?.state, "ok"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/isRecordModel") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body["prop"]?.state, "ok"); }); it("should put is model additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/isRecordModel") - .put({ - body: { - prop: { state: "ok" }, - knownProp: { state: "ok" } - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/isRecordModel") + .put({ + body: { + prop: { state: "ok" }, + knownProp: { state: "ok" } + } + }); + assert.strictEqual(result.status, "204"); }); it("should get extends model array additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/extendsRecordModelArray") - .get(); - assert.strictEqual(result.status, "200"); - result.body["prop"]?.forEach((item) => { - assert.strictEqual(item.state, "ok"); - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/extendsRecordModelArray") + .get(); + assert.strictEqual(result.status, "200"); + result.body["prop"]?.forEach((item) => { + assert.strictEqual(item.state, "ok"); + }); }); it("should put extends model array additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/extendsRecordModelArray") - .put({ - body: { - prop: [{ state: "ok" }, { state: "ok" }], - knownProp: [{ state: "ok" }, { state: "ok" }] - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/extendsRecordModelArray") + .put({ + body: { + prop: [{ state: "ok" }, { state: "ok" }], + knownProp: [{ state: "ok" }, { state: "ok" }] + } + }); + assert.strictEqual(result.status, "204"); }); it("should get is model array additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/isRecordModelArray") - .get(); - assert.strictEqual(result.status, "200"); - result.body["prop"]?.forEach((item) => { - assert.strictEqual(item.state, "ok"); - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/isRecordModelArray") + .get(); + assert.strictEqual(result.status, "200"); + result.body["prop"]?.forEach((item) => { + assert.strictEqual(item.state, "ok"); + }); }); it("should put is model array additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/isRecordModelArray") - .put({ - body: { - prop: [{ state: "ok" }, { state: "ok" }], - knownProp: [{ state: "ok" }, { state: "ok" }] - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/isRecordModelArray") + .put({ + body: { + prop: [{ state: "ok" }, { state: "ok" }], + knownProp: [{ state: "ok" }, { state: "ok" }] + } + }); + assert.strictEqual(result.status, "204"); }); it("should get spread record string additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/spreadRecordString") - .get({ - body: { - name: "SpreadSpringRecord", - prop: "abc" - } - }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/spreadRecordString") + .get({ + body: { + name: "SpreadSpringRecord", + prop: "abc" + } + }); + assert.strictEqual(result.status, "200"); }); it("should put spread record string additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/spreadRecordString") - .put({ - body: { - name: "SpreadSpringRecord", - prop: "abc" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/spreadRecordString") + .put({ + body: { + name: "SpreadSpringRecord", + prop: "abc" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get spread record float additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/spreadRecordFloat") - .get({ - body: { - id: 43.125, - prop: 43.125 - } - }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/spreadRecordFloat") + .get({ + body: { + id: 43.125, + prop: 43.125 + } + }); + assert.strictEqual(result.status, "200"); }); it("should put spread record float additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/spreadRecordFloat") - .put({ - body: { - id: 43.125, - prop: 43.125 - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/spreadRecordFloat") + .put({ + body: { + id: 43.125, + prop: 43.125 + } + }); + assert.strictEqual(result.status, "204"); }); it("should get spread record model additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/spreadRecordModel") - .get({ - body: { - prop: { state: "ok" }, - knownProp: { state: "ok" } - } - }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/spreadRecordModel") + .get({ + body: { + prop: { state: "ok" }, + knownProp: { state: "ok" } + } + }); + assert.strictEqual(result.status, "200"); }); it("should put spread record model additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/spreadRecordModel") - .put({ - body: { - prop: { state: "ok" }, - knownProp: { state: "ok" } - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/spreadRecordModel") + .put({ + body: { + prop: { state: "ok" }, + knownProp: { state: "ok" } + } + }); + assert.strictEqual(result.status, "204"); }); it("should get spread record model array additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/spreadRecordModelArray") - .get({ - body: { - knownProp: [{ state: "ok" }, { state: "ok" }], - prop: [{ state: "ok" }, { state: "ok" }] - } - }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/spreadRecordModelArray") + .get({ + body: { + knownProp: [{ state: "ok" }, { state: "ok" }], + prop: [{ state: "ok" }, { state: "ok" }] + } + }); + assert.strictEqual(result.status, "200"); }); it("should put spread record model array additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/spreadRecordModelArray") - .put({ - body: { - knownProp: [{ state: "ok" }, { state: "ok" }], - prop: [{ state: "ok" }, { state: "ok" }] - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/spreadRecordModelArray") + .put({ + body: { + knownProp: [{ state: "ok" }, { state: "ok" }], + prop: [{ state: "ok" }, { state: "ok" }] + } + }); + assert.strictEqual(result.status, "204"); }); it("should get spread different record string additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/spreadDifferentRecordString") - .get({ - body: { - id: 43.125, - prop: "abc" - } - }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/spreadDifferentRecordString") + .get({ + body: { + id: 43.125, + prop: "abc" + } + }); + assert.strictEqual(result.status, "200"); }); it("should put spread different record string additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/spreadDifferentRecordString") - .put({ - body: { - id: 43.125, - prop: "abc" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/spreadDifferentRecordString") + .put({ + body: { + id: 43.125, + prop: "abc" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get spread different record float additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/spreadDifferentRecordFloat") - .get({ - body: { - name: "abc", - prop: 43.125 - } - }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/spreadDifferentRecordFloat") + .get({ + body: { + name: "abc", + prop: 43.125 + } + }); + assert.strictEqual(result.status, "200"); }); it("should put spread different record float additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/spreadDifferentRecordFloat") - .put({ - body: { - name: "abc", - prop: 43.125 - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/spreadDifferentRecordFloat") + .put({ + body: { + name: "abc", + prop: 43.125 + } + }); + assert.strictEqual(result.status, "204"); }); it("should get spread different record model additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/spreadDifferentRecordModel") - .get({ - body: { - knownProp: "abc", - prop: { state: "ok" } - } - }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/spreadDifferentRecordModel") + .get({ + body: { + knownProp: "abc", + prop: { state: "ok" } + } + }); + assert.strictEqual(result.status, "200"); }); it("should put spread different record model additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/spreadDifferentRecordModel") - .put({ - body: { - knownProp: "abc", - prop: { state: "ok" } - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/spreadDifferentRecordModel") + .put({ + body: { + knownProp: "abc", + prop: { state: "ok" } + } + }); + assert.strictEqual(result.status, "204"); }); it("should get spread different record model array additional properties", async () => { - try { - const result = await client - .path( - "/type/property/additionalProperties/spreadDifferentRecordModelArray" - ) - .get({ - body: { - knownProp: "abc", - prop: [{ state: "ok" }, { state: "ok" }] - } - }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/type/property/additionalProperties/spreadDifferentRecordModelArray" + ) + .get({ + body: { + knownProp: "abc", + prop: [{ state: "ok" }, { state: "ok" }] + } + }); + assert.strictEqual(result.status, "200"); }); it("should put spread different record model array additional properties", async () => { - try { - const result = await client - .path( - "/type/property/additionalProperties/spreadDifferentRecordModelArray" - ) - .put({ - body: { - knownProp: "abc", - prop: [{ state: "ok" }, { state: "ok" }] - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/type/property/additionalProperties/spreadDifferentRecordModelArray" + ) + .put({ + body: { + knownProp: "abc", + prop: [{ state: "ok" }, { state: "ok" }] + } + }); + assert.strictEqual(result.status, "204"); }); it("should get extends different spread string additional properties", async () => { - try { - const result = await client - .path( - "/type/property/additionalProperties/extendsDifferentSpreadString" - ) - .get({ - body: { - id: 43.125, - prop: "abc", - derivedProp: "abc" - } - }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/type/property/additionalProperties/extendsDifferentSpreadString" + ) + .get({ + body: { + id: 43.125, + prop: "abc", + derivedProp: "abc" + } + }); + assert.strictEqual(result.status, "200"); }); it("should put extends different spread string additional properties", async () => { - try { - const result = await client - .path( - "/type/property/additionalProperties/extendsDifferentSpreadString" - ) - .put({ - body: { - id: 43.125, - prop: "abc", - derivedProp: "abc" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/type/property/additionalProperties/extendsDifferentSpreadString" + ) + .put({ + body: { + id: 43.125, + prop: "abc", + derivedProp: "abc" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get extends different spread float additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/extendsDifferentSpreadFloat") - .get({ - body: { - name: "abc", - prop: 43.125, - derivedProp: 43.125 - } - }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/extendsDifferentSpreadFloat") + .get({ + body: { + name: "abc", + prop: 43.125, + derivedProp: 43.125 + } + }); + assert.strictEqual(result.status, "200"); }); it("should put extends different spread float additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/extendsDifferentSpreadFloat") - .put({ - body: { - name: "abc", - prop: 43.125, - derivedProp: 43.125 - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/extendsDifferentSpreadFloat") + .put({ + body: { + name: "abc", + prop: 43.125, + derivedProp: 43.125 + } + }); + assert.strictEqual(result.status, "204"); }); it("should get extends different spread model additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/extendsDifferentSpreadModel") - .get({ - body: { - knownProp: "abc", - prop: { state: "ok" }, - derivedProp: { state: "ok" } - } - }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/extendsDifferentSpreadModel") + .get({ + body: { + knownProp: "abc", + prop: { state: "ok" }, + derivedProp: { state: "ok" } + } + }); + assert.strictEqual(result.status, "200"); }); it("should put extends different spread model additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/extendsDifferentSpreadModel") - .put({ - body: { - knownProp: "abc", - prop: { state: "ok" }, - derivedProp: { state: "ok" } - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/extendsDifferentSpreadModel") + .put({ + body: { + knownProp: "abc", + prop: { state: "ok" }, + derivedProp: { state: "ok" } + } + }); + assert.strictEqual(result.status, "204"); }); it("should get extends different spread model array additional properties", async () => { - try { - const result = await client - .path( - "/type/property/additionalProperties/extendsDifferentSpreadModelArray" - ) - .get({ - body: { - knownProp: "abc", - prop: [{ state: "ok" }, { state: "ok" }], - derivedProp: [{ state: "ok" }, { state: "ok" }] - } - }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/type/property/additionalProperties/extendsDifferentSpreadModelArray" + ) + .get({ + body: { + knownProp: "abc", + prop: [{ state: "ok" }, { state: "ok" }], + derivedProp: [{ state: "ok" }, { state: "ok" }] + } + }); + assert.strictEqual(result.status, "200"); }); it("should put extends different spread model array additional properties", async () => { - try { - const result = await client - .path( - "/type/property/additionalProperties/extendsDifferentSpreadModelArray" - ) - .put({ - body: { - knownProp: "abc", - prop: [{ state: "ok" }, { state: "ok" }], - derivedProp: [{ state: "ok" }, { state: "ok" }] - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/type/property/additionalProperties/extendsDifferentSpreadModelArray" + ) + .put({ + body: { + knownProp: "abc", + prop: [{ state: "ok" }, { state: "ok" }], + derivedProp: [{ state: "ok" }, { state: "ok" }] + } + }); + assert.strictEqual(result.status, "204"); }); it("should get multiple spread record additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/multipleSpreadRecord") - .get({ - body: { - flag: true, - prop1: "abc", - prop2: 43.125 - } - }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/multipleSpreadRecord") + .get({ + body: { + flag: true, + prop1: "abc", + prop2: 43.125 + } + }); + assert.strictEqual(result.status, "200"); }); it("should put multiple spread record additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/multipleSpreadRecord") - .put({ - body: { - flag: true, - prop1: "abc", - prop2: 43.125 - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/multipleSpreadRecord") + .put({ + body: { + flag: true, + prop1: "abc", + prop2: 43.125 + } + }); + assert.strictEqual(result.status, "204"); }); it("should get spread record union additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/spreadRecordUnion") - .get({ - body: { - flag: true, - prop1: "abc", - prop2: 43.125 - } - }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/spreadRecordUnion") + .get({ + body: { + flag: true, + prop1: "abc", + prop2: 43.125 + } + }); + assert.strictEqual(result.status, "200"); }); it("should put spread record union additional properties", async () => { - try { - const result = await client - .path("/type/property/additionalProperties/spreadRecordUnion") - .put({ - body: { - flag: true, - prop1: "abc", - prop2: 43.125 - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/additionalProperties/spreadRecordUnion") + .put({ + body: { + flag: true, + prop1: "abc", + prop2: 43.125 + } + }); + assert.strictEqual(result.status, "204"); }); it("should get spread record discriminate union additional properties", async () => { - try { - const result = await client - .path( - "/type/property/additionalProperties/spreadRecordDiscriminatedUnion" - ) - .get({ - body: { - name: "abc", - prop1: { - kind: "kind0", - fooProp: "abc" - }, - prop2: { - kind: "kind1", - start: "2021-01-01T00:00:00Z", - end: "2021-01-02T00:00:00Z" - } - } - }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/type/property/additionalProperties/spreadRecordDiscriminatedUnion" + ) + .get({ + body: { + name: "abc", + prop1: { + kind: "kind0", + fooProp: "abc" + }, + prop2: { + kind: "kind1", + start: "2021-01-01T00:00:00Z", + end: "2021-01-02T00:00:00Z" + } + } + }); + assert.strictEqual(result.status, "200"); }); it("should put spread record discriminate union additional properties", async () => { - try { - const result = await client - .path( - "/type/property/additionalProperties/spreadRecordDiscriminatedUnion" - ) - .put({ - body: { - name: "abc", - prop1: { - kind: "kind0", - fooProp: "abc" - }, - prop2: { - kind: "kind1", - start: "2021-01-01T00:00:00Z", - end: "2021-01-02T00:00:00Z" - } - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/type/property/additionalProperties/spreadRecordDiscriminatedUnion" + ) + .put({ + body: { + name: "abc", + prop1: { + kind: "kind0", + fooProp: "abc" + }, + prop2: { + kind: "kind1", + start: "2021-01-01T00:00:00Z", + end: "2021-01-02T00:00:00Z" + } + } + }); + assert.strictEqual(result.status, "204"); }); it("should get spread record nondiscriminate union additional properties", async () => { - try { - const result = await client - .path( - "/type/property/additionalProperties/spreadRecordNonDiscriminatedUnion" - ) - .get({ - body: { - name: "abc", - prop1: { - kind: "kind0", - fooProp: "abc" - }, - prop2: { - kind: "kind1", - start: "2021-01-01T00:00:00Z", - end: "2021-01-02T00:00:00Z" - } - } - }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/type/property/additionalProperties/spreadRecordNonDiscriminatedUnion" + ) + .get({ + body: { + name: "abc", + prop1: { + kind: "kind0", + fooProp: "abc" + }, + prop2: { + kind: "kind1", + start: "2021-01-01T00:00:00Z", + end: "2021-01-02T00:00:00Z" + } + } + }); + assert.strictEqual(result.status, "200"); }); it("should put spread record nondiscriminate union additional properties", async () => { - try { - const result = await client - .path( - "/type/property/additionalProperties/spreadRecordNonDiscriminatedUnion" - ) - .put({ - body: { - name: "abc", - prop1: { - kind: "kind0", - fooProp: "abc" - }, - prop2: { - kind: "kind1", - start: "2021-01-01T00:00:00Z", - end: "2021-01-02T00:00:00Z" - } - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/type/property/additionalProperties/spreadRecordNonDiscriminatedUnion" + ) + .put({ + body: { + name: "abc", + prop1: { + kind: "kind0", + fooProp: "abc" + }, + prop2: { + kind: "kind1", + start: "2021-01-01T00:00:00Z", + end: "2021-01-02T00:00:00Z" + } + } + }); + assert.strictEqual(result.status, "204"); }); it("should get spread record nondiscriminate union2 additional properties", async () => { - try { - const result = await client - .path( - "/type/property/additionalProperties/spreadRecordNonDiscriminatedUnion2" - ) - .get({ - body: { - name: "abc", - prop1: { - kind: "kind1", - start: "2021-01-01T00:00:00Z" - }, - prop2: { - kind: "kind1", - start: "2021-01-01T00:00:00Z", - end: "2021-01-02T00:00:00Z" - } - } - }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/type/property/additionalProperties/spreadRecordNonDiscriminatedUnion2" + ) + .get({ + body: { + name: "abc", + prop1: { + kind: "kind1", + start: "2021-01-01T00:00:00Z" + }, + prop2: { + kind: "kind1", + start: "2021-01-01T00:00:00Z", + end: "2021-01-02T00:00:00Z" + } + } + }); + assert.strictEqual(result.status, "200"); }); it("should put spread record nondiscriminate union2 additional properties", async () => { - try { - const result = await client - .path( - "/type/property/additionalProperties/spreadRecordNonDiscriminatedUnion2" - ) - .put({ - body: { - name: "abc", - prop1: { - kind: "kind1", - start: "2021-01-01T00:00:00Z" - }, - prop2: { - kind: "kind1", - start: "2021-01-01T00:00:00Z", - end: "2021-01-02T00:00:00Z" - } - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/type/property/additionalProperties/spreadRecordNonDiscriminatedUnion2" + ) + .put({ + body: { + name: "abc", + prop1: { + kind: "kind1", + start: "2021-01-01T00:00:00Z" + }, + prop2: { + kind: "kind1", + start: "2021-01-01T00:00:00Z", + end: "2021-01-02T00:00:00Z" + } + } + }); + assert.strictEqual(result.status, "204"); }); it("should get spread record nondiscriminate union3 additional properties", async () => { - try { - const result = await client - .path( - "/type/property/additionalProperties/spreadRecordNonDiscriminatedUnion3" - ) - .get({ - body: { - name: "abc", - prop1: [ - { - kind: "kind1", - start: "2021-01-01T00:00:00Z" - }, - { - kind: "kind1", - start: "2021-01-01T00:00:00Z" - } - ], - prop2: { + const result = await client + .path( + "/type/property/additionalProperties/spreadRecordNonDiscriminatedUnion3" + ) + .get({ + body: { + name: "abc", + prop1: [ + { + kind: "kind1", + start: "2021-01-01T00:00:00Z" + }, + { kind: "kind1", - start: "2021-01-01T00:00:00Z", - end: "2021-01-02T00:00:00Z" + start: "2021-01-01T00:00:00Z" } + ], + prop2: { + kind: "kind1", + start: "2021-01-01T00:00:00Z", + end: "2021-01-02T00:00:00Z" } - }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + } + }); + assert.strictEqual(result.status, "200"); }); it("should put spread record nondiscriminate union3 additional properties", async () => { - try { - const result = await client - .path( - "/type/property/additionalProperties/spreadRecordNonDiscriminatedUnion3" - ) - .put({ - body: { - name: "abc", - prop1: [ - { - kind: "kind1", - start: "2021-01-01T00:00:00Z" - }, - { - kind: "kind1", - start: "2021-01-01T00:00:00Z" - } - ], - prop2: { + const result = await client + .path( + "/type/property/additionalProperties/spreadRecordNonDiscriminatedUnion3" + ) + .put({ + body: { + name: "abc", + prop1: [ + { + kind: "kind1", + start: "2021-01-01T00:00:00Z" + }, + { kind: "kind1", - start: "2021-01-01T00:00:00Z", - end: "2021-01-02T00:00:00Z" + start: "2021-01-01T00:00:00Z" } + ], + prop2: { + kind: "kind1", + start: "2021-01-01T00:00:00Z", + end: "2021-01-02T00:00:00Z" } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + } + }); + assert.strictEqual(result.status, "204"); }); }); diff --git a/packages/typespec-ts/test/integration/modelPropertyNullable.spec.ts b/packages/typespec-ts/test/integration/modelPropertyNullable.spec.ts index 64baea82d3..5f98e9c423 100644 --- a/packages/typespec-ts/test/integration/modelPropertyNullable.spec.ts +++ b/packages/typespec-ts/test/integration/modelPropertyNullable.spec.ts @@ -51,69 +51,53 @@ describe("ModelsPropertyNullableClient Rest Client", () => { matrix([testedTypes], async (params: TypeDetail) => { it(`should get a null value for nullable ${params.type}`, async () => { - try { - const result = await client - .path(`/type/property/nullable/${params.type}/null` as any) - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.nullableProperty, null); - assert.deepEqual(result.body.requiredProperty, "foo"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/type/property/nullable/${params.type}/null` as any) + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.nullableProperty, null); + assert.deepEqual(result.body.requiredProperty, "foo"); }); it(`should get a non-null value for nullable ${params.type}`, async () => { - try { - const result = await client - .path(`/type/property/nullable/${params.type}/non-null` as any) - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body.nullableProperty, params.defaultValue); - assert.deepEqual(result.body.requiredProperty, "foo"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/type/property/nullable/${params.type}/non-null` as any) + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body.nullableProperty, params.defaultValue); + assert.deepEqual(result.body.requiredProperty, "foo"); }); it(`should patch a null value for nullable ${params.type}`, async () => { - try { - const result = await client - .path(`/type/property/nullable/${params.type}/null` as any) - .patch({ - contentType: "application/merge-patch+json", - body: { - requiredProperty: "foo", - nullableProperty: null - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/type/property/nullable/${params.type}/null` as any) + .patch({ + contentType: "application/merge-patch+json", + body: { + requiredProperty: "foo", + nullableProperty: null + } + }); + assert.strictEqual(result.status, "204"); }); it(`should patch a non-null value for nullable ${params.type}`, async () => { - try { - let property; - if (params.convertedToFn) { - property = params.convertedToFn(params.defaultValue); - } else { - property = params.defaultValue; - } - const result = await client - .path(`/type/property/nullable/${params.type}/non-null` as any) - .patch({ - contentType: "application/merge-patch+json", - body: { - requiredProperty: "foo", - nullableProperty: property || null - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); + let property; + if (params.convertedToFn) { + property = params.convertedToFn(params.defaultValue); + } else { + property = params.defaultValue; } + const result = await client + .path(`/type/property/nullable/${params.type}/non-null` as any) + .patch({ + contentType: "application/merge-patch+json", + body: { + requiredProperty: "foo", + nullableProperty: property || null + } + }); + assert.strictEqual(result.status, "204"); }); }); }); diff --git a/packages/typespec-ts/test/integration/modelPropertyOptional.spec.ts b/packages/typespec-ts/test/integration/modelPropertyOptional.spec.ts index d74dbe718f..f41468bbff 100644 --- a/packages/typespec-ts/test/integration/modelPropertyOptional.spec.ts +++ b/packages/typespec-ts/test/integration/modelPropertyOptional.spec.ts @@ -13,807 +13,551 @@ describe("ModelsPropertyOptional Rest Client", () => { }); it("should get all string", async () => { - try { - const result = await client - .path("/type/property/optional/string/all") - .get(); + const result = await client + .path("/type/property/optional/string/all") + .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.property, "hello"); - } catch (err) { - assert.fail(err as string); - } + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.property, "hello"); }); it("should get default string", async () => { - try { - const result = await client - .path("/type/property/optional/string/default") - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, {}); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/string/default") + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, {}); }); it("should put all string", async () => { - try { - const result = await client - .path("/type/property/optional/string/all") - .put({ - body: { property: "hello" } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/string/all") + .put({ + body: { property: "hello" } + }); + assert.strictEqual(result.status, "204"); }); it("should put default string", async () => { - try { - const result = await client - .path("/type/property/optional/string/default") - .put({ body: {} }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/string/default") + .put({ body: {} }); + assert.strictEqual(result.status, "204"); }); it("should get all bytes", async () => { - try { - const result = await client - .path("/type/property/optional/bytes/all") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.property, "aGVsbG8sIHdvcmxkIQ=="); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/bytes/all") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.property, "aGVsbG8sIHdvcmxkIQ=="); }); it("should get default bytes", async () => { - try { - const result = await client - .path("/type/property/optional/bytes/default") - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, {}); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/bytes/default") + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, {}); }); it("should put all bytes", async () => { - try { - const result = await client - .path("/type/property/optional/bytes/all") - .put({ - body: { property: "aGVsbG8sIHdvcmxkIQ==" } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/bytes/all") + .put({ + body: { property: "aGVsbG8sIHdvcmxkIQ==" } + }); + assert.strictEqual(result.status, "204"); }); it("should put default bytes", async () => { - try { - const result = await client - .path("/type/property/optional/bytes/default") - .put({ - body: {} - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/bytes/default") + .put({ + body: {} + }); + assert.strictEqual(result.status, "204"); }); it("should get all datetime", async () => { - try { - const result = await client - .path("/type/property/optional/datetime/all") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.property, "2022-08-26T18:38:00Z"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/datetime/all") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.property, "2022-08-26T18:38:00Z"); }); it("should get default datetime", async () => { - try { - const result = await client - .path("/type/property/optional/datetime/default") - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, {}); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/datetime/default") + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, {}); }); it("should put all datetime", async () => { - try { - const result = await client - .path("/type/property/optional/datetime/all") - .put({ - body: { property: "2022-08-26T18:38:00Z" } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/datetime/all") + .put({ + body: { property: "2022-08-26T18:38:00Z" } + }); + assert.strictEqual(result.status, "204"); }); it("should put default datetime", async () => { - try { - const result = await client - .path("/type/property/optional/datetime/default") - .put({ - body: {} - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/datetime/default") + .put({ + body: {} + }); + assert.strictEqual(result.status, "204"); }); it("should get all duration", async () => { - try { - const result = await client - .path("/type/property/optional/duration/all") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.property, "P123DT22H14M12.011S"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/duration/all") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.property, "P123DT22H14M12.011S"); }); it("should get default duration", async () => { - try { - const result = await client - .path("/type/property/optional/duration/default") - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, {}); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/duration/default") + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, {}); }); it("should put all duration", async () => { - try { - const result = await client - .path("/type/property/optional/duration/all") - .put({ - body: { property: "P123DT22H14M12.011S" } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/duration/all") + .put({ + body: { property: "P123DT22H14M12.011S" } + }); + assert.strictEqual(result.status, "204"); }); it("should put default duration", async () => { - try { - const result = await client - .path("/type/property/optional/duration/default") - .put({ - body: {} - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/duration/default") + .put({ + body: {} + }); + assert.strictEqual(result.status, "204"); }); it("should get all plainDate", async () => { - try { - const result = await client - .path("/type/property/optional/plainDate/all") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.property, "2022-12-12"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/plainDate/all") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.property, "2022-12-12"); }); it("should get default plainDate", async () => { - try { - const result = await client - .path("/type/property/optional/plainDate/default") - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, {}); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/plainDate/default") + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, {}); }); it("should put all plainDate", async () => { - try { - const result = await client - .path("/type/property/optional/plainDate/all") - .put({ - body: { property: "2022-12-12" } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/plainDate/all") + .put({ + body: { property: "2022-12-12" } + }); + assert.strictEqual(result.status, "204"); }); it("should put default plainDate", async () => { - try { - const result = await client - .path("/type/property/optional/plainDate/default") - .put({ - body: {} - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/plainDate/default") + .put({ + body: {} + }); + assert.strictEqual(result.status, "204"); }); it("should get all plainTime", async () => { - try { - const result = await client - .path("/type/property/optional/plainTime/all") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.property, "13:06:12"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/plainTime/all") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.property, "13:06:12"); }); it("should get default plainTime", async () => { - try { - const result = await client - .path("/type/property/optional/plainTime/default") - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, {}); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/plainTime/default") + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, {}); }); it("should put all plainTime", async () => { - try { - const result = await client - .path("/type/property/optional/plainTime/all") - .put({ - body: { property: "13:06:12" } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/plainTime/all") + .put({ + body: { property: "13:06:12" } + }); + assert.strictEqual(result.status, "204"); }); it("should put default plainTime", async () => { - try { - const result = await client - .path("/type/property/optional/plainTime/default") - .put({ - body: {} - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/plainTime/default") + .put({ + body: {} + }); + assert.strictEqual(result.status, "204"); }); it("should get all collections bytes", async () => { - try { - const result = await client - .path("/type/property/optional/collections/bytes/all") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.property?.length, 2); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/collections/bytes/all") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.property?.length, 2); }); it("should get default collections bytes", async () => { - try { - const result = await client - .path("/type/property/optional/collections/bytes/default") - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, {}); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/collections/bytes/default") + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, {}); }); it("should put all collections bytes", async () => { - try { - const result = await client - .path("/type/property/optional/collections/bytes/all") - .put({ - body: { property: ["aGVsbG8sIHdvcmxkIQ==", "aGVsbG8sIHdvcmxkIQ=="] } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/collections/bytes/all") + .put({ + body: { property: ["aGVsbG8sIHdvcmxkIQ==", "aGVsbG8sIHdvcmxkIQ=="] } + }); + assert.strictEqual(result.status, "204"); }); it("should put default collections bytes", async () => { - try { - const result = await client - .path("/type/property/optional/collections/bytes/default") - .put({ - body: {} - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/collections/bytes/default") + .put({ + body: {} + }); + assert.strictEqual(result.status, "204"); }); it("should get all collections model", async () => { - try { - const result = await client - .path("/type/property/optional/collections/model/all") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.property?.length, 2); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/collections/model/all") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.property?.length, 2); }); it("should get default collections model", async () => { - try { - const result = await client - .path("/type/property/optional/collections/model/default") - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, {}); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/collections/model/default") + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, {}); }); it("should put all collections model", async () => { - try { - const result = await client - .path("/type/property/optional/collections/model/all") - .put({ - body: { property: [{ property: "hello" }, { property: "world" }] } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/collections/model/all") + .put({ + body: { property: [{ property: "hello" }, { property: "world" }] } + }); + assert.strictEqual(result.status, "204"); }); it("should put default collections model", async () => { - try { - const result = await client - .path("/type/property/optional/collections/model/default") - .put({ - body: {} - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/collections/model/default") + .put({ + body: {} + }); + assert.strictEqual(result.status, "204"); }); it("should get all string literal", async () => { - try { - const result = await client - .path("/type/property/optional/string/literal/all") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.property, "hello"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/string/literal/all") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.property, "hello"); }); it("should get default string literal", async () => { - try { - const result = await client - .path("/type/property/optional/string/literal/default") - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, {}); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/string/literal/default") + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, {}); }); it("should put all string literal", async () => { - try { - const result = await client - .path("/type/property/optional/string/literal/all") - .put({ - body: { property: "hello" } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/string/literal/all") + .put({ + body: { property: "hello" } + }); + assert.strictEqual(result.status, "204"); }); it("should put default string literal", async () => { - try { - const result = await client - .path("/type/property/optional/string/literal/default") - .put({ - body: {} - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/string/literal/default") + .put({ + body: {} + }); + assert.strictEqual(result.status, "204"); }); it("should get all int literal", async () => { - try { - const result = await client - .path("/type/property/optional/int/literal/all") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.property, 1); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/int/literal/all") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.property, 1); }); it("should get default int literal", async () => { - try { - const result = await client - .path("/type/property/optional/int/literal/default") - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, {}); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/int/literal/default") + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, {}); }); it("should put all int literal", async () => { - try { - const result = await client - .path("/type/property/optional/int/literal/all") - .put({ - body: { property: 1 } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/int/literal/all") + .put({ + body: { property: 1 } + }); + assert.strictEqual(result.status, "204"); }); it("should put default int literal", async () => { - try { - const result = await client - .path("/type/property/optional/int/literal/default") - .put({ - body: {} - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/int/literal/default") + .put({ + body: {} + }); + assert.strictEqual(result.status, "204"); }); it("should get all float literal", async () => { - try { - const result = await client - .path("/type/property/optional/float/literal/all") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.property, 1.25); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/float/literal/all") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.property, 1.25); }); it("should get default float literal", async () => { - try { - const result = await client - .path("/type/property/optional/float/literal/default") - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, {}); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/float/literal/default") + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, {}); }); it("should put all float literal", async () => { - try { - const result = await client - .path("/type/property/optional/float/literal/all") - .put({ - body: { property: 1.25 } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/float/literal/all") + .put({ + body: { property: 1.25 } + }); + assert.strictEqual(result.status, "204"); }); it("should put default float literal", async () => { - try { - const result = await client - .path("/type/property/optional/float/literal/default") - .put({ - body: {} - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/float/literal/default") + .put({ + body: {} + }); + assert.strictEqual(result.status, "204"); }); it("should get all boolean literal", async () => { - try { - const result = await client - .path("/type/property/optional/boolean/literal/all") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.property, true); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/boolean/literal/all") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.property, true); }); it("should get default boolean literal", async () => { - try { - const result = await client - .path("/type/property/optional/boolean/literal/default") - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, {}); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/boolean/literal/default") + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, {}); }); it("should put all boolean literal", async () => { - try { - const result = await client - .path("/type/property/optional/boolean/literal/all") - .put({ - body: { property: true } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/boolean/literal/all") + .put({ + body: { property: true } + }); + assert.strictEqual(result.status, "204"); }); it("should put default boolean literal", async () => { - try { - const result = await client - .path("/type/property/optional/boolean/literal/default") - .put({ - body: {} - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/boolean/literal/default") + .put({ + body: {} + }); + assert.strictEqual(result.status, "204"); }); it("should get all union string literal", async () => { - try { - const result = await client - .path("/type/property/optional/union/string/literal/all") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.property, "world"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/union/string/literal/all") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.property, "world"); }); it("should get default union string literal", async () => { - try { - const result = await client - .path("/type/property/optional/union/string/literal/default") - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, {}); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/union/string/literal/default") + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, {}); }); it("should put all union string literal", async () => { - try { - const result = await client - .path("/type/property/optional/union/string/literal/all") - .put({ - body: { property: "world" } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/union/string/literal/all") + .put({ + body: { property: "world" } + }); + assert.strictEqual(result.status, "204"); }); it("should put default union string literal", async () => { - try { - const result = await client - .path("/type/property/optional/union/string/literal/default") - .put({ - body: {} - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/union/string/literal/default") + .put({ + body: {} + }); + assert.strictEqual(result.status, "204"); }); it("should get all union int literal", async () => { - try { - const result = await client - .path("/type/property/optional/union/int/literal/all") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.property, 2); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/union/int/literal/all") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.property, 2); }); it("should get default union int literal", async () => { - try { - const result = await client - .path("/type/property/optional/union/int/literal/default") - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, {}); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/union/int/literal/default") + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, {}); }); it("should put all union int literal", async () => { - try { - const result = await client - .path("/type/property/optional/union/int/literal/all") - .put({ - body: { property: 2 } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/union/int/literal/all") + .put({ + body: { property: 2 } + }); + assert.strictEqual(result.status, "204"); }); it("should put default union int literal", async () => { - try { - const result = await client - .path("/type/property/optional/union/int/literal/default") - .put({ - body: {} - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/union/int/literal/default") + .put({ + body: {} + }); + assert.strictEqual(result.status, "204"); }); it("should get all union float literal", async () => { - try { - const result = await client - .path("/type/property/optional/union/float/literal/all") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.property, 2.375); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/union/float/literal/all") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.property, 2.375); }); it("should get default union float literal", async () => { - try { - const result = await client - .path("/type/property/optional/union/float/literal/default") - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, {}); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/union/float/literal/default") + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, {}); }); it("should put all union float literal", async () => { - try { - const result = await client - .path("/type/property/optional/union/float/literal/all") - .put({ - body: { property: 2.375 } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/union/float/literal/all") + .put({ + body: { property: 2.375 } + }); + assert.strictEqual(result.status, "204"); }); it("should put default union float literal", async () => { - try { - const result = await client - .path("/type/property/optional/union/float/literal/default") - .put({ - body: {} - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/union/float/literal/default") + .put({ + body: {} + }); + assert.strictEqual(result.status, "204"); }); it("should get models that will return all properties in the model", async () => { - try { - const result = await client - .path("/type/property/optional/requiredAndOptional/all") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.optionalProperty, "hello"); - assert.strictEqual(result.body.requiredProperty, 42); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/requiredAndOptional/all") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.optionalProperty, "hello"); + assert.strictEqual(result.body.requiredProperty, 42); }); it("should get models that will return only the required properties", async () => { - try { - const result = await client - .path("/type/property/optional/requiredAndOptional/requiredOnly") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.requiredProperty, 42); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/requiredAndOptional/requiredOnly") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.requiredProperty, 42); }); it("should put a body with all properties present", async () => { - try { - const result = await client - .path("/type/property/optional/requiredAndOptional/all") - .put({ - body: { - requiredProperty: 42, - optionalProperty: "hello" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/requiredAndOptional/all") + .put({ + body: { + requiredProperty: 42, + optionalProperty: "hello" + } + }); + assert.strictEqual(result.status, "204"); }); it("should put a body with only required properties", async () => { - try { - const result = await client - .path("/type/property/optional/requiredAndOptional/requiredOnly") - .put({ - body: { - requiredProperty: 42 - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/property/optional/requiredAndOptional/requiredOnly") + .put({ + body: { + requiredProperty: 42 + } + }); + assert.strictEqual(result.status, "204"); }); }); diff --git a/packages/typespec-ts/test/integration/modelPropertyType.spec.ts b/packages/typespec-ts/test/integration/modelPropertyType.spec.ts index a6ea9d5161..63e9b7d5b8 100644 --- a/packages/typespec-ts/test/integration/modelPropertyType.spec.ts +++ b/packages/typespec-ts/test/integration/modelPropertyType.spec.ts @@ -140,36 +140,28 @@ describe("ModelsPropertyTypesClient Rest Client", () => { matrix([testedTypes], async (params: TypeDetail) => { it(`should get a ${params.type} value`, async () => { - try { - const result = await client - .path(`/type/property/value-types/${params.type}` as any) - .get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body.property, params.defaultValue); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path(`/type/property/value-types/${params.type}` as any) + .get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body.property, params.defaultValue); }); it(`should put a ${params.type} value`, async () => { - try { - let property; - if (params.convertedToFn) { - property = params.convertedToFn(params.defaultValue); - } else { - property = params.defaultValue; - } - const result = await client - .path(`/type/property/value-types/${params.type}` as any) - .put({ - body: { - property - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); + let property; + if (params.convertedToFn) { + property = params.convertedToFn(params.defaultValue); + } else { + property = params.defaultValue; } + const result = await client + .path(`/type/property/value-types/${params.type}` as any) + .put({ + body: { + property + } + }); + assert.strictEqual(result.status, "204"); }); }); }); diff --git a/packages/typespec-ts/test/integration/modelUsage.spec.ts b/packages/typespec-ts/test/integration/modelUsage.spec.ts index 28f2521b8e..f61165710a 100644 --- a/packages/typespec-ts/test/integration/modelUsage.spec.ts +++ b/packages/typespec-ts/test/integration/modelUsage.spec.ts @@ -13,35 +13,23 @@ describe("ModelsUsageClient Rest Client", () => { }); it("should post input model correctly", async () => { - try { - const result = await client.path("/type/model/usage/input").post({ - body - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/type/model/usage/input").post({ + body + }); + assert.strictEqual(result.status, "204"); }); it("should get output model correctly", async () => { - try { - const result = await client.path("/type/model/usage/output").get(); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, body); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/type/model/usage/output").get(); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, body); }); it("should get output model correctly", async () => { - try { - const result = await client - .path("/type/model/usage/input-output") - .post({ body }); - assert.strictEqual(result.status, "200"); - assert.deepEqual(result.body, body); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/model/usage/input-output") + .post({ body }); + assert.strictEqual(result.status, "200"); + assert.deepEqual(result.body, body); }); }); diff --git a/packages/typespec-ts/test/integration/payloadMediaType.spec.ts b/packages/typespec-ts/test/integration/payloadMediaType.spec.ts index cf24e12d88..f21429d6e9 100644 --- a/packages/typespec-ts/test/integration/payloadMediaType.spec.ts +++ b/packages/typespec-ts/test/integration/payloadMediaType.spec.ts @@ -13,48 +13,36 @@ describe("MediaType Client", () => { }); 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); - } + 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}"); + }); 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); - } + const result = await client + .path("/payload/media-type/string-body/sendAsText") + .post({ body: "{cat}", contentType: "text/plain" }); + assert.strictEqual(result.status, "200"); + }); 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); - } + const result = await client + .path("/payload/media-type/string-body/sendAsJson") + .post({ body: "foo", contentType: "application/json" }); + assert.strictEqual(result.status, "200"); + }); 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); - } + 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"); + }); }); diff --git a/packages/typespec-ts/test/integration/payloadPageable.spec.ts b/packages/typespec-ts/test/integration/payloadPageable.spec.ts index 483030233b..9637d30485 100644 --- a/packages/typespec-ts/test/integration/payloadPageable.spec.ts +++ b/packages/typespec-ts/test/integration/payloadPageable.spec.ts @@ -18,76 +18,60 @@ describe("Pageable Client", () => { }); it("should get pagable list without skiptoken", async () => { - try { - const result = await client - .path("/payload/pageable") - .get({ queryParameters: { maxpagesize: 3 } }); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.value[0]?.name, "user5"); - assert.strictEqual(result.body.value[1]?.name, "user6"); - assert.strictEqual(result.body.value[2]?.name, "user7"); - assert.strictEqual( - result.body.nextLink, - "http://localhost:3000/payload/pageable?skipToken=name-user7&maxpagesize=3" - ); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/payload/pageable") + .get({ queryParameters: { maxpagesize: 3 } }); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.value[0]?.name, "user5"); + assert.strictEqual(result.body.value[1]?.name, "user6"); + assert.strictEqual(result.body.value[2]?.name, "user7"); + assert.strictEqual( + result.body.nextLink, + "http://localhost:3000/payload/pageable?skipToken=name-user7&maxpagesize=3" + ); }); it("should get pagable list with skiptoken", async () => { - try { - const result = await client - .path("/payload/pageable") - .get({ queryParameters: { maxpagesize: 3, skipToken: "name-user7" } }); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.value[0]?.name, "user8"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/payload/pageable") + .get({ queryParameters: { maxpagesize: 3, skipToken: "name-user7" } }); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.value[0]?.name, "user8"); }); it("should get pagable list with wrong skiptoken", async () => { - try { - const result = await client - .path("/payload/pageable") - .get({ queryParameters: { maxpagesize: 3, skipToken: "wrong value" } }); - assert.strictEqual(result.status, "400"); - assert.strictEqual( - (result.body as any).message, - "Unsupported skipToken query parameter" - ); - assert.strictEqual( - (result.body as any).expected, - `Not provided for first page, "name-user7" for second page` - ); - assert.strictEqual((result.body as any).actual, "wrong value"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/payload/pageable") + .get({ queryParameters: { maxpagesize: 3, skipToken: "wrong value" } }); + assert.strictEqual(result.status, "400"); + assert.strictEqual( + (result.body as any).message, + "Unsupported skipToken query parameter" + ); + assert.strictEqual( + (result.body as any).expected, + `Not provided for first page, "name-user7" for second page` + ); + assert.strictEqual((result.body as any).actual, "wrong value"); }); it("should get pagable list", async () => { - try { - const initialResponse = await client - .path("/payload/pageable") - .get({ queryParameters: { maxpagesize: 3 } }); + const initialResponse = await client + .path("/payload/pageable") + .get({ queryParameters: { maxpagesize: 3 } }); - const iter = paginate(client, initialResponse); + const iter = paginate(client, initialResponse); - let result: UserOutput[] = []; - for await (const item of iter) { - result.push(item); - } - - assert.deepEqual(result, [ - { name: "user5" }, - { name: "user6" }, - { name: "user7" }, - { name: "user8" } - ]); - } catch (err) { - assert.fail(err as string); + let result: UserOutput[] = []; + for await (const item of iter) { + result.push(item); } + + assert.deepEqual(result, [ + { name: "user5" }, + { name: "user6" }, + { name: "user7" }, + { name: "user8" } + ]); }); }); diff --git a/packages/typespec-ts/test/integration/repeatableHeaders.spec.ts b/packages/typespec-ts/test/integration/repeatableHeaders.spec.ts index 7a8f25976f..d772539dbc 100644 --- a/packages/typespec-ts/test/integration/repeatableHeaders.spec.ts +++ b/packages/typespec-ts/test/integration/repeatableHeaders.spec.ts @@ -15,19 +15,15 @@ describe("RepeatabilityClient", () => { }); it("should set repeatable headers correctly", async () => { - try { - const result = await client - .path("/special-headers/repeatability/immediateSuccess") - .post({ - headers: { - "Repeatability-First-Sent": "Tue, 15 Nov 2022 12:45:26 GMT", - "Repeatability-Request-ID": "2378d9bc-1726-11ee-be56-0242ac120002" // fake uuid - } - }); - assert.strictEqual(result.status, "204"); - assert.strictEqual(result.headers["repeatability-result"], "accepted"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-headers/repeatability/immediateSuccess") + .post({ + headers: { + "Repeatability-First-Sent": "Tue, 15 Nov 2022 12:45:26 GMT", + "Repeatability-Request-ID": "2378d9bc-1726-11ee-be56-0242ac120002" // fake uuid + } + }); + assert.strictEqual(result.status, "204"); + assert.strictEqual(result.headers["repeatability-result"], "accepted"); }); }); diff --git a/packages/typespec-ts/test/integration/scalar.spec.ts b/packages/typespec-ts/test/integration/scalar.spec.ts index 69c2e7e900..d32bc151c5 100644 --- a/packages/typespec-ts/test/integration/scalar.spec.ts +++ b/packages/typespec-ts/test/integration/scalar.spec.ts @@ -16,172 +16,116 @@ 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; + }); + const result = await client + .path("/type/scalar/decimal/verify") + .post({ body: total }); + assert.strictEqual(result.status, "400"); }); 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; + }); + const result = await client + .path("/type/scalar/decimal128/verify") + .post({ body: total }); + assert.strictEqual(result.status, "400"); }); }); diff --git a/packages/typespec-ts/test/integration/serializationEncodeNameJson.spec.ts b/packages/typespec-ts/test/integration/serializationEncodeNameJson.spec.ts index d17863207c..6e75b400a9 100644 --- a/packages/typespec-ts/test/integration/serializationEncodeNameJson.spec.ts +++ b/packages/typespec-ts/test/integration/serializationEncodeNameJson.spec.ts @@ -15,27 +15,19 @@ describe("ClientEncodedNameClient Rest Client", () => { }); it("should post json property", async () => { - try { - const result = await client - .path("/serialization/encoded-name/json/property") - .post({ - body: { wireName: true } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/serialization/encoded-name/json/property") + .post({ + body: { wireName: true } + }); + assert.strictEqual(result.status, "204"); }); it("should get json property", async () => { - try { - const result = await client - .path("/serialization/encoded-name/json/property") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.wireName, true); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/serialization/encoded-name/json/property") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.wireName, true); }); }); diff --git a/packages/typespec-ts/test/integration/server.spec.ts b/packages/typespec-ts/test/integration/server.spec.ts index b9e517b29a..9d4ccfecc2 100644 --- a/packages/typespec-ts/test/integration/server.spec.ts +++ b/packages/typespec-ts/test/integration/server.spec.ts @@ -25,12 +25,8 @@ describe("SingleParamInServerPath Rest Client", () => { }); it("should work with no param", async () => { - try { - const result = await client.path("/server/path/single/myOp").head(); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/server/path/single/myOp").head(); + assert.strictEqual(result.status, "200"); }); }); @@ -47,21 +43,13 @@ describe("MultipleParamInServerPath Rest Client", () => { }); it("should work with no param", async () => { - try { - const result = await client.path("/").get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/").get(); + assert.strictEqual(result.status, "204"); }); it("should work with param", async () => { - try { - const result = await client.path("/{keyword}", "test").get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/{keyword}", "test").get(); + assert.strictEqual(result.status, "204"); }); }); @@ -81,39 +69,27 @@ describe(" NotVersionedParamInServerVersions Rest Client", () => { }); it("should work with no param", async () => { - try { - const result = await client - .path("/server/versions/not-versioned/without-api-version") - .head(); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/server/versions/not-versioned/without-api-version") + .head(); + assert.strictEqual(result.status, "200"); }); it("should work with param", async () => { - try { - const result = await client - .path("/server/versions/not-versioned/with-query-api-version") - .head({ queryParameters: { "api-version": "v1.0" } }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/server/versions/not-versioned/with-query-api-version") + .head({ queryParameters: { "api-version": "v1.0" } }); + assert.strictEqual(result.status, "200"); }); it("should work with path param", async () => { - try { - const result = await client - .path( - "/server/versions/not-versioned/with-path-api-version/{apiVersion}", - "v1.0" - ) - .head(); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/server/versions/not-versioned/with-path-api-version/{apiVersion}", + "v1.0" + ) + .head(); + assert.strictEqual(result.status, "200"); }); }); @@ -133,49 +109,33 @@ describe(" VersionedParamInServerVersions Rest Client", () => { }); it("should work with no param", async () => { - try { - const result = await client - .path("/server/versions/versioned/without-api-version") - .head(); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/server/versions/versioned/without-api-version") + .head(); + assert.strictEqual(result.status, "200"); }); it("should work with param", async () => { - try { - const result = await client - .path("/server/versions/versioned/with-query-api-version") - .head({ queryParameters: { "api-version": "2022-12-01-preview" } }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/server/versions/versioned/with-query-api-version") + .head({ queryParameters: { "api-version": "2022-12-01-preview" } }); + assert.strictEqual(result.status, "200"); }); it("should work with path param", async () => { - try { - const result = await client - .path( - "/server/versions/versioned/with-path-api-version/{apiVersion}", - "2022-12-01-preview" - ) - .head(); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/server/versions/versioned/with-path-api-version/{apiVersion}", + "2022-12-01-preview" + ) + .head(); + assert.strictEqual(result.status, "200"); }); it("should work with old param", async () => { - try { - const result = await client - .path("/server/versions/versioned/with-query-old-api-version") - .head({ queryParameters: { "api-version": "2021-01-01-preview" } }); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/server/versions/versioned/with-query-old-api-version") + .head({ queryParameters: { "api-version": "2021-01-01-preview" } }); + assert.strictEqual(result.status, "200"); }); }); diff --git a/packages/typespec-ts/test/integration/serverEndpointNotDefined.spec.ts b/packages/typespec-ts/test/integration/serverEndpointNotDefined.spec.ts index 624368d262..778ecf9e36 100644 --- a/packages/typespec-ts/test/integration/serverEndpointNotDefined.spec.ts +++ b/packages/typespec-ts/test/integration/serverEndpointNotDefined.spec.ts @@ -15,13 +15,9 @@ describe("NotDefinedParamInServerEndpoint Rest Client", () => { }); it("should work with not defined endpoint", async () => { - try { - const result = await client - .path("/server/endpoint/not-defined/valid") - .head(); - assert.strictEqual(result.status, "200"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/server/endpoint/not-defined/valid") + .head(); + assert.strictEqual(result.status, "200"); }); }); diff --git a/packages/typespec-ts/test/integration/specialWords.spec.ts b/packages/typespec-ts/test/integration/specialWords.spec.ts index 533af29266..ce4ae4c07c 100644 --- a/packages/typespec-ts/test/integration/specialWords.spec.ts +++ b/packages/typespec-ts/test/integration/specialWords.spec.ts @@ -2,6 +2,7 @@ import SpecialWordsClientFactory, { SpecialWordsClient } from "./generated/special-words/src/index.js"; import { assert } from "chai"; + describe("SpecialWordsClient Rest Client", () => { let client: SpecialWordsClient; @@ -11,1228 +12,773 @@ describe("SpecialWordsClient Rest Client", () => { describe("operations", () => { it("should get special words for operation `and`", async () => { - try { - const result = await client.path("/special-words/operations/and").get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/operations/and").get(); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `as`", async () => { - try { - const result = await client.path("/special-words/operations/as").get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/operations/as").get(); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `assert`", async () => { - try { - const result = await client - .path("/special-words/operations/assert") - .get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/operations/assert") + .get(); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `async`", async () => { - try { - const result = await client - .path("/special-words/operations/async") - .get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/operations/async") + .get(); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `await`", async () => { - try { - const result = await client - .path("/special-words/operations/await") - .get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/operations/await") + .get(); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `break`", async () => { - try { - const result = await client - .path("/special-words/operations/break") - .get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/operations/break") + .get(); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `class`", async () => { - try { - const result = await client - .path("/special-words/operations/class") - .get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/operations/class") + .get(); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `constructor`", async () => { - try { - const result = await client - .path("/special-words/operations/constructor") - .get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/operations/constructor") + .get(); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `continue`", async () => { - try { - const result = await client - .path("/special-words/operations/continue") - .get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/operations/continue") + .get(); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `def`", async () => { - try { - const result = await client.path("/special-words/operations/def").get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/operations/def").get(); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `del`", async () => { - try { - const result = await client.path("/special-words/operations/del").get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/operations/del").get(); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `elif`", async () => { - try { - const result = await client - .path("/special-words/operations/elif") - .get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/operations/elif") + .get(); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `else`", async () => { - try { - const result = await client - .path("/special-words/operations/else") - .get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/operations/else") + .get(); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `except`", async () => { - try { - const result = await client - .path("/special-words/operations/except") - .get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/operations/except") + .get(); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `exec`", async () => { - try { - const result = await client - .path("/special-words/operations/exec") - .get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/operations/exec") + .get(); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `finally`", async () => { - try { - const result = await client - .path("/special-words/operations/finally") - .get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/operations/finally") + .get(); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `for`", async () => { - try { - const result = await client.path("/special-words/operations/for").get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/operations/for").get(); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `from`", async () => { - try { - const result = await client - .path("/special-words/operations/from") - .get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/operations/from") + .get(); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `global`", async () => { - try { - const result = await client - .path("/special-words/operations/global") - .get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/operations/global") + .get(); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `if`", async () => { - try { - const result = await client.path("/special-words/operations/if").get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/operations/if").get(); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `import`", async () => { - try { - const result = await client - .path("/special-words/operations/import") - .get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/operations/import") + .get(); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `in`", async () => { - try { - const result = await client.path("/special-words/operations/in").get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/operations/in").get(); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `is`", async () => { - try { - const result = await client.path("/special-words/operations/is").get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/operations/is").get(); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `lambda`", async () => { - try { - const result = await client - .path("/special-words/operations/lambda") - .get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/operations/lambda") + .get(); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `not`", async () => { - try { - const result = await client.path("/special-words/operations/not").get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/operations/not").get(); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `or`", async () => { - try { - const result = await client.path("/special-words/operations/or").get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/operations/or").get(); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `pass`", async () => { - try { - const result = await client - .path("/special-words/operations/pass") - .get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/operations/pass") + .get(); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `raise`", async () => { - try { - const result = await client - .path("/special-words/operations/raise") - .get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/operations/raise") + .get(); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `return`", async () => { - try { - const result = await client - .path("/special-words/operations/return") - .get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/operations/return") + .get(); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `try`", async () => { - try { - const result = await client.path("/special-words/operations/try").get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/operations/try").get(); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `while`", async () => { - try { - const result = await client - .path("/special-words/operations/while") - .get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/operations/while") + .get(); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `with`", async () => { - try { - const result = await client - .path("/special-words/operations/with") - .get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/operations/with") + .get(); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `yield`", async () => { - try { - const result = await client - .path("/special-words/operations/yield") - .get(); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/operations/yield") + .get(); + assert.strictEqual(result.status, "204"); }); }); describe("parameters", () => { it("should get special words for operation `and`", async () => { - try { - const result = await client.path("/special-words/parameters/and").get({ - queryParameters: { - and: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/parameters/and").get({ + queryParameters: { + and: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `as`", async () => { - try { - const result = await client.path("/special-words/parameters/as").get({ + const result = await client.path("/special-words/parameters/as").get({ + queryParameters: { + as: "ok" + } + }); + assert.strictEqual(result.status, "204"); + }); + it("should get special words for operation `assert`", async () => { + const result = await client + .path("/special-words/parameters/assert") + .get({ queryParameters: { - as: "ok" + assert: "ok" } }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } - }); - - it("should get special words for operation `assert`", async () => { - try { - const result = await client - .path("/special-words/parameters/assert") - .get({ - queryParameters: { - assert: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `async`", async () => { - try { - const result = await client - .path("/special-words/parameters/async") - .get({ - queryParameters: { - async: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/parameters/async") + .get({ + queryParameters: { + async: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `await`", async () => { - try { - const result = await client - .path("/special-words/parameters/await") - .get({ - queryParameters: { - await: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/parameters/await") + .get({ + queryParameters: { + await: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `break`", async () => { - try { - const result = await client - .path("/special-words/parameters/break") - .get({ - queryParameters: { - break: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } - }); - - it("should get special words for operation `class`", async () => { - try { - const result = await client - .path("/special-words/parameters/class") - .get({ - queryParameters: { - class: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } - }); - - it("should get special words for operation `constructor`", async () => { - try { - const result = await client - .path("/special-words/parameters/constructor") - .get({ - queryParameters: { - constructor: "ok" as any - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } - }); - - it("should get special words for operation `continue`", async () => { - try { - const result = await client - .path("/special-words/parameters/continue") - .get({ - queryParameters: { - continue: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } - }); - - it("should get special words for operation `def`", async () => { - try { - const result = await client.path("/special-words/parameters/def").get({ + const result = await client + .path("/special-words/parameters/break") + .get({ queryParameters: { - def: "ok" + break: "ok" } }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + assert.strictEqual(result.status, "204"); }); - - it("should get special words for operation `del`", async () => { - try { - const result = await client.path("/special-words/parameters/del").get({ + it("should get special words for operation `class`", async () => { + const result = await client + .path("/special-words/parameters/class") + .get({ queryParameters: { - del: "ok" + class: "ok" } }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + assert.strictEqual(result.status, "204"); }); - - it("should get special words for operation `elif`", async () => { - try { - const result = await client.path("/special-words/parameters/elif").get({ + it("should get special words for operation `constructor`", async () => { + const result = await client + .path("/special-words/parameters/constructor") + .get({ queryParameters: { - elif: "ok" + constructor: "ok" as any } }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + assert.strictEqual(result.status, "204"); }); - - it("should get special words for operation `else`", async () => { - try { - const result = await client.path("/special-words/parameters/else").get({ + it("should get special words for operation `continue`", async () => { + const result = await client + .path("/special-words/parameters/continue") + .get({ queryParameters: { - else: "ok" + continue: "ok" } }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + assert.strictEqual(result.status, "204"); }); - - it("should get special words for operation `except`", async () => { - try { - const result = await client - .path("/special-words/parameters/except") - .get({ - queryParameters: { - except: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + it("should get special words for operation `def`", async () => { + const result = await client.path("/special-words/parameters/def").get({ + queryParameters: { + def: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); - - it("should get special words for operation `exec`", async () => { - try { - const result = await client.path("/special-words/parameters/exec").get({ + it("should get special words for operation `del`", async () => { + const result = await client.path("/special-words/parameters/del").get({ + queryParameters: { + del: "ok" + } + }); + assert.strictEqual(result.status, "204"); + }); + it("should get special words for operation `elif`", async () => { + const result = await client.path("/special-words/parameters/elif").get({ + queryParameters: { + elif: "ok" + } + }); + assert.strictEqual(result.status, "204"); + }); + it("should get special words for operation `else`", async () => { + const result = await client.path("/special-words/parameters/else").get({ + queryParameters: { + else: "ok" + } + }); + assert.strictEqual(result.status, "204"); + }); + it("should get special words for operation `except`", async () => { + const result = await client + .path("/special-words/parameters/except") + .get({ queryParameters: { - exec: "ok" + except: "ok" } }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `finally`", async () => { - try { - const result = await client - .path("/special-words/parameters/finally") - .get({ - queryParameters: { - finally: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + it("should get special words for operation `exec`", async () => { + const result = await client.path("/special-words/parameters/exec").get({ + queryParameters: { + exec: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `for`", async () => { - try { - const result = await client.path("/special-words/parameters/for").get({ + it("should get special words for operation `finally`", async () => { + const result = await client + .path("/special-words/parameters/finally") + .get({ queryParameters: { - for: "ok" + finally: "ok" } }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + assert.strictEqual(result.status, "204"); + }); + it("should get special words for operation `for`", async () => { + const result = await client.path("/special-words/parameters/for").get({ + queryParameters: { + for: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `from`", async () => { - try { - const result = await client.path("/special-words/parameters/from").get({ - queryParameters: { - from: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/parameters/from").get({ + queryParameters: { + from: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `global`", async () => { - try { - const result = await client - .path("/special-words/parameters/global") - .get({ - queryParameters: { - global: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } - }); - it("should get special words for operation `if`", async () => { - try { - const result = await client.path("/special-words/parameters/if").get({ + const result = await client + .path("/special-words/parameters/global") + .get({ queryParameters: { - if: "ok" + global: "ok" } }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `import`", async () => { - try { - const result = await client - .path("/special-words/parameters/import") - .get({ - queryParameters: { - import: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + it("should get special words for operation `if`", async () => { + const result = await client.path("/special-words/parameters/if").get({ + queryParameters: { + if: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `in`", async () => { - try { - const result = await client.path("/special-words/parameters/in").get({ + it("should get special words for operation `import`", async () => { + const result = await client + .path("/special-words/parameters/import") + .get({ queryParameters: { - in: "ok" + import: "ok" } }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + assert.strictEqual(result.status, "204"); + }); + it("should get special words for operation `in`", async () => { + const result = await client.path("/special-words/parameters/in").get({ + queryParameters: { + in: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `is`", async () => { - try { - const result = await client.path("/special-words/parameters/is").get({ - queryParameters: { - is: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/parameters/is").get({ + queryParameters: { + is: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `lambda`", async () => { - try { - const result = await client - .path("/special-words/parameters/lambda") - .get({ - queryParameters: { - lambda: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } - }); - it("should get special words for operation `not`", async () => { - try { - const result = await client.path("/special-words/parameters/not").get({ + const result = await client + .path("/special-words/parameters/lambda") + .get({ queryParameters: { - not: "ok" + lambda: "ok" } }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + assert.strictEqual(result.status, "204"); + }); + it("should get special words for operation `not`", async () => { + const result = await client.path("/special-words/parameters/not").get({ + queryParameters: { + not: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `or`", async () => { - try { - const result = await client.path("/special-words/parameters/or").get({ - queryParameters: { - or: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/parameters/or").get({ + queryParameters: { + or: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `pass`", async () => { - try { - const result = await client.path("/special-words/parameters/pass").get({ + const result = await client.path("/special-words/parameters/pass").get({ + queryParameters: { + pass: "ok" + } + }); + assert.strictEqual(result.status, "204"); + }); + it("should get special words for operation `raise`", async () => { + const result = await client + .path("/special-words/parameters/raise") + .get({ queryParameters: { - pass: "ok" + raise: "ok" } }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } - }); - - it("should get special words for operation `raise`", async () => { - try { - const result = await client - .path("/special-words/parameters/raise") - .get({ - queryParameters: { - raise: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `return`", async () => { - try { - const result = await client - .path("/special-words/parameters/return") - .get({ - queryParameters: { - return: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } - }); - - it("should get special words for operation `try`", async () => { - try { - const result = await client.path("/special-words/parameters/try").get({ + const result = await client + .path("/special-words/parameters/return") + .get({ queryParameters: { - try: "ok" + return: "ok" } }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `while`", async () => { - try { - const result = await client - .path("/special-words/parameters/while") - .get({ - queryParameters: { - while: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + it("should get special words for operation `try`", async () => { + const result = await client.path("/special-words/parameters/try").get({ + queryParameters: { + try: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); - - it("should get special words for operation `with`", async () => { - try { - const result = await client.path("/special-words/parameters/with").get({ + it("should get special words for operation `while`", async () => { + const result = await client + .path("/special-words/parameters/while") + .get({ queryParameters: { - with: "ok" + while: "ok" } }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + assert.strictEqual(result.status, "204"); + }); + it("should get special words for operation `with`", async () => { + const result = await client.path("/special-words/parameters/with").get({ + queryParameters: { + with: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `yield`", async () => { - try { - const result = await client - .path("/special-words/parameters/yield") - .get({ - queryParameters: { - yield: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/parameters/yield") + .get({ + queryParameters: { + yield: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `cancellationToken`", async () => { - try { - const result = await client - .path("/special-words/parameters/cancellationToken") - .get({ - queryParameters: { - cancellationToken: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/parameters/cancellationToken") + .get({ + queryParameters: { + cancellationToken: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); }); describe("models", () => { it("should get special words for operation `and`", async () => { - try { - const result = await client.path("/special-words/models/and").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/and").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `as`", async () => { - try { - const result = await client.path("/special-words/models/as").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/as").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `assert`", async () => { - try { - const result = await client.path("/special-words/models/assert").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/assert").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `async`", async () => { - try { - const result = await client.path("/special-words/models/async").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/async").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `await`", async () => { - try { - const result = await client.path("/special-words/models/await").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/await").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `break`", async () => { - try { - const result = await client.path("/special-words/models/break").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/break").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `class`", async () => { - try { - const result = await client.path("/special-words/models/class").post({ + const result = await client.path("/special-words/models/class").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); + }); + it("should get special words for operation `constructor`", async () => { + const result = await client + .path("/special-words/models/constructor") + .post({ body: { name: "ok" } }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } - }); - - it("should get special words for operation `constructor`", async () => { - try { - const result = await client - .path("/special-words/models/constructor") - .post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `continue`", async () => { - try { - const result = await client - .path("/special-words/models/continue") - .post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } - }); - - it("should get special words for operation `def`", async () => { - try { - const result = await client.path("/special-words/models/def").post({ + const result = await client + .path("/special-words/models/continue") + .post({ body: { name: "ok" } }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + assert.strictEqual(result.status, "204"); + }); + it("should get special words for operation `def`", async () => { + const result = await client.path("/special-words/models/def").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `del`", async () => { - try { - const result = await client.path("/special-words/models/del").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/del").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `elif`", async () => { - try { - const result = await client.path("/special-words/models/elif").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/elif").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `else`", async () => { - try { - const result = await client.path("/special-words/models/else").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/else").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `except`", async () => { - try { - const result = await client.path("/special-words/models/except").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/except").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `exec`", async () => { - try { - const result = await client.path("/special-words/models/exec").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/exec").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `finally`", async () => { - try { - const result = await client.path("/special-words/models/finally").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/finally").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `for`", async () => { - try { - const result = await client.path("/special-words/models/for").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/for").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `from`", async () => { - try { - const result = await client.path("/special-words/models/from").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/from").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `global`", async () => { - try { - const result = await client.path("/special-words/models/global").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/global").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `if`", async () => { - try { - const result = await client.path("/special-words/models/if").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/if").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `import`", async () => { - try { - const result = await client.path("/special-words/models/import").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/import").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `in`", async () => { - try { - const result = await client.path("/special-words/models/in").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/in").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `is`", async () => { - try { - const result = await client.path("/special-words/models/is").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/is").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `lambda`", async () => { - try { - const result = await client.path("/special-words/models/lambda").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/lambda").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `not`", async () => { - try { - const result = await client.path("/special-words/models/not").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/not").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `or`", async () => { - try { - const result = await client.path("/special-words/models/or").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/or").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `pass`", async () => { - try { - const result = await client.path("/special-words/models/pass").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/pass").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `raise`", async () => { - try { - const result = await client.path("/special-words/models/raise").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/raise").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `return`", async () => { - try { - const result = await client.path("/special-words/models/return").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/return").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `try`", async () => { - try { - const result = await client.path("/special-words/models/try").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/try").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `while`", async () => { - try { - const result = await client.path("/special-words/models/while").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/while").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); - it("should get special words for operation `with`", async () => { - try { - const result = await client.path("/special-words/models/with").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/with").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get special words for operation `yield`", async () => { - try { - const result = await client.path("/special-words/models/yield").post({ - body: { - name: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/special-words/models/yield").post({ + body: { + name: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); }); describe("model properties", () => { it("should post special words for operation `same-as-model`", async () => { - try { - const result = await client - .path("/special-words/model-properties/same-as-model") - .post({ - body: { - SameAsModel: "ok" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/special-words/model-properties/same-as-model") + .post({ + body: { + SameAsModel: "ok" + } + }); + assert.strictEqual(result.status, "204"); }); }); }); diff --git a/packages/typespec-ts/test/integration/spreadParameters.spec.ts b/packages/typespec-ts/test/integration/spreadParameters.spec.ts index c538caf3a2..f91caaaa6d 100644 --- a/packages/typespec-ts/test/integration/spreadParameters.spec.ts +++ b/packages/typespec-ts/test/integration/spreadParameters.spec.ts @@ -10,164 +10,124 @@ describe("HelloClient Rest Client", () => { }); it("should spread named model", async () => { - try { - const result = await client - .path("/parameters/spread/model/request-body") - .put({ - body: { - name: "foo" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/parameters/spread/model/request-body") + .put({ + body: { + name: "foo" + } + }); + assert.strictEqual(result.status, "204"); }); it("should spread model composite request only with body param", async () => { - try { - const result = await client - .path("/parameters/spread/model/composite-request-only-with-body") - .put({ - body: { - name: "foo" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/parameters/spread/model/composite-request-only-with-body") + .put({ + body: { + name: "foo" + } + }); + assert.strictEqual(result.status, "204"); }); it("should spread model composite request without body param", async () => { - try { - const result = await client - .path( - "/parameters/spread/model/composite-request-without-body/{name}", - "foo" - ) - .put({ headers: { "test-header": "bar" } }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path( + "/parameters/spread/model/composite-request-without-body/{name}", + "foo" + ) + .put({ headers: { "test-header": "bar" } }); + assert.strictEqual(result.status, "204"); }); it("should spread model composite request", async () => { - try { - const result = await client - .path("/parameters/spread/model/composite-request/{name}", "foo") - .put({ - headers: { "test-header": "bar" }, - body: { - name: "foo" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/parameters/spread/model/composite-request/{name}", "foo") + .put({ + headers: { "test-header": "bar" }, + body: { + name: "foo" + } + }); + assert.strictEqual(result.status, "204"); }); it("should spread model composite request mix", async () => { - try { - const result = await client - .path("/parameters/spread/model/composite-request-mix/{name}", "foo") - .put({ - headers: { "test-header": "bar" }, - body: { - prop: "foo" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/parameters/spread/model/composite-request-mix/{name}", "foo") + .put({ + headers: { "test-header": "bar" }, + body: { + prop: "foo" + } + }); + assert.strictEqual(result.status, "204"); }); it("should spread alias with only body param", async () => { - try { - const result = await client - .path("/parameters/spread/alias/request-body") - .put({ - body: { - name: "foo" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/parameters/spread/alias/request-body") + .put({ + body: { + name: "foo" + } + }); + assert.strictEqual(result.status, "204"); }); it("should spread alias with mixed params", async () => { - try { - const result = await client - .path("/parameters/spread/alias/request-parameter/{id}", "1") - .put({ - body: { - name: "foo" - }, - headers: { - "x-ms-test-header": "bar" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/parameters/spread/alias/request-parameter/{id}", "1") + .put({ + body: { + name: "foo" + }, + headers: { + "x-ms-test-header": "bar" + } + }); + assert.strictEqual(result.status, "204"); }); it("should spread alias with more than 5 params", async () => { - try { - const result = await client - .path("/parameters/spread/alias/multiple-parameters/{id}", "1") - .put({ - body: { - requiredString: "foo", - optionalInt: 1, - requiredIntList: [1, 2], - optionalStringList: ["foo", "bar"] - }, - headers: { - "x-ms-test-header": "bar" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/parameters/spread/alias/multiple-parameters/{id}", "1") + .put({ + body: { + requiredString: "foo", + optionalInt: 1, + requiredIntList: [1, 2], + optionalStringList: ["foo", "bar"] + }, + headers: { + "x-ms-test-header": "bar" + } + }); + assert.strictEqual(result.status, "204"); }); it("should spread alias with inner-model-parameter", async () => { - try { - const result = await client - .path("/parameters/spread/alias/inner-model-parameter/{id}", "1") - .post({ - body: { name: "foo" }, - headers: { - "x-ms-test-header": "bar" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/parameters/spread/alias/inner-model-parameter/{id}", "1") + .post({ + body: { name: "foo" }, + headers: { + "x-ms-test-header": "bar" + } + }); + assert.strictEqual(result.status, "204"); }); it("should spread alias with inner-alias-parameter", async () => { - try { - const result = await client - .path("/parameters/spread/alias/inner-alias-parameter/{id}", "1") - .post({ - body: { name: "foo", age: 1 }, - headers: { - "x-ms-test-header": "bar" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/parameters/spread/alias/inner-alias-parameter/{id}", "1") + .post({ + body: { name: "foo", age: 1 }, + headers: { + "x-ms-test-header": "bar" + } + }); + assert.strictEqual(result.status, "204"); }); }); diff --git a/packages/typespec-ts/test/integration/unionBody.spec.ts b/packages/typespec-ts/test/integration/unionBody.spec.ts index 14d64fc078..9b36fca2c6 100644 --- a/packages/typespec-ts/test/integration/unionBody.spec.ts +++ b/packages/typespec-ts/test/integration/unionBody.spec.ts @@ -12,24 +12,16 @@ describe("UnionBodyClient Rest Client", () => { }); it("should have no compile error for request body", async () => { - try { - const result = await client.path("/request-union-body").post({ - body: { - prop: "test" - } - }); - assert.strictEqual(result.status, "404"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/request-union-body").post({ + body: { + prop: "test" + } + }); + assert.strictEqual(result.status, "404"); }); it("should have no compile error for response body", async () => { - try { - const result = await client.path("/response-union-body").get(); - assert.strictEqual(result.status, "404"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/response-union-body").get(); + assert.strictEqual(result.status, "404"); }); }); diff --git a/packages/typespec-ts/test/integration/unions.spec.ts b/packages/typespec-ts/test/integration/unions.spec.ts index cafba76383..3bd1e0c31a 100644 --- a/packages/typespec-ts/test/integration/unions.spec.ts +++ b/packages/typespec-ts/test/integration/unions.spec.ts @@ -18,275 +18,195 @@ describe("UnionsClient Rest Client", () => { }); it("should get strings only union", async () => { - try { - const result = await client.path("/type/union/strings-only").get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.prop, "b"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/type/union/strings-only").get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.prop, "b"); }); it("should post strings only union", async () => { - try { - const result = await client.path("/type/union/strings-only").post({ - body: { - prop: "b" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/type/union/strings-only").post({ + body: { + prop: "b" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get strings extensible union", async () => { - try { - const result = await client.path("/type/union/string-extensible").get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.prop, "custom"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/type/union/string-extensible").get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.prop, "custom"); }); it("should post strings extensible union", async () => { - try { - const result = await client.path("/type/union/string-extensible").post({ - body: { - prop: "custom" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/type/union/string-extensible").post({ + body: { + prop: "custom" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get strings extensible named union", async () => { - try { - const result = await client - .path("/type/union/string-extensible-named") - .get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.prop, "custom"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/union/string-extensible-named") + .get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.prop, "custom"); }); it("should post strings extensible named union", async () => { - try { - const result = await client - .path("/type/union/string-extensible-named") - .post({ - body: { - prop: "custom" - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client + .path("/type/union/string-extensible-named") + .post({ + body: { + prop: "custom" + } + }); + assert.strictEqual(result.status, "204"); }); it("should get ints only union", async () => { - try { - const result = await client.path("/type/union/ints-only").get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.prop, 2); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/type/union/ints-only").get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.prop, 2); }); it("should post ints only union", async () => { - try { - const result = await client.path("/type/union/ints-only").post({ - body: { - prop: 2 - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/type/union/ints-only").post({ + body: { + prop: 2 + } + }); + assert.strictEqual(result.status, "204"); }); it("should get floats only union", async () => { - try { - const result = await client.path("/type/union/floats-only").get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.prop, 2.2); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/type/union/floats-only").get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.prop, 2.2); }); it("should post floats only union", async () => { - try { - const result = await client.path("/type/union/floats-only").post({ - body: { - prop: 2.2 - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/type/union/floats-only").post({ + body: { + prop: 2.2 + } + }); + assert.strictEqual(result.status, "204"); }); it("should get models only union", async () => { - try { - const result = await client.path("/type/union/models-only").get(); - assert.strictEqual(result.status, "200"); - if (isCatOutput(result.body.prop)) { - assert.strictEqual(result.body.prop.name, "test"); - } - } catch (err) { - assert.fail(err as string); + const result = await client.path("/type/union/models-only").get(); + assert.strictEqual(result.status, "200"); + if (isCatOutput(result.body.prop)) { + assert.strictEqual(result.body.prop.name, "test"); } }); it("should post models only union", async () => { - try { - const result = await client.path("/type/union/models-only").post({ - body: { - prop: { name: "test" } - } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/type/union/models-only").post({ + body: { + prop: { name: "test" } + } + }); + assert.strictEqual(result.status, "204"); }); it("should get enums only union", async () => { - try { - const result = await client.path("/type/union/enums-only").get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.prop.lr, "right"); - assert.strictEqual(result.body.prop.ud, "up"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/type/union/enums-only").get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.prop.lr, "right"); + assert.strictEqual(result.body.prop.ud, "up"); }); it("should post enums only union", async () => { - try { - const result = await client.path("/type/union/enums-only").post({ - body: { - prop: { - lr: "right", - ud: "up" - } + const result = await client.path("/type/union/enums-only").post({ + body: { + prop: { + lr: "right", + ud: "up" } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + } + }); + assert.strictEqual(result.status, "204"); }); it("should get string and array union", async () => { - try { - const result = await client.path("/type/union/string-and-array").get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.prop.string, "test"); - assert.strictEqual(result.body.prop.array[0], "test1"); - assert.strictEqual(result.body.prop.array[1], "test2"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/type/union/string-and-array").get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.prop.string, "test"); + assert.strictEqual(result.body.prop.array[0], "test1"); + assert.strictEqual(result.body.prop.array[1], "test2"); }); it("should post string and array union", async () => { - try { - const result = await client.path("/type/union/string-and-array").post({ - body: { - prop: { - string: "test", - array: ["test1", "test2"] - } + const result = await client.path("/type/union/string-and-array").post({ + body: { + prop: { + string: "test", + array: ["test1", "test2"] } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + } + }); + assert.strictEqual(result.status, "204"); }); it("should get mixed literals union", async () => { - try { - const result = await client.path("/type/union/mixed-literals").get(); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.prop.stringLiteral, "a"); - assert.strictEqual(result.body.prop.intLiteral, 2); - assert.strictEqual(result.body.prop.floatLiteral, 3.3); - assert.strictEqual(result.body.prop.booleanLiteral, true); - } catch (err) { - assert.fail(err as string); - } + const result = await client.path("/type/union/mixed-literals").get(); + assert.strictEqual(result.status, "200"); + assert.strictEqual(result.body.prop.stringLiteral, "a"); + assert.strictEqual(result.body.prop.intLiteral, 2); + assert.strictEqual(result.body.prop.floatLiteral, 3.3); + assert.strictEqual(result.body.prop.booleanLiteral, true); }); it("should post mixed literals union", async () => { - try { - const result = await client.path("/type/union/mixed-literals").post({ - body: { - prop: { - stringLiteral: "a", - intLiteral: 2, - floatLiteral: 3.3, - booleanLiteral: true - } + const result = await client.path("/type/union/mixed-literals").post({ + body: { + prop: { + stringLiteral: "a", + intLiteral: 2, + floatLiteral: 3.3, + booleanLiteral: true } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + } + }); + assert.strictEqual(result.status, "204"); }); it("should get mixed types union", async () => { - try { - const result = await client.path("/type/union/mixed-types").get(); - assert.strictEqual(result.status, "200"); - if (isCatOutput(result.body.prop.model)) { - assert.strictEqual(result.body.prop.model.name, "test"); - assert.strictEqual(result.body.prop.literal, "a"); - assert.strictEqual(result.body.prop.int, 2); - assert.strictEqual(result.body.prop.boolean, true); - } - } catch (err) { - assert.fail(err as string); + const result = await client.path("/type/union/mixed-types").get(); + assert.strictEqual(result.status, "200"); + if (isCatOutput(result.body.prop.model)) { + assert.strictEqual(result.body.prop.model.name, "test"); + assert.strictEqual(result.body.prop.literal, "a"); + assert.strictEqual(result.body.prop.int, 2); + assert.strictEqual(result.body.prop.boolean, true); } }); it("should post mixed types union", async () => { - try { - const result = await client.path("/type/union/mixed-types").post({ - body: { - prop: { - model: { + const result = await client.path("/type/union/mixed-types").post({ + body: { + prop: { + model: { + name: "test" + }, + literal: "a", + int: 2, + boolean: true, + array: [ + { name: "test" }, - literal: "a", - int: 2, - boolean: true, - array: [ - { - name: "test" - }, - "a", - 2, - true - ] - } + "a", + 2, + true + ] } - }); - assert.strictEqual(result.status, "204"); - } catch (err) { - assert.fail(err as string); - } + } + }); + assert.strictEqual(result.status, "204"); }); }); diff --git a/packages/typespec-ts/test/integration/versioningRemoved.spec.ts b/packages/typespec-ts/test/integration/versioningRemoved.spec.ts index a88fa2e540..501adbe146 100644 --- a/packages/typespec-ts/test/integration/versioningRemoved.spec.ts +++ b/packages/typespec-ts/test/integration/versioningRemoved.spec.ts @@ -1,27 +1,27 @@ -import VersioningRemovedClientFactory, { - VersioningRemovedClient -} from "./generated/versioning/removed/src/index.js"; -import { assert } from "chai"; -describe("VersioningRemoved Rest Client", () => { - let client: VersioningRemovedClient; +// import VersioningRemovedClientFactory, { +// VersioningRemovedClient +// } from "./generated/versioning/removed/src/index.js"; +// import { assert } from "chai"; +// describe("VersioningRemoved Rest Client", () => { +// let client: VersioningRemovedClient; - beforeEach(() => { - client = VersioningRemovedClientFactory("http://localhost:3000", "v2", { - allowInsecureConnection: true - }); - }); +// beforeEach(() => { +// client = VersioningRemovedClientFactory("http://localhost:3000", "v2", { +// allowInsecureConnection: true +// }); +// }); - it("versioning removed test", async () => { - const result = await client.path("/v2").post({ - body: { - prop: "foo", - enumProp: "enumMemberV2", - unionProp: "bar" - } - }); - assert.strictEqual(result.status, "200"); - assert.strictEqual(result.body.prop, "foo"); - assert.strictEqual(result.body.enumProp, "enumMemberV2"); - assert.strictEqual(result.body.unionProp, "bar"); - }); -}); +// it("versioning removed test", async () => { +// const result = await client.path("/v2").post({ +// body: { +// prop: "foo", +// enumProp: "enumMemberV2", +// unionProp: "bar" +// } +// }); +// assert.strictEqual(result.status, "200"); +// assert.strictEqual(result.body.prop, "foo"); +// assert.strictEqual(result.body.enumProp, "enumMemberV2"); +// assert.strictEqual(result.body.unionProp, "bar"); +// }); +// }); diff --git a/packages/typespec-ts/test/modularIntegration/arrayItemTypes.spec.ts b/packages/typespec-ts/test/modularIntegration/arrayItemTypes.spec.ts index 83ef42bbad..7c8b829627 100644 --- a/packages/typespec-ts/test/modularIntegration/arrayItemTypes.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/arrayItemTypes.spec.ts @@ -79,114 +79,106 @@ describe("Array Item-Types Client", () => { }); for (let item of testedTypes) { it(`should get ${item.type} value`, async () => { - try { - let result: any; - switch (item.type) { - case "int32": - result = await client.int32Value.get(); - break; - case "int64": - result = await client.int64Value.get(); - break; - case "boolean": - result = await client.booleanValue.get(); - break; - case "string": - result = await client.stringValue.get(); - break; - case "float32": - result = await client.float32Value.get(); - break; - case "datetime": - result = await client.datetimeValue.get(); - break; - case "duration": - result = await client.durationValue.get(); - break; - case "unknown": - result = await client.unknownValue.get(); - break; - // case "model": - // result = await client.modelValue.get(); - // break; - case "nullable-float": - result = await client.nullableFloatValue.get(); - break; - case "nullable-int32": - result = await client.nullableInt32Value.get(); - break; - case "nullable-string": - result = await client.nullableStringValue.get(); - break; - case "nullable-boolean": - result = await client.nullableBooleanValue.get(); - break; - // case "nullable-model": - // result = await client.nullableModelValue.get(); - // break; - default: - break; - } - assert.deepEqual(result, item.defaultValue); - } catch (err) { - assert.fail(err as string); + let result: any; + switch (item.type) { + case "int32": + result = await client.int32Value.get(); + break; + case "int64": + result = await client.int64Value.get(); + break; + case "boolean": + result = await client.booleanValue.get(); + break; + case "string": + result = await client.stringValue.get(); + break; + case "float32": + result = await client.float32Value.get(); + break; + case "datetime": + result = await client.datetimeValue.get(); + break; + case "duration": + result = await client.durationValue.get(); + break; + case "unknown": + result = await client.unknownValue.get(); + break; + // case "model": + // result = await client.modelValue.get(); + // break; + case "nullable-float": + result = await client.nullableFloatValue.get(); + break; + case "nullable-int32": + result = await client.nullableInt32Value.get(); + break; + case "nullable-string": + result = await client.nullableStringValue.get(); + break; + case "nullable-boolean": + result = await client.nullableBooleanValue.get(); + break; + // case "nullable-model": + // result = await client.nullableModelValue.get(); + // break; + default: + break; } + assert.deepEqual(result, item.defaultValue); }); } for (let item of testedTypes) { it(`should put ${item.type} vaule`, async () => { - try { - let result: any; - switch (item.type) { - case "int32": - result = await client.int32Value.put(item.defaultValue); - break; - case "int64": - result = await client.int64Value.put(item.defaultValue); - break; - case "boolean": - result = await client.booleanValue.put(item.defaultValue); - break; - case "string": - result = await client.stringValue.put(item.defaultValue); - break; - case "float32": - result = await client.float32Value.put(item.defaultValue); - break; - case "datetime": - result = await client.datetimeValue.put(item.defaultValue); - break; - case "duration": - result = await client.durationValue.put(item.defaultValue); - break; - case "unknown": - result = await client.unknownValue.put(item.defaultValue); - break; - case "model": - result = await client.modelValue.put(item.defaultValue); - break; - case "nullable-float": - result = await client.nullableFloatValue.put(item.defaultValue); - break; - case "nullable-boolean": - result = await client.nullableBooleanValue.put(item.defaultValue); - break; - case "nullable-int32": - result = await client.nullableInt32Value.put(item.defaultValue); - break; - case "nullable-string": - result = await client.nullableStringValue.put(item.defaultValue); - break; - case "nullable-model": - result = await client.nullableModelValue.put(item.defaultValue); - break; - default: - break; - } - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); + let result: any; + switch (item.type) { + case "int32": + result = await client.int32Value.put(item.defaultValue); + break; + case "int64": + result = await client.int64Value.put(item.defaultValue); + break; + case "boolean": + result = await client.booleanValue.put(item.defaultValue); + break; + case "string": + result = await client.stringValue.put(item.defaultValue); + break; + case "float32": + result = await client.float32Value.put(item.defaultValue); + break; + case "datetime": + result = await client.datetimeValue.put(item.defaultValue); + break; + case "duration": + result = await client.durationValue.put(item.defaultValue); + break; + case "unknown": + result = await client.unknownValue.put(item.defaultValue); + break; + case "model": + result = await client.modelValue.put(item.defaultValue); + break; + case "nullable-float": + result = await client.nullableFloatValue.put(item.defaultValue); + break; + case "nullable-boolean": + result = await client.nullableBooleanValue.put(item.defaultValue); + break; + case "nullable-int32": + result = await client.nullableInt32Value.put(item.defaultValue); + break; + case "nullable-string": + result = await client.nullableStringValue.put(item.defaultValue); + break; + case "nullable-model": + result = await client.nullableModelValue.put(item.defaultValue); + break; + default: + break; } + assert.isUndefined(result); }); } }); diff --git a/packages/typespec-ts/test/modularIntegration/authApiKey.spec.ts b/packages/typespec-ts/test/modularIntegration/authApiKey.spec.ts index ac16fed8b0..56458e20c2 100644 --- a/packages/typespec-ts/test/modularIntegration/authApiKey.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/authApiKey.spec.ts @@ -2,10 +2,11 @@ import { ApiKeyClient } from "./generated/authentication/api-key/src/index.js"; import { assert } from "chai"; describe("ApiKeyClient Classical Client", () => { - let client: ApiKeyClient; + let validKeyClient: ApiKeyClient; + let invalidKeyClient: ApiKeyClient; beforeEach(() => { - client = new ApiKeyClient( + validKeyClient = new ApiKeyClient( { key: "valid-key" }, @@ -14,20 +15,25 @@ describe("ApiKeyClient Classical Client", () => { endpoint: "http://localhost:3002" } ); + invalidKeyClient = new ApiKeyClient( + { + key: "invalid-key" + }, + { + allowInsecureConnection: true, + endpoint: "http://localhost:3002" + } + ); }); it("should not throw exception if apiKey is valid", async () => { - try { - const result = await client.valid(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await validKeyClient.valid(); + assert.strictEqual(result, undefined); }); it("should throw exception if the apiKey is invalid", async () => { try { - await client.invalid(); + await invalidKeyClient.invalid(); assert.fail("Expected an exception to be thrown."); } catch (err: any) { assert.strictEqual(err.message, "Unexpected status code: 403"); diff --git a/packages/typespec-ts/test/modularIntegration/authHttpCustom.spec.ts b/packages/typespec-ts/test/modularIntegration/authHttpCustom.spec.ts index 066d385319..5c5d70584e 100644 --- a/packages/typespec-ts/test/modularIntegration/authHttpCustom.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/authHttpCustom.spec.ts @@ -2,10 +2,11 @@ import { CustomClient } from "./generated/authentication/http/custom/src/index.j import { assert } from "chai"; describe("CustomClient Classical Client", () => { - let client: CustomClient; + let validKeyClient: CustomClient; + let invalidKeyClient: CustomClient; beforeEach(() => { - client = new CustomClient( + validKeyClient = new CustomClient( { key: "valid-key" }, @@ -14,20 +15,25 @@ describe("CustomClient Classical Client", () => { endpoint: "http://localhost:3002" } ); + invalidKeyClient = new CustomClient( + { + key: "invalid-key" + }, + { + allowInsecureConnection: true, + endpoint: "http://localhost:3002" + } + ); }); it("should not throw exception if apiKey is valid", async () => { - try { - const result = await client.valid(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await validKeyClient.valid(); + assert.strictEqual(result, undefined); }); it("should throw exception if the apiKey is invalid", async () => { try { - await client.invalid(); + await invalidKeyClient.invalid(); assert.fail("Expected an exception to be thrown."); } catch (err: any) { assert.strictEqual(err.message, "Unexpected status code: 403"); diff --git a/packages/typespec-ts/test/modularIntegration/authOauth2.spec.ts b/packages/typespec-ts/test/modularIntegration/authOauth2.spec.ts index 1acdc03c46..f485eaab02 100644 --- a/packages/typespec-ts/test/modularIntegration/authOauth2.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/authOauth2.spec.ts @@ -45,12 +45,8 @@ describe("OAuth2Context in API Layer", () => { }); it("should not throw exception if token is valid", async () => { - try { - const result = await valid(context); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await valid(context); + assert.strictEqual(result, undefined); }); it("should throw exception if the token is invalid", async () => { diff --git a/packages/typespec-ts/test/modularIntegration/authUnion.spec.ts b/packages/typespec-ts/test/modularIntegration/authUnion.spec.ts index a7a089a43d..61d34386cc 100644 --- a/packages/typespec-ts/test/modularIntegration/authUnion.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/authUnion.spec.ts @@ -55,23 +55,15 @@ describe("UnionContext in API Layer", () => { } it("should not throw exception if apiKey is valid", async () => { - try { - prepareKey(); - const result = await validKey(context); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + prepareKey(); + const result = await validKey(context); + assert.strictEqual(result, undefined); }); it("should throw exception if the token is valid", async () => { - try { - prepareToken(); - const result = await validToken(context); - assert.strictEqual(result, undefined); - } catch (err: any) { - assert.fail(err as string); - } + prepareToken(); + const result = await validToken(context); + assert.strictEqual(result, undefined); }); }); @@ -118,22 +110,14 @@ describe("UnionClient in classical client", () => { } it("should not throw exception if apiKey is valid", async () => { - try { - prepareKey(); - const result = await client.validKey(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + prepareKey(); + const result = await client.validKey(); + assert.strictEqual(result, undefined); }); it("should throw exception if the token is valid", async () => { - try { - prepareToken(); - const result = await client.validToken(); - assert.strictEqual(result, undefined); - } catch (err: any) { - assert.fail(err as string); - } + prepareToken(); + const result = await client.validToken(); + assert.strictEqual(result, undefined); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/azureArmResources.spec.ts b/packages/typespec-ts/test/modularIntegration/azureArmResources.spec.ts index aa49afcdab..34e1e7c405 100644 --- a/packages/typespec-ts/test/modularIntegration/azureArmResources.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/azureArmResources.spec.ts @@ -78,7 +78,7 @@ describe("Azure Arm Resources Rest Client", () => { it("should update singleton tracked resources", async () => { const result = await client.singleton.update("test-rg", { - location: "eastus2", + location: "eastus", properties: { description: "valid2" } @@ -87,7 +87,7 @@ describe("Azure Arm Resources Rest Client", () => { assert.strictEqual(result.id, validSingletonResource.id); assert.strictEqual(result.name, validSingletonResource.name); assert.strictEqual(result.type, validSingletonResource.type); - assert.strictEqual(result.location, "eastus2"); + assert.strictEqual(result.location, "eastus"); assert.strictEqual(result.properties?.description, "valid2"); }); diff --git a/packages/typespec-ts/test/modularIntegration/azureClientGeneratorCoreAccess.spec.ts b/packages/typespec-ts/test/modularIntegration/azureClientGeneratorCoreAccess.spec.ts index 9e724817b8..5b9231a549 100644 --- a/packages/typespec-ts/test/modularIntegration/azureClientGeneratorCoreAccess.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/azureClientGeneratorCoreAccess.spec.ts @@ -14,85 +14,49 @@ describe("Azure ClientGeneratorCore Access Client", () => { }); it("should get no decorator in public operation", async () => { - try { - const result = await client.noDecoratorInPublic("myname"); - assert.equal(result.name, "myname"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.noDecoratorInPublic("sample"); + assert.equal(result.name, "sample"); }); it("should get public decorator in public operation", async () => { - try { - const result = await client.publicDecoratorInPublic("myname"); - assert.equal(result.name, "myname"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.publicDecoratorInPublic("sample"); + assert.equal(result.name, "sample"); }); it("should get no decorator in internal operation", async () => { - try { - const result = await client.noDecoratorInInternal("myname"); - assert.equal(result.name, "myname"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.noDecoratorInInternal("sample"); + assert.equal(result.name, "sample"); }); it("should get internal decorator in internal operation", async () => { - try { - const result = await client.internalDecoratorInInternal("myname"); - assert.equal(result.name, "myname"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.internalDecoratorInInternal("sample"); + assert.equal(result.name, "sample"); }); it("should get public decorator in internal operation", async () => { - try { - const result = await client.publicDecoratorInInternal("myname"); - assert.equal(result.name, "myname"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.publicDecoratorInInternal("sample"); + assert.equal(result.name, "sample"); }); it("should get public shared model in operation", async () => { - try { - const result = await client.public("myname"); - assert.equal(result.name, "myname"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.public("sample"); + assert.equal(result.name, "sample"); }); it("should get internal shared model in operation", async () => { - try { - const result = await client.internal("myname"); - assert.equal(result.name, "myname"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.internal("sample"); + assert.equal(result.name, "sample"); }); it("should get relative model in operation", async () => { - try { - const result = await client.operation("myname"); - assert.equal(result.name, "Madge"); - assert.equal(result.inner.name, "Madge"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operation("Madge"); + assert.equal(result.name, "Madge"); + assert.equal(result.inner.name, "Madge"); }); it("should get relative model in discriminator", async () => { - try { - const result = await client.discriminator("myname"); - assert.equal(result.name, "Madge"); - assert.equal(result.kind, "real"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.discriminator("real"); + assert.equal(result.name, "Madge"); + assert.equal(result.kind, "real"); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/azureCoreTraits.spec.ts b/packages/typespec-ts/test/modularIntegration/azureCoreTraits.spec.ts index 8580d86c5f..e777a3ae89 100644 --- a/packages/typespec-ts/test/modularIntegration/azureCoreTraits.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/azureCoreTraits.spec.ts @@ -12,43 +12,35 @@ describe("Traits Client", () => { }); it("client smoke test", async () => { - try { - const result = await client.smokeTest(1, "123", { - ifNoneMatch: '"invalid"', - ifMatch: '"valid"', - ifUnmodifiedSince: new Date("Fri, 26 Aug 2022 14:38:00 GMT"), - ifModifiedSince: new Date("Thu, 26 Aug 2021 14:38:00 GMT") - }); - assert.isNotNull(result); - assert.strictEqual( - JSON.stringify(result), - JSON.stringify({ - id: 1, - name: "Madge" - }) - ); - } catch (err) { - assert.fail(err as string); - } + const result = await client.smokeTest(1, "123", { + ifNoneMatch: '"invalid"', + ifMatch: '"valid"', + ifUnmodifiedSince: new Date("Fri, 26 Aug 2022 14:38:00 GMT"), + ifModifiedSince: new Date("Thu, 26 Aug 2021 14:38:00 GMT") + }); + assert.isNotNull(result); + assert.strictEqual( + JSON.stringify(result), + JSON.stringify({ + id: 1, + name: "Madge" + }) + ); }); it("client repeatable action", async () => { - try { - const result = await client.repeatableAction( - 1, - { userActionValue: "test" }, - { - repeatabilityRequestId: "86aede1f-96fa-4e7f-b1e1-bf8a947cb804", - repeatabilityFirstSent: new Date("Wed, 15 Nov 2023 15:38:00 GMT") - } - ); - assert.isNotNull(result); - assert.strictEqual( - JSON.stringify(result), - JSON.stringify({ userActionResult: "test" }) - ); - } catch (err) { - assert.fail(err as string); - } + const result = await client.repeatableAction( + 1, + { userActionValue: "test" }, + { + repeatabilityRequestId: "86aede1f-96fa-4e7f-b1e1-bf8a947cb804", + repeatabilityFirstSent: new Date("Wed, 15 Nov 2023 15:38:00 GMT") + } + ); + assert.isNotNull(result); + assert.strictEqual( + JSON.stringify(result), + JSON.stringify({ userActionResult: "test" }) + ); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/azurecorescalar.spec.ts b/packages/typespec-ts/test/modularIntegration/azurecorescalar.spec.ts index ee69bc4fb5..3efeaccce5 100644 --- a/packages/typespec-ts/test/modularIntegration/azurecorescalar.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/azurecorescalar.spec.ts @@ -11,49 +11,29 @@ describe("Scalar Azure core Client", () => { }); it("should get an Azure Location value", async () => { - try { - const result = await client.get(); - assert.strictEqual(result, "eastus"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.get(); + assert.strictEqual(result, "eastus"); }); it("should put an Azure Location value", async () => { - try { - const result = await client.put("eastus", { - requestOptions: { headers: { "content-type": "text/plain" } } - }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.put("eastus", { + requestOptions: { headers: { "content-type": "text/plain" } } + }); + assert.isUndefined(result); }); it("should post an Azure Location value", async () => { - try { - const result = await client.post({ location: "eastus" }); - assert.deepEqual(result, { location: "eastus" }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.post({ location: "eastus" }); + assert.deepEqual(result, { location: "eastus" }); }); it("should post an Azure Location value with header", async () => { - try { - const result = await client.header("eastus"); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.header("eastus"); + assert.isUndefined(result); }); it("should post an Azure Location with query", async () => { - try { - const result = await client.query("eastus"); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.query("eastus"); + assert.isUndefined(result); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/basicParameters.spec.ts b/packages/typespec-ts/test/modularIntegration/basicParameters.spec.ts index ffd0a57e9c..77858d6036 100644 --- a/packages/typespec-ts/test/modularIntegration/basicParameters.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/basicParameters.spec.ts @@ -11,20 +11,12 @@ describe("BasicClient Client", () => { }); it("basic parameters explicit-body simple", async () => { - try { - const result = await client.explicitBody.simple({ name: "foo" }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.explicitBody.simple({ name: "foo" }); + assert.isUndefined(result); }); it("basic parameters implicit-body simple", async () => { - try { - const result = await client.implicitBody.simple("foo"); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.implicitBody.simple("foo"); + assert.isUndefined(result); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/bodyOptionality.spec.ts b/packages/typespec-ts/test/modularIntegration/bodyOptionality.spec.ts index a2adfaa842..a68c276777 100644 --- a/packages/typespec-ts/test/modularIntegration/bodyOptionality.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/bodyOptionality.spec.ts @@ -14,38 +14,22 @@ describe("Body Optionality Client", () => { }); it("should support required-explicit body", async () => { - try { - const result = await client.requiredExplicit({ name: "foo" }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.requiredExplicit({ name: "foo" }); + assert.isUndefined(result); }); it("should support optional-explicit body", async () => { - try { - const result = await client.optionalExplicit.set({ body: { name: "foo" } }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.optionalExplicit.set({ body: { name: "foo" } }); + assert.isUndefined(result); }); it("should support optional-explicit omitted body", async () => { - try { - const result = await client.optionalExplicit.omit(); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.optionalExplicit.omit(); + assert.isUndefined(result); }); it("should support required-implicit body", async () => { - try { - const result = await client.requiredImplicit("foo"); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.requiredImplicit("foo"); + assert.isUndefined(result); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/clientNaming.spec.ts b/packages/typespec-ts/test/modularIntegration/clientNaming.spec.ts index 9dd326ffcc..74d1ec6346 100644 --- a/packages/typespec-ts/test/modularIntegration/clientNaming.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/clientNaming.spec.ts @@ -14,111 +14,67 @@ describe("NameAndEncodedName Client", () => { }); it("should work with property client", async () => { - try { - const result = await client.client({ clientName: true }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.client({ clientName: true }); + assert.isUndefined(result); }); it("should work with property language", async () => { - try { - const result = await client.language({ tSName: true }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.language({ tSName: true }); + assert.isUndefined(result); }); it("should work with property compatibleWithEncodedName", async () => { - try { - const result = await client.compatibleWithEncodedName({ - clientName: true - }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.compatibleWithEncodedName({ + clientName: true + }); + assert.isUndefined(result); }); it("should work with operation", async () => { - try { - const result = await client.clientName(); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.clientName(); + assert.isUndefined(result); }); it("should work with parameter", async () => { - try { - const result = await client.parameter("true"); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameter("true"); + assert.isUndefined(result); }); it("should work with header request", async () => { - try { - const result = await client.request("true"); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.request("true"); + assert.isUndefined(result); }); it("should work with header response", async () => { - try { - const result = await client.response({ - onResponse: function (res) { - assert.strictEqual(res.headers.get("default-name"), "true"); - } - }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.response({ + onResponse: function (res) { + assert.strictEqual(res.headers.get("default-name"), "true"); + } + }); + assert.isUndefined(result); }); it("should work with model client", async () => { - try { - const result = await client.clientModel.client({ defaultName: true }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.clientModel.client({ defaultName: true }); + assert.isUndefined(result); }); it("should work with model language", async () => { - try { - const result = await client.clientModel.language({ defaultName: true }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.clientModel.language({ defaultName: true }); + assert.isUndefined(result); }); it("should work union enum name", async () => { - try { - const result = await client.unionEnum.unionEnumName("value1", { - requestOptions: { headers: { "content-type": "text/plain" } } - }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.unionEnum.unionEnumName("value1", { + requestOptions: { headers: { "content-type": "text/plain" } } + }); + assert.isUndefined(result); }); it("should work with union enum member name", async () => { - try { - const result = await client.unionEnum.unionEnumMemberName("value1", { - requestOptions: { headers: { "content-type": "text/plain" } } - }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.unionEnum.unionEnumMemberName("value1", { + requestOptions: { headers: { "content-type": "text/plain" } } + }); + assert.isUndefined(result); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/clientStructureDefault.spec.ts b/packages/typespec-ts/test/modularIntegration/clientStructureDefault.spec.ts index 70de0dbd99..d583af7b7e 100644 --- a/packages/typespec-ts/test/modularIntegration/clientStructureDefault.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/clientStructureDefault.spec.ts @@ -10,83 +10,47 @@ describe("Client Structure Default Rest Client", () => { }); it("should call operation one correctly", async () => { - try { - const result = await client.one(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.one(); + assert.strictEqual(result, undefined); }); it("should call operation two correctly", async () => { - try { - const result = await client.two(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.two(); + assert.strictEqual(result, undefined); }); it("should call operation three correctly", async () => { - try { - const result = await client.foo.three(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.foo.three(); + assert.strictEqual(result, undefined); }); it("should call operation four correctly", async () => { - try { - const result = await client.foo.four(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.foo.four(); + assert.strictEqual(result, undefined); }); it("should call operation five correctly", async () => { - try { - const result = await client.bar.five(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.bar.five(); + assert.strictEqual(result, undefined); }); it("should call operation six correctly", async () => { - try { - const result = await client.bar.six(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.bar.six(); + assert.strictEqual(result, undefined); }); it("should call operation seven correctly", async () => { - try { - const result = await client.baz.foo.seven(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.baz.foo.seven(); + assert.strictEqual(result, undefined); }); it("should call operation eight correctly", async () => { - try { - const result = await client.qux.eight(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.qux.eight(); + assert.strictEqual(result, undefined); }); it("should call operation nine correctly", async () => { - try { - const result = await client.qux.bar.nine(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.qux.bar.nine(); + assert.strictEqual(result, undefined); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/clientStructureMultiClient.spec.ts b/packages/typespec-ts/test/modularIntegration/clientStructureMultiClient.spec.ts index 2a39064332..d001ada8bc 100644 --- a/packages/typespec-ts/test/modularIntegration/clientStructureMultiClient.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/clientStructureMultiClient.spec.ts @@ -17,56 +17,32 @@ describe("Client Structure Multi-Client Rest Client", () => { }); it("should call operation one correctly", async () => { - try { - const result = await clientA.renamedOne(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await clientA.renamedOne(); + assert.strictEqual(result, undefined); }); it("should call operation two correctly", async () => { - try { - const result = await clientB.renamedTwo(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await clientB.renamedTwo(); + assert.strictEqual(result, undefined); }); it("should call operation three correctly", async () => { - try { - const result = await clientA.renamedThree(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await clientA.renamedThree(); + assert.strictEqual(result, undefined); }); it("should call operation four correctly", async () => { - try { - const result = await clientB.renamedFour(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await clientB.renamedFour(); + assert.strictEqual(result, undefined); }); it("should call operation five correctly", async () => { - try { - const result = await clientA.renamedFive(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await clientA.renamedFive(); + assert.strictEqual(result, undefined); }); it("should call operation six correctly", async () => { - try { - const result = await clientB.renamedSix(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await clientB.renamedSix(); + assert.strictEqual(result, undefined); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/clientStructureRenamed.spec.ts b/packages/typespec-ts/test/modularIntegration/clientStructureRenamed.spec.ts index b2028c5a62..9b38b528c6 100644 --- a/packages/typespec-ts/test/modularIntegration/clientStructureRenamed.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/clientStructureRenamed.spec.ts @@ -14,56 +14,32 @@ describe("Client Structure Renamed-Operation Rest Client", () => { }); it("should call operation one correctly", async () => { - try { - const result = await client.renamedOne(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.renamedOne(); + assert.strictEqual(result, undefined); }); it("should call operation two correctly", async () => { - try { - const result = await client.group.renamedTwo(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.group.renamedTwo(); + assert.strictEqual(result, undefined); }); it("should call operation three correctly", async () => { - try { - const result = await client.renamedThree(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.renamedThree(); + assert.strictEqual(result, undefined); }); it("should call operation four correctly", async () => { - try { - const result = await client.group.renamedFour(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.group.renamedFour(); + assert.strictEqual(result, undefined); }); it("should call operation five correctly", async () => { - try { - const result = await client.renamedFive(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.renamedFive(); + assert.strictEqual(result, undefined); }); it("should call operation six correctly", async () => { - try { - const result = await client.group.renamedSix(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.group.renamedSix(); + assert.strictEqual(result, undefined); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/clientStructureTwoGroup.spec.ts b/packages/typespec-ts/test/modularIntegration/clientStructureTwoGroup.spec.ts index e1b4e8902a..dba5918d2e 100644 --- a/packages/typespec-ts/test/modularIntegration/clientStructureTwoGroup.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/clientStructureTwoGroup.spec.ts @@ -14,56 +14,32 @@ describe("Client Structure Two-Operation-Group Rest Client", () => { }); it("should call operation one correctly", async () => { - try { - const result = await client.group1.one(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.group1.one(); + assert.strictEqual(result, undefined); }); it("should call operation two correctly", async () => { - try { - const result = await client.group2.two(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.group2.two(); + assert.strictEqual(result, undefined); }); it("should call operation three correctly", async () => { - try { - const result = await client.group1.three(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.group1.three(); + assert.strictEqual(result, undefined); }); it("should call operation four correctly", async () => { - try { - const result = await client.group1.four(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.group1.four(); + assert.strictEqual(result, undefined); }); it("should call operation five correctly", async () => { - try { - const result = await client.group2.five(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.group2.five(); + assert.strictEqual(result, undefined); }); it("should call operation six correctly", async () => { - try { - const result = await client.group2.six(); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.group2.six(); + assert.strictEqual(result, undefined); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/collectionFormat.spec.ts b/packages/typespec-ts/test/modularIntegration/collectionFormat.spec.ts index d02eb520f4..a54f21a317 100644 --- a/packages/typespec-ts/test/modularIntegration/collectionFormat.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/collectionFormat.spec.ts @@ -12,60 +12,36 @@ describe("CollectionFormatClient Classical Client", () => { }); it("should send csv format in query", async () => { - try { - const result = await client.query.csv(["blue", "red", "green"]); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.query.csv(["blue", "red", "green"]); + assert.strictEqual(result, undefined); }); it("should send multi format in query", async () => { - try { - const result = await client.query.multi(["blue", "red", "green"], { - requestOptions: { - skipUrlEncoding: true - } - }); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.query.multi(["blue", "red", "green"], { + requestOptions: { + skipUrlEncoding: true + } + }); + assert.strictEqual(result, undefined); }); it("should send pipes format in query", async () => { - try { - const result = await client.query.pipes(["blue", "red", "green"]); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.query.pipes(["blue", "red", "green"]); + assert.strictEqual(result, undefined); }); it("should send ssv format in query", async () => { - try { - const result = await client.query.ssv(["blue", "red", "green"]); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.query.ssv(["blue", "red", "green"]); + assert.strictEqual(result, undefined); }); it("should send tsv format in query", async () => { - try { - const result = await client.query.tsv(["blue", "red", "green"]); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.query.tsv(["blue", "red", "green"]); + assert.strictEqual(result, undefined); }); it("should send csv format in header", async () => { - try { - const result = await client.header.csv(["blue", "red", "green"]); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.header.csv(["blue", "red", "green"]); + assert.strictEqual(result, undefined); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/customClientRequestId.spec.ts b/packages/typespec-ts/test/modularIntegration/customClientRequestId.spec.ts index d64c4f1d5d..bb1ffa2ebd 100644 --- a/packages/typespec-ts/test/modularIntegration/customClientRequestId.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/customClientRequestId.spec.ts @@ -12,45 +12,37 @@ describe("XmsRequestIdClient Classical Client", () => { }); it("should add client-request-id in header transparently", async () => { - try { - const result = await client.get(); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.get(); + assert.isUndefined(result); }); it("should override request id with client setting one", async () => { - try { - const overrideId = "86aede1f-96fa-4e7f-b1e1-bf8a947cb804"; - const result = await client.get({ - requestOptions: { - headers: { - "x-ms-client-request-id": overrideId - } + const overrideId = "86aede1f-96fa-4e7f-b1e1-bf8a947cb804"; + const result = await client.get({ + requestOptions: { + headers: { + "x-ms-client-request-id": overrideId } - }); - assert.isUndefined(result); - const checkClientRequestIdPolicy: PipelinePolicy = { - sendRequest: (req, next) => { - assert.equal(overrideId, req.headers.get("x-ms-client-request-id")); - return next(req); - }, - name: "preventCachingPolicy" - }; - client = new XmsClientRequestIdClient({ - allowInsecureConnection: true, - endpoint: "http://localhost:3002", - additionalPolicies: [ - { - policy: checkClientRequestIdPolicy, - position: "perCall" - } - ] - }); - } catch (err) { - assert.fail(err as string); - } + } + }); + assert.isUndefined(result); + const checkClientRequestIdPolicy: PipelinePolicy = { + sendRequest: (req, next) => { + assert.equal(overrideId, req.headers.get("x-ms-client-request-id")); + return next(req); + }, + name: "preventCachingPolicy" + }; + client = new XmsClientRequestIdClient({ + allowInsecureConnection: true, + endpoint: "http://localhost:3002", + additionalPolicies: [ + { + policy: checkClientRequestIdPolicy, + position: "perCall" + } + ] + }); }); it("should override with x-test-client-request-id header", async () => { diff --git a/packages/typespec-ts/test/modularIntegration/encodeBytes.spec.ts b/packages/typespec-ts/test/modularIntegration/encodeBytes.spec.ts index 407329f39b..72d463055d 100644 --- a/packages/typespec-ts/test/modularIntegration/encodeBytes.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/encodeBytes.spec.ts @@ -18,156 +18,108 @@ describe("EncodeBytesClient Modular Client", () => { describe("query", () => { it(`should get bytes`, async () => { - try { - const result = await client.query.default( - stringToUint8Array("dGVzdA==", "base64") - ); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.query.default( + stringToUint8Array("dGVzdA==", "base64") + ); + assert.isUndefined(result); }); it(`should get bytes base64 encoding`, async () => { - try { - const result = await client.query.base64( - stringToUint8Array("dGVzdA==", "base64") - ); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.query.base64( + stringToUint8Array("dGVzdA==", "base64") + ); + assert.isUndefined(result); }); it(`should get bytes base64url encoding`, async () => { - try { - const result = await client.query.base64url( - stringToUint8Array("dGVzdA", "base64url") - ); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.query.base64url( + stringToUint8Array("dGVzdA", "base64url") + ); + assert.isUndefined(result); }); it(`should get bytes base64url-array`, async () => { - try { - const result = await client.query.base64urlArray([ - stringToUint8Array("dGVzdA", "base64url"), - stringToUint8Array("dGVzdA", "base64url") - ]); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.query.base64urlArray([ + stringToUint8Array("dGVzdA", "base64url"), + stringToUint8Array("dGVzdA", "base64url") + ]); + assert.isUndefined(result); }); }); describe("property", () => { it(`should post bytes`, async () => { - try { - const result = await client.property.default({ - value: stringToUint8Array("dGVzdA==", "base64") - }); - assert.deepEqual( - result.value, - stringToUint8Array("dGVzdA==", "base64") - ); - } catch (err) { - assert.fail(err as string); - } + const result = await client.property.default({ + value: stringToUint8Array("dGVzdA==", "base64") + }); + assert.deepEqual( + result.value, + stringToUint8Array("dGVzdA==", "base64") + ); }); it(`should post bytes base64 encoding`, async () => { - try { - const result = await client.property.base64({ - value: stringToUint8Array("dGVzdA==", "base64") - }); - assert.deepEqual( - result.value, - stringToUint8Array("dGVzdA==", "base64") - ); - } catch (err) { - assert.fail(err as string); - } + const result = await client.property.base64({ + value: stringToUint8Array("dGVzdA==", "base64") + }); + assert.deepEqual( + result.value, + stringToUint8Array("dGVzdA==", "base64") + ); }); it(`should post bytes base64url encoding`, async () => { - try { - const result = await client.property.base64url({ - value: stringToUint8Array("dGVzdA", "base64url") - }); - assert.deepEqual( - uint8ArrayToString(result.value, "base64url"), - "dGVzdA" - ); - } catch (err) { - assert.fail(err as string); - } + const result = await client.property.base64url({ + value: stringToUint8Array("dGVzdA", "base64url") + }); + assert.deepEqual( + uint8ArrayToString(result.value, "base64url"), + "dGVzdA" + ); }); it(`should post bytes base64url array`, async () => { - try { - const result = await client.property.base64urlArray({ - value: [ - stringToUint8Array("dGVzdA", "base64url"), - stringToUint8Array("dGVzdA", "base64url") - ] - }); - assert.deepEqual(result.value, [ + const result = await client.property.base64urlArray({ + value: [ stringToUint8Array("dGVzdA", "base64url"), stringToUint8Array("dGVzdA", "base64url") - ]); - } catch (err) { - assert.fail(err as string); - } + ] + }); + assert.deepEqual(result.value, [ + stringToUint8Array("dGVzdA", "base64url"), + stringToUint8Array("dGVzdA", "base64url") + ]); }); }); describe("header", () => { it(`should get bytes`, async () => { - try { - const result = await client.header.default( - stringToUint8Array("dGVzdA==", "base64") - ); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.header.default( + stringToUint8Array("dGVzdA==", "base64") + ); + assert.isUndefined(result); }); it(`should get bytes base64 encoding`, async () => { - try { - const result = await client.header.base64( - stringToUint8Array("dGVzdA==", "base64") - ); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.header.base64( + stringToUint8Array("dGVzdA==", "base64") + ); + assert.isUndefined(result); }); it(`should get bytes base64url encoding`, async () => { - try { - const result = await client.header.base64url( - stringToUint8Array("dGVzdA", "base64url") - ); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.header.base64url( + stringToUint8Array("dGVzdA", "base64url") + ); + assert.isUndefined(result); }); it(`should get bytes base64url-array`, async () => { - try { - const result = await client.header.base64urlArray([ - stringToUint8Array("dGVzdA", "base64url"), - stringToUint8Array("dGVzdA", "base64url") - ]); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.header.base64urlArray([ + stringToUint8Array("dGVzdA", "base64url"), + stringToUint8Array("dGVzdA", "base64url") + ]); + assert.isUndefined(result); }); }); @@ -191,53 +143,37 @@ describe("EncodeBytesClient Modular Client", () => { }); it(`should post bytes base64 encoding`, async () => { - try { - const result = await client.requestBody.base64( - stringToUint8Array("dGVzdA==", "base64"), - { - requestOptions: { headers: { "content-type": "application/json" } } - } - ); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.requestBody.base64( + stringToUint8Array("dGVzdA==", "base64"), + { + requestOptions: { headers: { "content-type": "application/json" } } + } + ); + assert.isUndefined(result); }); it(`should post bytes base64url encoding`, async () => { - try { - const result = await client.requestBody.base64url( - stringToUint8Array("dGVzdA", "base64url"), - { - requestOptions: { headers: { "content-type": "application/json" } } - } - ); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.requestBody.base64url( + stringToUint8Array("dGVzdA", "base64url"), + { + requestOptions: { headers: { "content-type": "application/json" } } + } + ); + assert.isUndefined(result); }); it(`should post bytes with custom content type`, async () => { - try { - const result = await client.requestBody.customContentType(pngFile, { - contentType: "image/png" - }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.requestBody.customContentType(pngFile, { + contentType: "image/png" + }); + assert.isUndefined(result); }).timeout(10000); it(`should post bytes with custom content type`, async () => { - try { - const result = await client.requestBody.octetStream(pngFile, { - contentType: "application/octet-stream" - }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.requestBody.octetStream(pngFile, { + contentType: "application/octet-stream" + }); + assert.isUndefined(result); }); }); @@ -246,56 +182,36 @@ describe("EncodeBytesClient Modular Client", () => { resolve("../../packages/typespec-ts/temp/assets/image.png") ).toString("utf-8"); it(`should get bytes with base64 encoding by default`, async () => { - try { - const result = await client.responseBody.default(); - assert.strictEqual(uint8ArrayToString(result, "base64"), "dGVzdA=="); - } catch (err) { - assert.fail(err as string); - } + const result = await client.responseBody.default(); + assert.strictEqual(uint8ArrayToString(result, "base64"), "dGVzdA=="); }); it(`should get bytes base64 encoding`, async () => { - try { - const result = await client.responseBody.base64(); - assert.strictEqual(uint8ArrayToString(result, "base64"), "dGVzdA=="); - } catch (err) { - assert.fail(err as string); - } + const result = await client.responseBody.base64(); + assert.strictEqual(uint8ArrayToString(result, "base64"), "dGVzdA=="); }); it(`should get bytes base64url encoding`, async () => { - try { - const result = await client.responseBody.base64url(); - assert.strictEqual(uint8ArrayToString(result, "base64url"), "dGVzdA"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.responseBody.base64url(); + assert.strictEqual(uint8ArrayToString(result, "base64url"), "dGVzdA"); }); it(`should get bytes with custom content type`, async () => { - try { - const result = await client.responseBody.customContentType({ - onResponse: (res) => { - res.headers.get("content-type") === "image/png"; - } - }); - assert.strictEqual(uint8ArrayToString(result, "utf-8"), pngFile); - } catch (err) { - assert.fail(err as string); - } + const result = await client.responseBody.customContentType({ + onResponse: (res) => { + res.headers.get("content-type") === "image/png"; + } + }); + assert.strictEqual(uint8ArrayToString(result, "utf-8"), pngFile); }); it(`should get bytes with octet-stream content type`, async () => { - try { - const result = await client.responseBody.octetStream({ - onResponse: (res) => { - res.headers.get("content-type") === "application/octet-stream"; - } - }); - assert.strictEqual(uint8ArrayToString(result, "utf-8"), pngFile); - } catch (err) { - assert.fail(err as string); - } + const result = await client.responseBody.octetStream({ + onResponse: (res) => { + res.headers.get("content-type") === "application/octet-stream"; + } + }); + assert.strictEqual(uint8ArrayToString(result, "utf-8"), pngFile); }); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/encodeDatetime.spec.ts b/packages/typespec-ts/test/modularIntegration/encodeDatetime.spec.ts index 253c41bd8b..d5b28b3301 100644 --- a/packages/typespec-ts/test/modularIntegration/encodeDatetime.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/encodeDatetime.spec.ts @@ -15,239 +15,163 @@ describe("EncodeDatetimeClient Rest Client", () => { describe("query", () => { it(`should get default datetime`, async () => { - try { - const result = await client.query.default( - new Date("2022-08-26T18:38:00.000Z") - ); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.query.default( + new Date("2022-08-26T18:38:00.000Z") + ); + assert.isUndefined(result); }); it(`should get rfc3339`, async () => { - try { - const result = await client.query.rfc3339( - new Date("2022-08-26T18:38:00.000Z") - ); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.query.rfc3339( + new Date("2022-08-26T18:38:00.000Z") + ); + assert.isUndefined(result); }); it(`should get rfc7231`, async () => { - try { - const result = await client.query.rfc7231( - new Date("Fri, 26 Aug 2022 14:38:00 GMT") - ); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.query.rfc7231( + new Date("Fri, 26 Aug 2022 14:38:00 GMT") + ); + assert.isUndefined(result); }); it(`should get unix timestamp`, async () => { - try { - const result = await client.query.unixTimestamp(new Date(1686566864)); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.query.unixTimestamp(new Date(1686566864)); + assert.isUndefined(result); }); it(`should get unix timestamp-array`, async () => { - try { - const result = await client.query.unixTimestampArray([ - new Date(1686566864), - new Date(1686734256) - ]); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.query.unixTimestampArray([ + new Date(1686566864), + new Date(1686734256) + ]); + assert.isUndefined(result); }); }); describe("property", () => { it(`should get default datetime`, async () => { - try { - const result = await client.property.default({ - value: new Date("2022-08-26T18:38:00.000Z") - }); - assert.deepEqual(result.value, new Date("2022-08-26T18:38:00.000Z")); - } catch (err) { - assert.fail(err as string); - } + const result = await client.property.default({ + value: new Date("2022-08-26T18:38:00.000Z") + }); + assert.deepEqual(result.value, new Date("2022-08-26T18:38:00.000Z")); }); it(`should get rfc3339`, async () => { - try { - const result = await client.property.rfc3339({ - value: new Date("2022-08-26T18:38:00.000Z") - }); - assert.deepEqual(result.value, new Date("2022-08-26T18:38:00.000Z")); - } catch (err) { - assert.fail(err as string); - } + const result = await client.property.rfc3339({ + value: new Date("2022-08-26T18:38:00.000Z") + }); + assert.deepEqual(result.value, new Date("2022-08-26T18:38:00.000Z")); }); it(`should get rfc7231`, async () => { - try { - const result = await client.property.rfc7231({ - value: new Date("Fri, 26 Aug 2022 14:38:00 GMT") - }); - assert.deepEqual( - result.value, - new Date("Fri, 26 Aug 2022 14:38:00 GMT") - ); - } catch (err) { - assert.fail(err as string); - } + const result = await client.property.rfc7231({ + value: new Date("Fri, 26 Aug 2022 14:38:00 GMT") + }); + assert.deepEqual( + result.value, + new Date("Fri, 26 Aug 2022 14:38:00 GMT") + ); }); it(`should get unix timestamp`, async () => { - try { - const result = await client.property.unixTimestamp({ - value: new Date(1686566864) - }); - assert.deepEqual(result.value, new Date(1686566864)); - } catch (err) { - assert.fail(err as string); - } + const result = await client.property.unixTimestamp({ + value: new Date(1686566864) + }); + assert.deepEqual(result.value, new Date(1686566864)); }); it(`should get unix timestamp-array`, async () => { - try { - const result = await client.property.unixTimestampArray({ - value: [new Date(1686566864), new Date(1686734256)] - }); - assert.deepEqual(result.value, [ - new Date(1686566864), - new Date(1686734256) - ]); - } catch (err) { - assert.fail(err as string); - } + const result = await client.property.unixTimestampArray({ + value: [new Date(1686566864), new Date(1686734256)] + }); + assert.deepEqual(result.value, [ + new Date(1686566864), + new Date(1686734256) + ]); }); }); describe("header", () => { it(`should get default datetime`, async () => { - try { - const result = await client.header.default( - new Date("Fri, 26 Aug 2022 14:38:00 GMT") - ); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.header.default( + new Date("Fri, 26 Aug 2022 14:38:00 GMT") + ); + assert.isUndefined(result); }); it(`should get rfc3339`, async () => { - try { - const result = await client.header.rfc3339( - new Date("2022-08-26T18:38:00.000Z") - ); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.header.rfc3339( + new Date("2022-08-26T18:38:00.000Z") + ); + assert.isUndefined(result); }); it(`should get rfc7231`, async () => { - try { - const result = await client.header.rfc7231( - new Date("Fri, 26 Aug 2022 14:38:00 GMT") - ); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.header.rfc7231( + new Date("Fri, 26 Aug 2022 14:38:00 GMT") + ); + assert.isUndefined(result); }); it(`should get unix timestamp`, async () => { - try { - const result = await client.header.unixTimestamp(new Date(1686566864)); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.header.unixTimestamp(new Date(1686566864)); + assert.isUndefined(result); }); it(`should get unix timestamp-array`, async () => { - try { - const result = await client.header.unixTimestampArray([ - new Date(1686566864), - new Date(1686734256) - ]); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.header.unixTimestampArray([ + new Date(1686566864), + new Date(1686734256) + ]); + assert.isUndefined(result); }); }); describe("response header", () => { it(`should get default header`, async () => { - try { - const result = await client.responseHeader.default({ - onResponse: (res) => { - assert.strictEqual( - res.headers.get("value"), - "Fri, 26 Aug 2022 14:38:00 GMT" - ); - } - }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.responseHeader.default({ + onResponse: (res) => { + assert.strictEqual( + res.headers.get("value"), + "Fri, 26 Aug 2022 14:38:00 GMT" + ); + } + }); + assert.isUndefined(result); }); it(`should get rfc3339 header`, async () => { - try { - const result = await client.responseHeader.rfc3339({ - onResponse: (res) => { - assert.strictEqual( - res.headers.get("value"), - "2022-08-26T18:38:00.000Z" - ); - } - }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.responseHeader.rfc3339({ + onResponse: (res) => { + assert.strictEqual( + res.headers.get("value"), + "2022-08-26T18:38:00.000Z" + ); + } + }); + assert.isUndefined(result); }); it(`should get rfc7231 header`, async () => { - try { - const result = await client.responseHeader.rfc7231({ - onResponse: (res) => { - assert.strictEqual( - res.headers.get("value"), - "Fri, 26 Aug 2022 14:38:00 GMT" - ); - } - }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.responseHeader.rfc7231({ + onResponse: (res) => { + assert.strictEqual( + res.headers.get("value"), + "Fri, 26 Aug 2022 14:38:00 GMT" + ); + } + }); + assert.isUndefined(result); }); it(`should get unix-timestamp header`, async () => { - try { - const result = await client.responseHeader.unixTimestamp({ - onResponse: (res) => { - assert.strictEqual(res.headers.get("value"), "1686566864"); - } - }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.responseHeader.unixTimestamp({ + onResponse: (res) => { + assert.strictEqual(res.headers.get("value"), "1686566864"); + } + }); + assert.isUndefined(result); }); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/encodeDuration.spec.ts b/packages/typespec-ts/test/modularIntegration/encodeDuration.spec.ts index 6635da81e6..7c14a6d6f8 100644 --- a/packages/typespec-ts/test/modularIntegration/encodeDuration.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/encodeDuration.spec.ts @@ -15,171 +15,99 @@ describe("EncodeDurationClient Rest Client", () => { describe("query", () => { it(`should get default duration`, async () => { - try { - const result = await client.query.default("P40D"); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.query.default("P40D"); + assert.isUndefined(result); }); it(`should get iso8601 duration`, async () => { - try { - const result = await client.query.iso8601("P40D"); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.query.iso8601("P40D"); + assert.isUndefined(result); }); it(`should get float seconds`, async () => { - try { - const result = await client.query.floatSeconds(35.625); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.query.floatSeconds(35.625); + assert.isUndefined(result); }); it(`should get float64 seconds`, async () => { - try { - const result = await client.query.float64Seconds(35.625); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.query.float64Seconds(35.625); + assert.isUndefined(result); }); it(`should get int32 seconds`, async () => { - try { - const result = await client.query.int32Seconds(36); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.query.int32Seconds(36); + assert.isUndefined(result); }); it(`should get int32 seconds array`, async () => { - try { - const result = await client.query.int32SecondsArray([36, 47]); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.query.int32SecondsArray([36, 47]); + assert.isUndefined(result); }); }); describe("property", () => { it(`should get default duration`, async () => { - try { - const result = await client.property.default({ value: "P40D" }); - assert.deepEqual(result.value, "P40D"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.property.default({ value: "P40D" }); + assert.deepEqual(result.value, "P40D"); }); it(`should get iso8601 duration`, async () => { - try { - const result = await client.property.iso8601({ value: "P40D" }); - assert.deepEqual(result.value, "P40D"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.property.iso8601({ value: "P40D" }); + assert.deepEqual(result.value, "P40D"); }); it(`should get float seconds`, async () => { - try { - const result = await client.property.floatSeconds({ value: 35.625 }); - assert.deepEqual(result.value, 35.625); - } catch (err) { - assert.fail(err as string); - } + const result = await client.property.floatSeconds({ value: 35.625 }); + assert.deepEqual(result.value, 35.625); }); it(`should get float64 seconds`, async () => { - try { - const result = await client.property.float64Seconds({ value: 35.625 }); - assert.deepEqual(result.value, 35.625); - } catch (err) { - assert.fail(err as string); - } + const result = await client.property.float64Seconds({ value: 35.625 }); + assert.deepEqual(result.value, 35.625); }); it(`should get int32 seconds`, async () => { - try { - const result = await client.property.int32Seconds({ value: 36 }); - assert.deepEqual(result.value, 36); - } catch (err) { - assert.fail(err as string); - } + const result = await client.property.int32Seconds({ value: 36 }); + assert.deepEqual(result.value, 36); }); it(`should get float seconds array`, async () => { - try { - const result = await client.property.floatSecondsArray({ - value: [35.625, 46.75] - }); - assert.deepEqual(result.value, [35.625, 46.75]); - } catch (err) { - assert.fail(err as string); - } + const result = await client.property.floatSecondsArray({ + value: [35.625, 46.75] + }); + assert.deepEqual(result.value, [35.625, 46.75]); }); }); describe("header", () => { it(`should get default duration`, async () => { - try { - const result = await client.header.default("P40D"); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.header.default("P40D"); + assert.isUndefined(result); }); it(`should get iso8601 duration`, async () => { - try { - const result = await client.header.iso8601("P40D"); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.header.iso8601("P40D"); + assert.isUndefined(result); }); it(`should get float seconds`, async () => { - try { - const result = await client.header.floatSeconds(35.625); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.header.floatSeconds(35.625); + assert.isUndefined(result); }); it(`should get float64 seconds`, async () => { - try { - const result = await client.header.float64Seconds(35.625); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.header.float64Seconds(35.625); + assert.isUndefined(result); }); it(`should get int32 seconds`, async () => { - try { - const result = await client.header.int32Seconds(36); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.header.int32Seconds(36); + assert.isUndefined(result); }); it(`should get int32 seconds array`, async () => { - try { - const result = await client.header.iso8601Array(["P40D", "P50D"]); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.header.iso8601Array(["P40D", "P50D"]); + assert.isUndefined(result); }); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/extensibleEnums.spec.ts b/packages/typespec-ts/test/modularIntegration/extensibleEnums.spec.ts index 16d590485f..b8ef1771a6 100644 --- a/packages/typespec-ts/test/modularIntegration/extensibleEnums.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/extensibleEnums.spec.ts @@ -11,42 +11,26 @@ describe("ExtensibleEnums Rest Client", () => { }); it("should get known value", async () => { - try { - const result = await client.string.getKnownValue(); - assert.strictEqual(result, "Monday"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.string.getKnownValue(); + assert.strictEqual(result, "Monday"); }); it("should get unknown value", async () => { - try { - const result = await client.string.getUnknownValue(); - assert.strictEqual(result, "Weekend"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.string.getUnknownValue(); + assert.strictEqual(result, "Weekend"); }); it("should put known value", async () => { - try { - const result = await client.string.putKnownValue("Monday", { - requestOptions: { headers: { "content-type": "text/plain" } } - }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.string.putKnownValue("Monday", { + requestOptions: { headers: { "content-type": "text/plain" } } + }); + assert.isUndefined(result); }); it("should put unknown value and receives 500", async () => { - try { - const result = await client.string.putUnknownValue("Weekend" as any, { - requestOptions: { headers: { "content-type": "text/plain" } } - }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.string.putUnknownValue("Weekend" as any, { + requestOptions: { headers: { "content-type": "text/plain" } } + }); + assert.isUndefined(result); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/fixedEnums.spec.ts b/packages/typespec-ts/test/modularIntegration/fixedEnums.spec.ts index 5d8957deb3..b83a546e17 100644 --- a/packages/typespec-ts/test/modularIntegration/fixedEnums.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/fixedEnums.spec.ts @@ -11,23 +11,15 @@ describe("FixedEnums Rest Client", () => { }); it("should get known value", async () => { - try { - const result = await client.string.getKnownValue(); - assert.strictEqual(result, "Monday"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.string.getKnownValue(); + assert.strictEqual(result, "Monday"); }); it("should put known value", async () => { - try { - const result = await client.string.putKnownValue("Monday", { - requestOptions: { headers: { "content-type": "text/plain" } } - }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.string.putKnownValue("Monday", { + requestOptions: { headers: { "content-type": "text/plain" } } + }); + assert.isUndefined(result); }); it("should put unknown value and receives 500", async () => { diff --git a/packages/typespec-ts/test/modularIntegration/generated/versioning/removed/src/index.d.ts b/packages/typespec-ts/test/modularIntegration/generated/versioning/removed/src/index.d.ts index 59a83f3e87..5e3981385f 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/versioning/removed/src/index.d.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/versioning/removed/src/index.d.ts @@ -4,17 +4,28 @@ import { Pipeline } from '@azure/core-rest-pipeline'; export declare type EnumV2 = "enumMemberV2"; +export declare type EnumV3 = "enumMemberV1" | "enumMemberV2Preview"; + export declare interface ModelV2 { prop: string; enumProp: EnumV2; unionProp: UnionV2; } +export declare interface ModelV3 { + id: string; + enumProp: EnumV3; +} + +export declare interface ModelV3OptionalParams extends OperationOptions { +} + export declare class RemovedClient { private _client; readonly pipeline: Pipeline; constructor(endpointParam: string, version: Versions, options?: RemovedClientOptionalParams); v2(body: ModelV2, options?: V2OptionalParams): Promise; + modelV3(body: ModelV3, options?: ModelV3OptionalParams): Promise; } export declare interface RemovedClientOptionalParams extends ClientOptions { @@ -25,6 +36,6 @@ export declare type UnionV2 = string | number; export declare interface V2OptionalParams extends OperationOptions { } -export declare type Versions = "v1" | "v2"; +export declare type Versions = "v1" | "v2preview" | "v2"; export { } diff --git a/packages/typespec-ts/test/modularIntegration/headersRepeatability.spec.ts b/packages/typespec-ts/test/modularIntegration/headersRepeatability.spec.ts index ce81baae70..cc0ab0c5da 100644 --- a/packages/typespec-ts/test/modularIntegration/headersRepeatability.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/headersRepeatability.spec.ts @@ -12,15 +12,11 @@ describe("Repeatability Client", () => { }); it("should add client-request-id and date in header", async () => { - try { - const requestID = "86aede1f-96fa-4e7f-b1e1-bf8a947cb804"; - const result = await client.immediateSuccess( - requestID, - new Date("Mon, 13 Nov 2023 14:38:00 GMT") - ); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const requestID = "86aede1f-96fa-4e7f-b1e1-bf8a947cb804"; + const result = await client.immediateSuccess( + requestID, + new Date("Mon, 13 Nov 2023 14:38:00 GMT") + ); + assert.isUndefined(result); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/lroRpc.spec.ts b/packages/typespec-ts/test/modularIntegration/lroRpc.spec.ts index ee498b0671..a9fed23601 100644 --- a/packages/typespec-ts/test/modularIntegration/lroRpc.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/lroRpc.spec.ts @@ -12,13 +12,9 @@ describe("RpcClient Classical Client", () => { }); it("should await poller result directly", async () => { - try { - const result = await client.longRunningRpc({ - prompt: "text" - }); - assert.strictEqual(result.data, "text data"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.longRunningRpc({ + prompt: "text" + }); + assert.strictEqual(result.data, "text data"); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/lroStardard.spec.ts b/packages/typespec-ts/test/modularIntegration/lroStardard.spec.ts index 1cc5d1e5d4..aa6bc4aa70 100644 --- a/packages/typespec-ts/test/modularIntegration/lroStardard.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/lroStardard.spec.ts @@ -18,14 +18,10 @@ describe("LROStandardClient Classical Client", () => { describe("createOrReplace", () => { it("should await poller result directly", async () => { - try { - const result = await client.createOrReplace("madge", { - role: "contributor" - } as any); - assert.deepEqual(result, { name: "madge", role: "contributor" }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.createOrReplace("madge", { + role: "contributor" + } as any); + assert.deepEqual(result, { name: "madge", role: "contributor" }); }); it("serialize and rehydration", async () => { @@ -204,30 +200,22 @@ describe("LROStandardClient Classical Client", () => { describe("delete", () => { it("should await poller result directly", async () => { - try { - const result = await client.delete("madge"); - assert.strictEqual(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.delete("madge"); + assert.strictEqual(result, undefined); }); it("should count polling counts correctly", async () => { - try { - const poller = client.delete("madge"); - let pollingCounts = 0; - const expectedStates = ["running", "succeeded"]; - const actualStates: string[] = []; - while (!poller.isDone) { - pollingCounts++; - await poller.poll(); - actualStates.push(poller.operationState?.status!); - } - assert.deepEqual(actualStates, expectedStates); - assert.strictEqual(pollingCounts, 2); - } catch (err) { - assert.fail(err as string); + const poller = client.delete("madge"); + let pollingCounts = 0; + const expectedStates = ["running", "succeeded"]; + const actualStates: string[] = []; + while (!poller.isDone) { + pollingCounts++; + await poller.poll(); + actualStates.push(poller.operationState?.status!); } + assert.deepEqual(actualStates, expectedStates); + assert.strictEqual(pollingCounts, 2); }); it("serialize and rehydration", async () => { @@ -241,33 +229,25 @@ describe("LROStandardClient Classical Client", () => { describe("export", () => { it("should await poller result directly", async () => { - try { - const result = await client.export("madge", "json"); - assert.deepEqual(result, { - name: "madge", - resourceUri: "/users/madge" - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.export("madge", "json"); + assert.deepEqual(result, { + name: "madge", + resourceUri: "/users/madge" + }); }); it("should count polling counts correctly", async () => { - try { - const poller = client.export("madge", "json"); - let pollingCounts = 0; - const expectedStates = ["running", "succeeded"]; - const actualStates: string[] = []; - while (!poller.isDone) { - pollingCounts++; - await poller.poll(); - actualStates.push(poller.operationState?.status!); - } - assert.deepEqual(actualStates, expectedStates); - assert.strictEqual(pollingCounts, 2); - } catch (err) { - assert.fail(err as string); + const poller = client.export("madge", "json"); + let pollingCounts = 0; + const expectedStates = ["running", "succeeded"]; + const actualStates: string[] = []; + while (!poller.isDone) { + pollingCounts++; + await poller.poll(); + actualStates.push(poller.operationState?.status!); } + assert.deepEqual(actualStates, expectedStates); + assert.strictEqual(pollingCounts, 2); }); it("serialize and rehydration", async () => { diff --git a/packages/typespec-ts/test/modularIntegration/modelInheritanceEnumDiscriminator.spec.ts b/packages/typespec-ts/test/modularIntegration/modelInheritanceEnumDiscriminator.spec.ts index 61df89f0e4..037e62dd5c 100644 --- a/packages/typespec-ts/test/modularIntegration/modelInheritanceEnumDiscriminator.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/modelInheritanceEnumDiscriminator.spec.ts @@ -24,76 +24,44 @@ describe("EnumDiscriminatorClient Rest Client", () => { kind: "cobra" }; it("should get extensible enum", async () => { - try { - const result = await client.getExtensibleModel(); - assert.deepEqual(result, validBody); - } catch (err) { - assert.fail(err as string); - } + const result = await client.getExtensibleModel(); + assert.deepEqual(result, validBody); }); it("should put extensible enum", async () => { - try { - const result = await client.putExtensibleModel(validBody); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.putExtensibleModel(validBody); + assert.isUndefined(result); }); it("should get extensible enum if missing discriminator", async () => { - try { - const result = await client.getExtensibleModelMissingDiscriminator(); - assert.deepEqual(result.weight, 10); - assert.isUndefined(result.kind); - } catch (err) { - assert.fail(err as string); - } + const result = await client.getExtensibleModelMissingDiscriminator(); + assert.deepEqual(result.weight, 10); + assert.isUndefined(result.kind); }); it("should get extensible enum if wrong discriminator", async () => { - try { - const result = await client.getExtensibleModelWrongDiscriminator(); - assert.deepEqual(result, { weight: 8, kind: "wrongKind" }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.getExtensibleModelWrongDiscriminator(); + assert.deepEqual(result, { weight: 8, kind: "wrongKind" }); }); it("should get fixed enum", async () => { - try { - const result = await client.getFixedModel(); - assert.deepEqual(result, validFixedEnumBody); - } catch (err) { - assert.fail(err as string); - } + const result = await client.getFixedModel(); + assert.deepEqual(result, validFixedEnumBody); }); it("should put fixed enum", async () => { - try { - const result = await client.putFixedModel(validFixedEnumBody); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.putFixedModel(validFixedEnumBody); + assert.isUndefined(result); }); it("should get fixed enum if missing discriminator", async () => { - try { - const result = await client.getFixedModelMissingDiscriminator(); - assert.deepEqual(result.length, 10); - assert.isUndefined(result.kind); - } catch (err) { - assert.fail(err as string); - } + const result = await client.getFixedModelMissingDiscriminator(); + assert.deepEqual(result.length, 10); + assert.isUndefined(result.kind); }); it("should get fixed enum if wrong discriminator", async () => { - try { - const result = await client.getFixedModelWrongDiscriminator(); - assert.deepEqual(result, { length: 8, kind: "wrongKind" }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.getFixedModelWrongDiscriminator(); + assert.deepEqual(result, { length: 8, kind: "wrongKind" }); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/modelInheritanceNestedDiscriminator.spec.ts b/packages/typespec-ts/test/modularIntegration/modelInheritanceNestedDiscriminator.spec.ts index d87543f2e5..2364811b67 100644 --- a/packages/typespec-ts/test/modularIntegration/modelInheritanceNestedDiscriminator.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/modelInheritanceNestedDiscriminator.spec.ts @@ -22,23 +22,15 @@ describe("NestedDiscriminatorClient Rest Client", () => { sharktype: "goblin" }; it("should get valid", async () => { - try { - const result = await client.getModel(); - assert.strictEqual(result.age, 1); - assert.strictEqual(result.kind, "shark"); - assert.strictEqual((result as Shark).sharktype, "goblin"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.getModel(); + assert.strictEqual(result.age, 1); + assert.strictEqual(result.kind, "shark"); + assert.strictEqual((result as Shark).sharktype, "goblin"); }); it("should put valid", async () => { - try { - const result = await client.putModel(validBody); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.putModel(validBody); + assert.isUndefined(result); }); const validRecursiveBody: Salmon = { @@ -99,49 +91,33 @@ describe("NestedDiscriminatorClient Rest Client", () => { } }; it("should get recursive body", async () => { - try { - const result = await client.getRecursiveModel(); + const result = await client.getRecursiveModel(); + assert.strictEqual( + JSON.stringify(result, Object.keys(result).sort()), + JSON.stringify(validRecursiveBody, Object.keys(validRecursiveBody).sort()) + ); + if (result.kind === "salmon") { assert.strictEqual( - JSON.stringify(result, Object.keys(result).sort()), - JSON.stringify(validRecursiveBody, Object.keys(validRecursiveBody).sort()) + (result as Salmon).partner?.kind, + validRecursiveBody.partner?.kind ); - if (result.kind === "salmon") { - assert.strictEqual( - (result as Salmon).partner?.kind, - validRecursiveBody.partner?.kind - ); - } - } catch (err) { - assert.fail(err as string); } }); it("should put recursive body", async () => { - try { - const result = await client.putRecursiveModel(validRecursiveBody); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.putRecursiveModel(validRecursiveBody); + assert.isUndefined(result); }); it("should get missing discriminator body", async () => { - try { - const result = await client.getMissingDiscriminator(); - assert.strictEqual(result.age, 1); - assert.isUndefined(result.kind); - } catch (err) { - assert.fail(err as string); - } + const result = await client.getMissingDiscriminator(); + assert.strictEqual(result.age, 1); + assert.isUndefined(result.kind); }); it("should get wrong discriminator body", async () => { - try { - const result = await client.getWrongDiscriminator(); - assert.strictEqual(result.age, 1); - assert.strictEqual(result.kind, "wrongKind"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.getWrongDiscriminator(); + assert.strictEqual(result.age, 1); + assert.strictEqual(result.kind, "wrongKind"); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/modelInheritanceNotDiscriminated.spec.ts b/packages/typespec-ts/test/modularIntegration/modelInheritanceNotDiscriminated.spec.ts index 8acaa5013b..3a5bb8e5e2 100644 --- a/packages/typespec-ts/test/modularIntegration/modelInheritanceNotDiscriminated.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/modelInheritanceNotDiscriminated.spec.ts @@ -16,29 +16,17 @@ describe("NotDiscriminatedClient Rest Client", () => { const validBody: Siamese = { name: "abc", age: 32, smart: true }; it("should get valid", async () => { - try { - const result = await client.getValid(); - assert.deepEqual(result, validBody); - } catch (err) { - assert.fail(err as string); - } + const result = await client.getValid(); + assert.deepEqual(result, validBody); }); it("should put valid", async () => { - try { - const result = await client.putValid(validBody); - assert.deepEqual(result, validBody); - } catch (err) { - assert.fail(err as string); - } + const result = await client.putValid(validBody); + assert.deepEqual(result, validBody); }); it("should post valid", async () => { - try { - const result = await client.postValid(validBody); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.postValid(validBody); + assert.isUndefined(result); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/modelInheritanceRecursive.spec.ts b/packages/typespec-ts/test/modularIntegration/modelInheritanceRecursive.spec.ts index 60cbf9efa0..c33a151204 100644 --- a/packages/typespec-ts/test/modularIntegration/modelInheritanceRecursive.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/modelInheritanceRecursive.spec.ts @@ -31,20 +31,12 @@ describe("Recursive Client", () => { }); it("Inheritance Recursive put test", async () => { - try { - const result = await client.put(body); - assert.isNotNull(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.put(body); + assert.isNotNull(result); }); it("Inheritance Recursive get test", async () => { - try { - const result = await client.get(); - assert.isNotNull(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.get(); + assert.isNotNull(result); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/modelInheritanceSingleDiscriminator.spec.ts b/packages/typespec-ts/test/modularIntegration/modelInheritanceSingleDiscriminator.spec.ts index 69fa6a1b47..92cb73b4ef 100644 --- a/packages/typespec-ts/test/modularIntegration/modelInheritanceSingleDiscriminator.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/modelInheritanceSingleDiscriminator.spec.ts @@ -40,66 +40,38 @@ describe("SingleDiscriminatorClient Rest Client", () => { } }; it("should get model with single discriminator", async () => { - try { - const result = await client.getModel(); - assert.deepEqual(result, validBody); - } catch (err) { - assert.fail(err as string); - } + const result = await client.getModel(); + assert.deepEqual(result, validBody); }); it("should put model with single discriminator", async () => { - try { - const result = await client.putModel(validBody); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.putModel(validBody); + assert.isUndefined(result); }); it("should get recursive model with single discriminator", async () => { - try { - const result = await client.getRecursiveModel(); - assert.deepEqual(result, validRecursiveBody); - } catch (err) { - assert.fail(err as string); - } + const result = await client.getRecursiveModel(); + assert.deepEqual(result, validRecursiveBody); }); it("should put recursive model with single discriminator", async () => { - try { - const result = await client.putRecursiveModel(validRecursiveBody); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.putRecursiveModel(validRecursiveBody); + assert.isUndefined(result); }); it("should get if missing discriminator", async () => { - try { - const result = await client.getMissingDiscriminator(); - assert.deepEqual(result.wingspan, 1); - assert.isUndefined(result.kind); - } catch (err) { - assert.fail(err as string); - } + const result = await client.getMissingDiscriminator(); + assert.deepEqual(result.wingspan, 1); + assert.isUndefined(result.kind); }); it("should get if wrong discriminator", async () => { - try { - const result = await client.getWrongDiscriminator(); - assert.deepEqual(result, { wingspan: 1, kind: "wrongKind" }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.getWrongDiscriminator(); + assert.deepEqual(result, { wingspan: 1, kind: "wrongKind" }); }); it("should get legacy model", async () => { - try { - const result = await client.getLegacyModel(); - assert.deepEqual(result, { size: 20, kind: "t-rex" }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.getLegacyModel(); + assert.deepEqual(result, { size: 20, kind: "t-rex" }); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/modelPropertyAdditional.spec.ts b/packages/typespec-ts/test/modularIntegration/modelPropertyAdditional.spec.ts index abba19853e..8fcce66255 100644 --- a/packages/typespec-ts/test/modularIntegration/modelPropertyAdditional.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/modelPropertyAdditional.spec.ts @@ -1,6 +1,8 @@ import { assert } from "chai"; import { AdditionalPropertiesClient } from "./generated/type/property/additional-properties/src/index.js"; + describe("ModelPropertyAdditional Client", () => { + let client: AdditionalPropertiesClient; beforeEach(() => { @@ -14,902 +16,583 @@ describe("ModelPropertyAdditional Client", () => { }); it("should get extends Different Spread Float value", async () => { - try { - const result = await client.extendsDifferentSpreadFloat.get(); - assert.deepEqual(result, { - name: "abc", - prop: 43.125, - derivedProp: 43.125 - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.extendsDifferentSpreadFloat.get(); + assert.deepEqual(result, { + name: "abc", + prop: 43.125, + derivedProp: 43.125 + }); }); - it("should put extends Different Spread Float value", async () => { - try { - const result = await client.extendsDifferentSpreadFloat.put({ - name: "abc", - prop: 43.125, - derivedProp: 43.125 - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.extendsDifferentSpreadFloat.put({ + name: "abc", + prop: 43.125, + derivedProp: 43.125 + }); + assert.equal(result, undefined); }); - it("should get extends Different Spread Model value", async () => { - try { - const result = await client.extendsDifferentSpreadModel.get(); - assert.deepEqual(result, { - knownProp: "abc", - prop: { state: "ok" }, - derivedProp: { state: "ok" } - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.extendsDifferentSpreadModel.get(); + assert.deepEqual(result, { + knownProp: "abc", + prop: { state: "ok" }, + derivedProp: { state: "ok" } + }); }); - it("should put extends Different Spread Model value", async () => { - try { - const result = await client.extendsDifferentSpreadModel.put({ - knownProp: "abc", - prop: { state: "ok" }, - derivedProp: { state: "ok" } - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.extendsDifferentSpreadModel.put({ + knownProp: "abc", + prop: { state: "ok" }, + derivedProp: { state: "ok" } + }); + assert.equal(result, undefined); }); - it("should get extends Different Spread Model Array value", async () => { - try { - const result = await client.extendsDifferentSpreadModelArray.get(); - assert.deepEqual(result, { - knownProp: "abc", - prop: [{ state: "ok" }, { state: "ok" }], - derivedProp: [{ state: "ok" }, { state: "ok" }] - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.extendsDifferentSpreadModelArray.get(); + assert.deepEqual(result, { + knownProp: "abc", + prop: [{ state: "ok" }, { state: "ok" }], + derivedProp: [{ state: "ok" }, { state: "ok" }] + }); }); - it("should put extends Different Spread Model Array value", async () => { - try { - const result = await client.extendsDifferentSpreadModelArray.put({ - knownProp: "abc", - prop: [{ state: "ok" }, { state: "ok" }], - derivedProp: [{ state: "ok" }, { state: "ok" }] - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.extendsDifferentSpreadModelArray.put({ + knownProp: "abc", + prop: [{ state: "ok" }, { state: "ok" }], + derivedProp: [{ state: "ok" }, { state: "ok" }] + }); + assert.equal(result, undefined); }); - it("should get extends Different Spread String value", async () => { - try { - const result = await client.extendsDifferentSpreadString.get(); - assert.deepEqual(result, { - id: 43.125, - prop: "abc", - derivedProp: "abc" - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.extendsDifferentSpreadString.get(); + assert.deepEqual(result, { + id: 43.125, + prop: "abc", + derivedProp: "abc" + }); }); - it("should put extends Different Spread String value", async () => { - try { - const result = await client.extendsDifferentSpreadString.put({ - id: 43.125, - prop: "abc", - derivedProp: "abc" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.extendsDifferentSpreadString.put({ + id: 43.125, + prop: "abc", + derivedProp: "abc" + }); + assert.equal(result, undefined); }); - it("should get extends Float value", async () => { - try { - const result = await client.extendsFloat.get(); - assert.deepEqual(result, { - id: 43.125, - prop: 43.125 - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.extendsFloat.get(); + assert.deepEqual(result, { + id: 43.125, + prop: 43.125 + }); }); - it("should put extends Float value", async () => { - try { - const result = await client.extendsFloat.put({ - id: 43.125, - prop: 43.125 - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.extendsFloat.put({ + id: 43.125, + prop: 43.125 + }); + assert.equal(result, undefined); }); - it("should get extends Model value", async () => { - try { - const result = await client.extendsModel.get(); - assert.deepEqual(result, { - knownProp: { state: "ok" }, - prop: { state: "ok" } - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.extendsModel.get(); + assert.deepEqual(result, { + knownProp: { state: "ok" }, + prop: { state: "ok" } + }); }); - it("should put extends Model value", async () => { - try { - const result = await client.extendsModel.put({ - knownProp: { state: "ok" }, - prop: { state: "ok" } - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.extendsModel.put({ + knownProp: { state: "ok" }, + prop: { state: "ok" } + }); + assert.equal(result, undefined); }); - it("should get extends Model Array value", async () => { - try { - const result = await client.extendsModelArray.get(); - assert.deepEqual(result, { - knownProp: [{ state: "ok" }, { state: "ok" }], - prop: [{ state: "ok" }, { state: "ok" }] - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.extendsModelArray.get(); + assert.deepEqual(result, { + knownProp: [{ state: "ok" }, { state: "ok" }], + prop: [{ state: "ok" }, { state: "ok" }] + }); }); - it("should put extends Model Array value", async () => { - try { - const result = await client.extendsModelArray.put({ - knownProp: [{ state: "ok" }, { state: "ok" }], - prop: [{ state: "ok" }, { state: "ok" }] - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.extendsModelArray.put({ + knownProp: [{ state: "ok" }, { state: "ok" }], + prop: [{ state: "ok" }, { state: "ok" }] + }); + assert.equal(result, undefined); }); - it("should get extends String value", async () => { - try { - const result = await client.extendsString.get(); - assert.deepEqual(result, { - name: "ExtendsStringAdditionalProperties", - prop: "abc" - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.extendsString.get(); + assert.deepEqual(result, { + name: "ExtendsStringAdditionalProperties", + prop: "abc" + }); }); - it("should put extends String value", async () => { - try { - const result = await client.extendsString.put({ - name: "ExtendsStringAdditionalProperties", - prop: "abc" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.extendsString.put({ + name: "ExtendsStringAdditionalProperties", + prop: "abc" + }); + assert.equal(result, undefined); }); - it("should get extends Unknown value", async () => { - try { - const result = await client.extendsUnknown.get(); - assert.deepEqual(result, { - name: "ExtendsUnknownAdditionalProperties", - prop1: 32, - prop2: true, - prop3: "abc" - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.extendsUnknown.get(); + assert.deepEqual(result, { + name: "ExtendsUnknownAdditionalProperties", + prop1: 32, + prop2: true, + prop3: "abc" + }); }); - it("should put extends Unknown value", async () => { - try { - const result = await client.extendsUnknown.put({ - name: "ExtendsUnknownAdditionalProperties", - prop1: 32, - prop2: true, - prop3: "abc" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.extendsUnknown.put({ + name: "ExtendsUnknownAdditionalProperties", + prop1: 32, + prop2: true, + prop3: "abc" + }); + assert.equal(result, undefined); }); - it("should get extends Unknown Derived value", async () => { - try { - const result = await client.extendsUnknownDerived.get(); - assert.deepEqual(result, { - name: "ExtendsUnknownAdditionalProperties", - index: 314, - age: 2.71875, - prop1: 32, - prop2: true, - prop3: "abc" - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.extendsUnknownDerived.get(); + assert.deepEqual(result, { + name: "ExtendsUnknownAdditionalProperties", + index: 314, + age: 2.71875, + prop1: 32, + prop2: true, + prop3: "abc" + }); }); - it("should put extends Unknown Derived value", async () => { - try { - const result = await client.extendsUnknownDerived.put({ - name: "ExtendsUnknownAdditionalProperties", - index: 314, - age: 2.71875, - prop1: 32, - prop2: true, - prop3: "abc" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.extendsUnknownDerived.put({ + name: "ExtendsUnknownAdditionalProperties", + index: 314, + age: 2.71875, + prop1: 32, + prop2: true, + prop3: "abc" + }); + assert.equal(result, undefined); }); - it("should get extends Unknown Discriminated value", async () => { - try { - const result = await client.extendsUnknownDiscriminated.get(); - assert.deepEqual(result, { - kind: "derived", - name: "Derived", - index: 314, - age: 2.71875, - prop1: 32, - prop2: true, - prop3: "abc" - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.extendsUnknownDiscriminated.get(); + assert.deepEqual(result, { + kind: "derived", + name: "Derived", + index: 314, + age: 2.71875, + prop1: 32, + prop2: true, + prop3: "abc" + }); }); - it("should put extends Unknown Discriminated value", async () => { - try { - const result = await client.extendsUnknownDiscriminated.put({ - kind: "derived", - name: "Derived", - index: 314, - age: 2.71875, - prop1: 32, - prop2: true, - prop3: "abc" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.extendsUnknownDiscriminated.put({ + kind: "derived", + name: "Derived", + index: 314, + age: 2.71875, + prop1: 32, + prop2: true, + prop3: "abc" + }); + assert.equal(result, undefined); }); - it("should get is Float value", async () => { - try { - const result = await client.isFloat.get(); - assert.deepEqual(result, { - id: 43.125, - prop: 43.125 - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.isFloat.get(); + assert.deepEqual(result, { + id: 43.125, + prop: 43.125 + }); }); - it("should put is Float value", async () => { - try { - const result = await client.isFloat.put({ - id: 43.125, - prop: 43.125 - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.isFloat.put({ + id: 43.125, + prop: 43.125 + }); + assert.equal(result, undefined); }); - it("should get is Model value", async () => { - try { - const result = await client.isModel.get(); - assert.deepEqual(result, { - knownProp: { state: "ok" }, - prop: { state: "ok" } - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.isModel.get(); + assert.deepEqual(result, { + knownProp: { state: "ok" }, + prop: { state: "ok" } + }); }); - it("should put is Model value", async () => { - try { - const result = await client.isModel.put({ - knownProp: { state: "ok" }, - prop: { state: "ok" } - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.isModel.put({ + knownProp: { state: "ok" }, + prop: { state: "ok" } + }); + assert.equal(result, undefined); }); - it("should get is Model Array value", async () => { - try { - const result = await client.isModelArray.get(); - assert.deepEqual(result, { - knownProp: [{ state: "ok" }, { state: "ok" }], - prop: [{ state: "ok" }, { state: "ok" }] - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.isModelArray.get(); + assert.deepEqual(result, { + knownProp: [{ state: "ok" }, { state: "ok" }], + prop: [{ state: "ok" }, { state: "ok" }] + }); }); - it("should put is Model Array value", async () => { - try { - const result = await client.isModelArray.put({ - knownProp: [{ state: "ok" }, { state: "ok" }], - prop: [{ state: "ok" }, { state: "ok" }] - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.isModelArray.put({ + knownProp: [{ state: "ok" }, { state: "ok" }], + prop: [{ state: "ok" }, { state: "ok" }] + }); + assert.equal(result, undefined); }); - it("should get is String value", async () => { - try { - const result = await client.isString.get(); - assert.deepEqual(result, { - name: "IsStringAdditionalProperties", - prop: "abc" - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.isString.get(); + assert.deepEqual(result, { + name: "IsStringAdditionalProperties", + prop: "abc" + }); }); - it("should put is String value", async () => { - try { - const result = await client.isString.put({ - name: "IsStringAdditionalProperties", - prop: "abc" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.isString.put({ + name: "IsStringAdditionalProperties", + prop: "abc" + }); + assert.equal(result, undefined); }); - it("should get is Unknown value", async () => { - try { - const result = await client.isUnknown.get(); - assert.deepEqual(result, { - name: "IsUnknownAdditionalProperties", - prop1: 32, - prop2: true, - prop3: "abc" - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.isUnknown.get(); + assert.deepEqual(result, { + name: "IsUnknownAdditionalProperties", + prop1: 32, + prop2: true, + prop3: "abc" + }); }); - it("should put isUnknown value", async () => { - try { - const result = await client.isUnknown.put({ - name: "IsUnknownAdditionalProperties", - prop1: 32, - prop2: true, - prop3: "abc" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.isUnknown.put({ + name: "IsUnknownAdditionalProperties", + prop1: 32, + prop2: true, + prop3: "abc" + }); + assert.equal(result, undefined); }); - it("should get is Unknown Derived value", async () => { - try { - const result = await client.isUnknownDerived.get(); - assert.deepEqual(result, { - name: "IsUnknownAdditionalProperties", - index: 314, - age: 2.71875, - prop1: 32, - prop2: true, - prop3: "abc" - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.isUnknownDerived.get(); + assert.deepEqual(result, { + name: "IsUnknownAdditionalProperties", + index: 314, + age: 2.71875, + prop1: 32, + prop2: true, + prop3: "abc" + }); }); - it("should put is Unknown Derived value", async () => { - try { - const result = await client.isUnknownDerived.put({ - name: "IsUnknownAdditionalProperties", - index: 314, - age: 2.71875, - prop1: 32, - prop2: true, - prop3: "abc" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.isUnknownDerived.put({ + name: "IsUnknownAdditionalProperties", + index: 314, + age: 2.71875, + prop1: 32, + prop2: true, + prop3: "abc" + }); + assert.equal(result, undefined); }); - it("should get is Unknown Discriminated value", async () => { - try { - const result = await client.isUnknownDiscriminated.get(); - assert.deepEqual(result, { - kind: "derived", - name: "Derived", - index: 314, - age: 2.71875, - prop1: 32, - prop2: true, - prop3: "abc" - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.isUnknownDiscriminated.get(); + assert.deepEqual(result, { + kind: "derived", + name: "Derived", + index: 314, + age: 2.71875, + prop1: 32, + prop2: true, + prop3: "abc" + }); }); - it("should put is Unknown Discriminated value", async () => { - try { - const result = await client.isUnknownDiscriminated.put({ - kind: "derived", - name: "Derived", - index: 314, - age: 2.71875, - prop1: 32, - prop2: true, - prop3: "abc" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.isUnknownDiscriminated.put({ + kind: "derived", + name: "Derived", + index: 314, + age: 2.71875, + prop1: 32, + prop2: true, + prop3: "abc" + }); + assert.equal(result, undefined); }); - it("should get multiple Spread value", async () => { - try { - const result = await client.multipleSpread.get(); - assert.deepEqual(result, { - flag: true, - prop1: "abc", - prop2: 43.125 - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.multipleSpread.get(); + assert.deepEqual(result, { + flag: true, + prop1: "abc", + prop2: 43.125 + }); }); - it("should put multiple Spread value", async () => { - try { - const result = await client.multipleSpread.put({ - flag: true, - prop1: "abc", - prop2: 43.125 - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.multipleSpread.put({ + flag: true, + prop1: "abc", + prop2: 43.125 + }); + assert.equal(result, undefined); }); - it("should get spread Different Float value", async () => { - try { - const result = await client.spreadDifferentFloat.get(); - assert.deepEqual(result, { - name: "abc", - prop: 43.125 - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.spreadDifferentFloat.get(); + assert.deepEqual(result, { + name: "abc", + prop: 43.125 + }); }); - it("should put spread Different Float value", async () => { - try { - const result = await client.spreadDifferentFloat.put({ - name: "abc", - prop: 43.125 - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.spreadDifferentFloat.put({ + name: "abc", + prop: 43.125 + }); + assert.equal(result, undefined); }); - it("should get spread Different Model value", async () => { - try { - const result = await client.spreadDifferentModel.get(); - assert.deepEqual(result, { - knownProp: "abc", - prop: { state: "ok" } - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.spreadDifferentModel.get(); + assert.deepEqual(result, { + knownProp: "abc", + prop: { state: "ok" } + }); }); - it("should put spread Different Model value", async () => { - try { - const result = await client.spreadDifferentModel.put({ - knownProp: "abc", - prop: { state: "ok" } - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.spreadDifferentModel.put({ + knownProp: "abc", + prop: { state: "ok" } + }); + assert.equal(result, undefined); }); - it("should get spread Different Model Array value", async () => { - try { - const result = await client.spreadDifferentModelArray.get(); - assert.deepEqual(result, { - knownProp: "abc", - prop: [{ state: "ok" }, { state: "ok" }] - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.spreadDifferentModelArray.get(); + assert.deepEqual(result, { + knownProp: "abc", + prop: [{ state: "ok" }, { state: "ok" }] + }); }); - it("should put spread Different Model Array value", async () => { - try { - const result = await client.spreadDifferentModelArray.put({ - knownProp: "abc", - prop: [{ state: "ok" }, { state: "ok" }] - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.spreadDifferentModelArray.put({ + knownProp: "abc", + prop: [{ state: "ok" }, { state: "ok" }] + }); + assert.equal(result, undefined); }); - it("should get spread Different String value", async () => { - try { - const result = await client.spreadDifferentString.get(); - assert.deepEqual(result, { - id: 43.125, - prop: "abc" - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.spreadDifferentString.get(); + assert.deepEqual(result, { + id: 43.125, + prop: "abc" + }); }); - it("should put spread Different String value", async () => { - try { - const result = await client.spreadDifferentString.put({ - id: 43.125, - prop: "abc" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.spreadDifferentString.put({ + id: 43.125, + prop: "abc" + }); + assert.equal(result, undefined); }); - it("should get spread Float value", async () => { - try { - const result = await client.spreadFloat.get(); - assert.deepEqual(result, { - id: 43.125, - prop: 43.125 - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.spreadFloat.get(); + assert.deepEqual(result, { + id: 43.125, + prop: 43.125 + }); }); - it("should put spread Float value", async () => { - try { - const result = await client.spreadFloat.put({ - id: 43.125, - prop: 43.125 - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.spreadFloat.put({ + id: 43.125, + prop: 43.125 + }); + assert.equal(result, undefined); }); - it("should get spread Model value", async () => { - try { - const result = await client.spreadModel.get(); - assert.deepEqual(result, { - knownProp: { state: "ok" }, - prop: { state: "ok" } - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.spreadModel.get(); + assert.deepEqual(result, { + knownProp: { state: "ok" }, + prop: { state: "ok" } + }); }); - it("should put spread Model value", async () => { - try { - const result = await client.spreadModel.put({ - knownProp: { state: "ok" }, - prop: { state: "ok" } - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.spreadModel.put({ + knownProp: { state: "ok" }, + prop: { state: "ok" } + }); + assert.equal(result, undefined); }); - it("should get spread Model Array value", async () => { - try { - const result = await client.spreadModelArray.get(); - assert.deepEqual(result, { - knownProp: [{ state: "ok" }, { state: "ok" }], - prop: [{ state: "ok" }, { state: "ok" }] - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.spreadModelArray.get(); + assert.deepEqual(result, { + knownProp: [{ state: "ok" }, { state: "ok" }], + prop: [{ state: "ok" }, { state: "ok" }] + }); }); - it("should put spread Model Array value", async () => { - try { - const result = await client.spreadModelArray.put({ - knownProp: [{ state: "ok" }, { state: "ok" }], - prop: [{ state: "ok" }, { state: "ok" }] - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.spreadModelArray.put({ + knownProp: [{ state: "ok" }, { state: "ok" }], + prop: [{ state: "ok" }, { state: "ok" }] + }); + assert.equal(result, undefined); }); - it("should get spread Record Discriminated Union value", async () => { - try { - const result = await client.spreadRecordDiscriminatedUnion.get(); - assert.deepEqual(result, { - name: "abc", - prop1: { - kind: "kind0", - fooProp: "abc" - }, - prop2: { - kind: "kind1", - start: "2021-01-01T00:00:00Z", - end: "2021-01-02T00:00:00Z" - } - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.spreadRecordDiscriminatedUnion.get(); + assert.deepEqual(result, { + name: "abc", + prop1: { + kind: "kind0", + fooProp: "abc" + }, + prop2: { + kind: "kind1", + start: "2021-01-01T00:00:00Z", + end: "2021-01-02T00:00:00Z" + } + }); }); - it("should put spread Record Discriminated Union value", async () => { - try { - const result = await client.spreadRecordDiscriminatedUnion.put({ - name: "abc", - prop1: { - kind: "kind0", - fooProp: "abc" - }, - prop2: { - kind: "kind1", - start: "2021-01-01T00:00:00Z", - end: "2021-01-02T00:00:00Z" - } - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.spreadRecordDiscriminatedUnion.put({ + name: "abc", + prop1: { + kind: "kind0", + fooProp: "abc" + }, + prop2: { + kind: "kind1", + start: "2021-01-01T00:00:00Z", + end: "2021-01-02T00:00:00Z" + } + }); + assert.equal(result, undefined); }); - it("should get spread Record NonDiscriminated Union value", async () => { - try { - const result = await client.spreadRecordNonDiscriminatedUnion.get(); - assert.deepEqual(result, { - name: "abc", - prop1: { - kind: "kind0", - fooProp: "abc" - }, - prop2: { - kind: "kind1", - start: "2021-01-01T00:00:00Z", - end: "2021-01-02T00:00:00Z" - } - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.spreadRecordNonDiscriminatedUnion.get(); + assert.deepEqual(result, { + name: "abc", + prop1: { + kind: "kind0", + fooProp: "abc" + }, + prop2: { + kind: "kind1", + start: "2021-01-01T00:00:00Z", + end: "2021-01-02T00:00:00Z" + } + }); }); - it("should put spread Record NonDiscriminated Union value", async () => { - try { - const result = await client.spreadRecordNonDiscriminatedUnion.put({ - name: "abc", - prop1: { - kind: "kind0", - fooProp: "abc" - }, - prop2: { - kind: "kind1", - start: "2021-01-01T00:00:00Z", - end: "2021-01-02T00:00:00Z" - } - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.spreadRecordNonDiscriminatedUnion.put({ + name: "abc", + prop1: { + kind: "kind0", + fooProp: "abc" + }, + prop2: { + kind: "kind1", + start: "2021-01-01T00:00:00Z", + end: "2021-01-02T00:00:00Z" + } + }); + assert.equal(result, undefined); }); - it("should get spread Record NonDiscriminated Union2 value", async () => { - try { - const result = await client.spreadRecordNonDiscriminatedUnion2.get(); - assert.deepEqual(result, { - name: "abc", - prop1: { - kind: "kind1", - start: "2021-01-01T00:00:00Z" - }, - prop2: { - kind: "kind1", - start: "2021-01-01T00:00:00Z", - end: "2021-01-02T00:00:00Z" - } - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.spreadRecordNonDiscriminatedUnion2.get(); + assert.deepEqual(result, { + name: "abc", + prop1: { + kind: "kind1", + start: "2021-01-01T00:00:00Z" + }, + prop2: { + kind: "kind1", + start: "2021-01-01T00:00:00Z", + end: "2021-01-02T00:00:00Z" + } + }); }); - it("should put spread Record NonDiscriminated Union2 value", async () => { - try { - const result = await client.spreadRecordNonDiscriminatedUnion2.put({ - name: "abc", - prop1: { + const result = await client.spreadRecordNonDiscriminatedUnion2.put({ + name: "abc", + prop1: { + kind: "kind1", + start: "2021-01-01T00:00:00Z" + }, + prop2: { + kind: "kind1", + start: "2021-01-01T00:00:00Z", + end: "2021-01-02T00:00:00Z" + } + }); + assert.equal(result, undefined); + }); + it("should get spread Record NonDiscriminated Union3 value", async () => { + const result = await client.spreadRecordNonDiscriminatedUnion3.get(); + assert.deepEqual(result, { + name: "abc", + prop1: [ + { kind: "kind1", start: "2021-01-01T00:00:00Z" }, - prop2: { + { kind: "kind1", - start: "2021-01-01T00:00:00Z", - end: "2021-01-02T00:00:00Z" - } - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } - }); - - it("should get spread Record NonDiscriminated Union3 value", async () => { - try { - const result = await client.spreadRecordNonDiscriminatedUnion3.get(); - assert.deepEqual(result, { - name: "abc", - prop1: [ - { - kind: "kind1", - start: "2021-01-01T00:00:00Z" - }, - { - kind: "kind1", - start: "2021-01-01T00:00:00Z" - } - ], - prop2: { - kind: "kind1", - start: "2021-01-01T00:00:00Z", - end: "2021-01-02T00:00:00Z" + start: "2021-01-01T00:00:00Z" } - }); - } catch (err) { - assert.fail(err as string); - } + ], + prop2: { + kind: "kind1", + start: "2021-01-01T00:00:00Z", + end: "2021-01-02T00:00:00Z" + } + }); }); - it("should put spread Record NonDiscriminated Union3 value", async () => { - try { - const result = await client.spreadRecordNonDiscriminatedUnion3.put({ - name: "abc", - prop1: [ - { - kind: "kind1", - start: "2021-01-01T00:00:00Z" - }, - { - kind: "kind1", - start: "2021-01-01T00:00:00Z" - } - ], - prop2: { + const result = await client.spreadRecordNonDiscriminatedUnion3.put({ + name: "abc", + prop1: [ + { kind: "kind1", - start: "2021-01-01T00:00:00Z", - end: "2021-01-02T00:00:00Z" + start: "2021-01-01T00:00:00Z" + }, + { + kind: "kind1", + start: "2021-01-01T00:00:00Z" } - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + ], + prop2: { + kind: "kind1", + start: "2021-01-01T00:00:00Z", + end: "2021-01-02T00:00:00Z" + } + }); + assert.equal(result, undefined); }); - it("should get spread Record Union value", async () => { - try { - const result = await client.spreadRecordUnion.get(); - assert.deepEqual(result, { - flag: true, - prop1: "abc", - prop2: 43.125 - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.spreadRecordUnion.get(); + assert.deepEqual(result, { + flag: true, + prop1: "abc", + prop2: 43.125 + }); }); - it("should put spread Record Union value", async () => { - try { - const result = await client.spreadRecordUnion.put({ - flag: true, - prop1: "abc", - prop2: 43.125 - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.spreadRecordUnion.put({ + flag: true, + prop1: "abc", + prop2: 43.125 + }); + assert.equal(result, undefined); }); - it("should get spread String value", async () => { - try { - const result = await client.spreadString.get(); - assert.deepEqual(result, { - name: "SpreadSpringRecord", - prop: "abc" - }); - } catch (err) { - assert.fail(err as string); - } + const result = await client.spreadString.get(); + assert.deepEqual(result, { + name: "SpreadSpringRecord", + prop: "abc" + }); }); - it("should put spread String value", async () => { - try { - const result = await client.spreadString.put({ - name: "SpreadSpringRecord", - prop: "abc" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.spreadString.put({ + name: "SpreadSpringRecord", + prop: "abc" + }); + assert.equal(result, undefined); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/modelPropertyType.spec.ts b/packages/typespec-ts/test/modularIntegration/modelPropertyType.spec.ts index 9da2cec161..0611505bff 100644 --- a/packages/typespec-ts/test/modularIntegration/modelPropertyType.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/modelPropertyType.spec.ts @@ -141,260 +141,252 @@ describe("ModelsPropertyTypesClient Rest Client", () => { }); for (let item of testedTypes) { it(`should get a ${item.type} value`, async () => { - try { - let result: any; - if (item.convertedToFn) { - item.defaultValue = item.convertedToFn(item.defaultValue); - } else { - item.defaultValue = item.defaultValue; - } - switch (item.type) { - case "boolean": - result = await client.boolean.get(); - break; - case "string": - result = await client.string.get(); - break; - case "bytes": - result = await client.bytes.get(); - break; - case "int": - result = await client.int.get(); - break; - case "float": - result = await client.float.get(); - break; - case "decimal": - result = await client.decimal.get(); - break; - case "decimal128": - result = await client.decimal128.get(); - break; - case "datetime": - result = await client.datetime.get(); - break; - case "duration": - result = await client.duration.get(); - break; - case "enum": - result = await client.enum.get(); - break; - case "extensible-enum": - result = await client.extensibleEnum.get(); - break; - case "model": - result = await client.model.get(); - break; - case "collections/string": - result = await client.collectionsString.get(); - break; - case "collections/int": - result = await client.collectionsInt.get(); - break; - case "collections/model": - result = await client.collectionsModel.get(); - break; - case "dictionary/string": - result = await client.dictionaryString.get(); - break; - case "never": - result = await client.never.get(); - break; - case "unknown/string": - result = await client.unknownString.get(); - break; - case "unknown/int": - result = await client.unknownInt.get(); - break; - case "unknown/dict": - result = await client.unknownDict.get(); - break; - case "unknown/array": - result = await client.unknownArray.get(); - break; - case "string/literal": - result = await client.stringLiteral.get(); - break; - case "int/literal": - result = await client.intLiteral.get(); - break; - case "float/literal": - result = await client.floatLiteral.get(); - break; - case "boolean/literal": - result = await client.booleanLiteral.get(); - break; - case "union/string/literal": - result = await client.unionStringLiteral.get(); - break; - case "union/int/literal": - result = await client.unionIntLiteral.get(); - break; - case "union/float/literal": - result = await client.unionFloatLiteral.get(); - break; - case "union-enum-value": - result = await client.unionEnumValue.get(); - break; - default: - throw new Error(`Unknown type ${item.type}`); - } - assert.deepEqual(result.property, item.defaultValue); - } catch (err) { - assert.fail(err as string); + let result: any; + if (item.convertedToFn) { + item.defaultValue = item.convertedToFn(item.defaultValue); + } else { + item.defaultValue = item.defaultValue; } + switch (item.type) { + case "boolean": + result = await client.boolean.get(); + break; + case "string": + result = await client.string.get(); + break; + case "bytes": + result = await client.bytes.get(); + break; + case "int": + result = await client.int.get(); + break; + case "float": + result = await client.float.get(); + break; + case "decimal": + result = await client.decimal.get(); + break; + case "decimal128": + result = await client.decimal128.get(); + break; + case "datetime": + result = await client.datetime.get(); + break; + case "duration": + result = await client.duration.get(); + break; + case "enum": + result = await client.enum.get(); + break; + case "extensible-enum": + result = await client.extensibleEnum.get(); + break; + case "model": + result = await client.model.get(); + break; + case "collections/string": + result = await client.collectionsString.get(); + break; + case "collections/int": + result = await client.collectionsInt.get(); + break; + case "collections/model": + result = await client.collectionsModel.get(); + break; + case "dictionary/string": + result = await client.dictionaryString.get(); + break; + case "never": + result = await client.never.get(); + break; + case "unknown/string": + result = await client.unknownString.get(); + break; + case "unknown/int": + result = await client.unknownInt.get(); + break; + case "unknown/dict": + result = await client.unknownDict.get(); + break; + case "unknown/array": + result = await client.unknownArray.get(); + break; + case "string/literal": + result = await client.stringLiteral.get(); + break; + case "int/literal": + result = await client.intLiteral.get(); + break; + case "float/literal": + result = await client.floatLiteral.get(); + break; + case "boolean/literal": + result = await client.booleanLiteral.get(); + break; + case "union/string/literal": + result = await client.unionStringLiteral.get(); + break; + case "union/int/literal": + result = await client.unionIntLiteral.get(); + break; + case "union/float/literal": + result = await client.unionFloatLiteral.get(); + break; + case "union-enum-value": + result = await client.unionEnumValue.get(); + break; + default: + throw new Error(`Unknown type ${item.type}`); + } + assert.deepEqual(result.property, item.defaultValue); }); } for (let item of testedTypes) { it(`should put a ${item.type} value`, async () => { - try { - let result: any; - if (item.convertedToFn) { - item.defaultValue = item.convertedToFn(item.defaultValue); - } else { - item.defaultValue = item.defaultValue; - } - switch (item.type) { - case "boolean": - result = await client.boolean.put({ property: item.defaultValue }); - break; - case "string": - result = await client.string.put({ property: item.defaultValue }); - break; - case "bytes": - result = await client.bytes.put({ - property: item.defaultValue - }); - break; - case "int": - result = await client.int.put({ property: item.defaultValue }); - break; - case "float": - result = await client.float.put({ property: item.defaultValue }); - break; - case "decimal": - result = await client.decimal.put({ property: item.defaultValue }); - break; - case "decimal128": - result = await client.decimal128.put({ - property: item.defaultValue - }); - break; - case "datetime": - result = await client.datetime.put({ - property: item.defaultValue - }); - break; - case "duration": - result = await client.duration.put({ - property: item.defaultValue - }); - break; - case "enum": - result = await client.enum.put({ property: item.defaultValue }); - break; - case "extensible-enum": - result = await client.extensibleEnum.put({ - property: item.defaultValue - }); - break; - case "model": - result = await client.model.put({ - property: item.defaultValue - }); - break; - case "collections/string": - result = await client.collectionsString.put({ - property: item.defaultValue - }); - break; - case "collections/int": - result = await client.collectionsInt.put({ - property: item.defaultValue - }); - break; - case "collections/model": - result = await client.collectionsModel.put({ - property: item.defaultValue - }); - break; - case "dictionary/string": - result = await client.dictionaryString.put({ - property: item.defaultValue - }); - break; - case "never": - result = await client.never.put({ - property: item.defaultValue as never - }); - break; - case "unknown/string": - result = await client.unknownString.put({ - property: item.defaultValue - }); - break; - case "unknown/int": - result = await client.unknownInt.put({ - property: item.defaultValue - }); - break; - case "unknown/dict": - result = await client.unknownDict.put({ - property: item.defaultValue - }); - break; - case "unknown/array": - result = await client.unknownArray.put({ - property: item.defaultValue - }); - break; - case "string/literal": - result = await client.stringLiteral.put({ - property: item.defaultValue - }); - break; - case "int/literal": - result = await client.intLiteral.put({ - property: item.defaultValue - }); - break; - case "float/literal": - result = await client.floatLiteral.put({ - property: item.defaultValue - }); - break; - case "boolean/literal": - result = await client.booleanLiteral.put({ - property: item.defaultValue - }); - break; - case "union/string/literal": - result = await client.unionStringLiteral.put({ - property: item.defaultValue - }); - break; - case "union/int/literal": - result = await client.unionIntLiteral.put({ - property: item.defaultValue - }); - break; - case "union/float/literal": - result = await client.unionFloatLiteral.put({ - property: item.defaultValue - }); - break; - case "union-enum-value": - result = await client.unionEnumValue.put({ - property: item.defaultValue - }); - break; - default: - throw new Error(`Unknown type ${item.type}`); - } - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); + let result: any; + if (item.convertedToFn) { + item.defaultValue = item.convertedToFn(item.defaultValue); + } else { + item.defaultValue = item.defaultValue; + } + switch (item.type) { + case "boolean": + result = await client.boolean.put({ property: item.defaultValue }); + break; + case "string": + result = await client.string.put({ property: item.defaultValue }); + break; + case "bytes": + result = await client.bytes.put({ + property: item.defaultValue + }); + break; + case "int": + result = await client.int.put({ property: item.defaultValue }); + break; + case "float": + result = await client.float.put({ property: item.defaultValue }); + break; + case "decimal": + result = await client.decimal.put({ property: item.defaultValue }); + break; + case "decimal128": + result = await client.decimal128.put({ + property: item.defaultValue + }); + break; + case "datetime": + result = await client.datetime.put({ + property: item.defaultValue + }); + break; + case "duration": + result = await client.duration.put({ + property: item.defaultValue + }); + break; + case "enum": + result = await client.enum.put({ property: item.defaultValue }); + break; + case "extensible-enum": + result = await client.extensibleEnum.put({ + property: item.defaultValue + }); + break; + case "model": + result = await client.model.put({ + property: item.defaultValue + }); + break; + case "collections/string": + result = await client.collectionsString.put({ + property: item.defaultValue + }); + break; + case "collections/int": + result = await client.collectionsInt.put({ + property: item.defaultValue + }); + break; + case "collections/model": + result = await client.collectionsModel.put({ + property: item.defaultValue + }); + break; + case "dictionary/string": + result = await client.dictionaryString.put({ + property: item.defaultValue + }); + break; + case "never": + result = await client.never.put({ + property: item.defaultValue as never + }); + break; + case "unknown/string": + result = await client.unknownString.put({ + property: item.defaultValue + }); + break; + case "unknown/int": + result = await client.unknownInt.put({ + property: item.defaultValue + }); + break; + case "unknown/dict": + result = await client.unknownDict.put({ + property: item.defaultValue + }); + break; + case "unknown/array": + result = await client.unknownArray.put({ + property: item.defaultValue + }); + break; + case "string/literal": + result = await client.stringLiteral.put({ + property: item.defaultValue + }); + break; + case "int/literal": + result = await client.intLiteral.put({ + property: item.defaultValue + }); + break; + case "float/literal": + result = await client.floatLiteral.put({ + property: item.defaultValue + }); + break; + case "boolean/literal": + result = await client.booleanLiteral.put({ + property: item.defaultValue + }); + break; + case "union/string/literal": + result = await client.unionStringLiteral.put({ + property: item.defaultValue + }); + break; + case "union/int/literal": + result = await client.unionIntLiteral.put({ + property: item.defaultValue + }); + break; + case "union/float/literal": + result = await client.unionFloatLiteral.put({ + property: item.defaultValue + }); + break; + case "union-enum-value": + result = await client.unionEnumValue.put({ + property: item.defaultValue + }); + break; + default: + throw new Error(`Unknown type ${item.type}`); } + assert.isUndefined(result); }); } }); diff --git a/packages/typespec-ts/test/modularIntegration/modelsEmpty.spec.ts b/packages/typespec-ts/test/modularIntegration/modelsEmpty.spec.ts index 5e8246c3e0..1bb7dbb5c1 100644 --- a/packages/typespec-ts/test/modularIntegration/modelsEmpty.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/modelsEmpty.spec.ts @@ -13,31 +13,19 @@ describe("Empty Client", () => { }); it("should put empty value", async () => { - try { - const result = await client.putEmpty(body); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.putEmpty(body); + assert.isUndefined(result); }); it("should get empty value", async () => { - try { - const result = await client.getEmpty(); - assert.isNotNull(result); - assert.strictEqual(JSON.stringify(result), JSON.stringify(body)); - } catch (err) { - assert.fail(err as string); - } + const result = await client.getEmpty(); + assert.isNotNull(result); + assert.strictEqual(JSON.stringify(result), JSON.stringify(body)); }); it("should post round trip empty value", async () => { - try { - const result = await client.postRoundTripEmpty(body); - assert.isNotNull(result); - assert.strictEqual(JSON.stringify(result), JSON.stringify(body)); - } catch (err) { - assert.fail(err as string); - } + const result = await client.postRoundTripEmpty(body); + assert.isNotNull(result); + assert.strictEqual(JSON.stringify(result), JSON.stringify(body)); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/payloadMediaType.spec.ts b/packages/typespec-ts/test/modularIntegration/payloadMediaType.spec.ts index e0c695ae90..8a3ae073c0 100644 --- a/packages/typespec-ts/test/modularIntegration/payloadMediaType.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/payloadMediaType.spec.ts @@ -12,41 +12,25 @@ describe("MediaType Client", () => { }); it("should getAsText", async () => { - try { - const result = await client.stringBody.getAsText({ - requestOptions: { headers: { accept: "text/plain" } } - }); - assert.strictEqual(result, "{cat}"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.stringBody.getAsText({ + requestOptions: { headers: { accept: "text/plain" } } + }); + assert.strictEqual(result, "{cat}"); }); it("should sendAsText", async () => { - try { - const result = await client.stringBody.sendAsText("{cat}"); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.stringBody.sendAsText("{cat}"); + assert.isUndefined(result); }); it("should getAsJson", async () => { - try { - const result = await client.stringBody.getAsJson(); - console.log(result); - assert.strictEqual(result, "foo"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.stringBody.getAsJson(); + console.log(result); + assert.strictEqual(result, "foo"); }); it("should sendAsJson", async () => { - try { - const result = await client.stringBody.sendAsJson("foo"); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.stringBody.sendAsJson("foo"); + assert.isUndefined(result); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/payloadPageable.spec.ts b/packages/typespec-ts/test/modularIntegration/payloadPageable.spec.ts index 9444683624..283fa2b06c 100644 --- a/packages/typespec-ts/test/modularIntegration/payloadPageable.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/payloadPageable.spec.ts @@ -36,14 +36,10 @@ describe("PageableClient Classical Client", () => { maxpagesize: 3 }); const items = []; - try { - for await (const user of iter) { - items.push(user); - } - assert.strictEqual(items.length, 4); - } catch (err: any) { - assert.fail(err as string); + for await (const user of iter) { + items.push(user); } + assert.strictEqual(items.length, 4); }); it("should list all users byPage", async () => { @@ -51,14 +47,10 @@ describe("PageableClient Classical Client", () => { maxpagesize: 3 }); const items: User[] = []; - try { - for await (const user of iter.byPage()) { - items.push(...user); - } - assert.strictEqual(items.length, 4); - } catch (err: any) { - assert.fail(err as string); + for await (const user of iter.byPage()) { + items.push(...user); } + assert.strictEqual(items.length, 4); }); it("should list left users byPage if continuationToken is set", async () => { diff --git a/packages/typespec-ts/test/modularIntegration/scalar.spec.ts b/packages/typespec-ts/test/modularIntegration/scalar.spec.ts index bcdab0b4cb..b6d524a713 100644 --- a/packages/typespec-ts/test/modularIntegration/scalar.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/scalar.spec.ts @@ -14,135 +14,87 @@ describe("Scalar Client", () => { }); it("should get string value", async () => { - try { - const result = await client.string.get({ - requestOptions: { - headers: { - accept: "text/plain" - } + const result = await client.string.get({ + requestOptions: { + headers: { + accept: "text/plain" } - }); - assert.strictEqual(result, "test"); - } catch (err) { - assert.fail(err as string); - } + } + }); + assert.strictEqual(result, "test"); }); it("should put string value", async () => { - try { - const result = await client.string.put("test", { - requestOptions: { - headers: { - "content-type": "text/plain" - } + const result = await client.string.put("test", { + requestOptions: { + headers: { + "content-type": "text/plain" } - }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + } + }); + assert.isUndefined(result); }); it("should get boolean value", async () => { - try { - const result = await client.boolean.get(); - assert.strictEqual(result, true); - } catch (err) { - assert.fail(err as string); - } + const result = await client.boolean.get(); + assert.strictEqual(result, true); }); it("should put boolean value", async () => { - try { - const result = await client.boolean.put(true); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.boolean.put(true); + assert.isUndefined(result); }); it("should get unknown value", async () => { - try { - const result = await client.unknown.get({ - requestOptions: { - headers: { - accept: "text/plain" - } + const result = await client.unknown.get({ + requestOptions: { + headers: { + accept: "text/plain" } - }); - assert.strictEqual(result, "test"); - } catch (err) { - assert.fail(err as string); - } + } + }); + assert.strictEqual(result, "test"); }); it("should put unknown value", async () => { - try { - const result = await client.unknown.put("test", { - requestOptions: { - headers: { - "content-type": "text/plain" - } + const result = await client.unknown.put("test", { + requestOptions: { + headers: { + "content-type": "text/plain" } - }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + } + }); + assert.isUndefined(result); }); it("should get decimal response body", async () => { - try { - const result = await client.decimalType.responseBody(); - assert.strictEqual(result, 0.33333); - } catch (err) { - assert.fail(err as string); - } + const result = await client.decimalType.responseBody(); + assert.strictEqual(result, 0.33333); }); it("should put decimal request body", async () => { - try { - const result = await client.decimalType.requestBody(0.33333); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.decimalType.requestBody(0.33333); + assert.isUndefined(result); }); it("should get decimal request parameter", async () => { - try { - const result = await client.decimalType.requestParameter(0.33333); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.decimalType.requestParameter(0.33333); + assert.isUndefined(result); }); it("should get decimal128 response body", async () => { - try { - const result = await client.decimal128Type.responseBody(); - assert.strictEqual(result, 0.33333); - } catch (err) { - assert.fail(err as string); - } + const result = await client.decimal128Type.responseBody(); + assert.strictEqual(result, 0.33333); }); it("should put decimal128 request body", async () => { - try { - const result = await client.decimal128Type.requestBody(0.33333); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.decimal128Type.requestBody(0.33333); + assert.isUndefined(result); }); it("should get decimal128 request parameter", async () => { - try { - const result = await client.decimal128Type.requestParameter(0.33333); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.decimal128Type.requestParameter(0.33333); + assert.isUndefined(result); }); it("should fail to post decimal verify", async () => { diff --git a/packages/typespec-ts/test/modularIntegration/serializationEncodeNameJson.spec.ts b/packages/typespec-ts/test/modularIntegration/serializationEncodeNameJson.spec.ts index 04f156052c..6050a31a37 100644 --- a/packages/typespec-ts/test/modularIntegration/serializationEncodeNameJson.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/serializationEncodeNameJson.spec.ts @@ -14,20 +14,12 @@ describe("NameAndEncodedName Client", () => { }); it("should get encoded-name json property", async () => { - try { - const result = await client.get(); - assert.strictEqual(result.defaultName, true); - } catch (err) { - assert.fail(err as string); - } + const result = await client.get(); + assert.strictEqual(result.defaultName, true); }); it("should post encoded-name json property", async () => { - try { - const result = await client.send({ defaultName: true }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.send({ defaultName: true }); + assert.isUndefined(result); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/server.spec.ts b/packages/typespec-ts/test/modularIntegration/server.spec.ts index ef16dbbe41..a7bda7798f 100644 --- a/packages/typespec-ts/test/modularIntegration/server.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/server.spec.ts @@ -16,12 +16,8 @@ describe("Single Server Path Client", () => { }); it("should work with no param", async () => { - try { - const result = await client.myOp(); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.myOp(); + assert.isUndefined(result); }); }); @@ -38,21 +34,13 @@ describe("Multiple Server Path Client", () => { }); it("should work with no param", async () => { - try { - const result = await client.noOperationParams(); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.noOperationParams(); + assert.isUndefined(result); }); it("should work with param", async () => { - try { - const result = await client.withOperationPathParam("test"); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.withOperationPathParam("test"); + assert.isUndefined(result); }); }); @@ -69,30 +57,18 @@ describe("NotVersioned Server Version Client", () => { }); it("should work without apiVersion", async () => { - try { - const result = await client.withoutApiVersion(); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.withoutApiVersion(); + assert.isUndefined(result); }); it("should work with param", async () => { - try { - const result = await client.withQueryApiVersion("v1.0"); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.withQueryApiVersion("v1.0"); + assert.isUndefined(result); }); it("should work with path param", async () => { - try { - const result = await client.withPathApiVersion("v1.0"); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.withPathApiVersion("v1.0"); + assert.isUndefined(result); }); }); @@ -109,51 +85,31 @@ describe("Versioned Server Version Client", () => { }); it("should work without apiVersion", async () => { - try { - const result = await client.withoutApiVersion(); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.withoutApiVersion(); + assert.isUndefined(result); }); it("should work with param with default value", async () => { - try { - const result = await client.withQueryApiVersion(); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.withQueryApiVersion(); + assert.isUndefined(result); }); it("should work with param with explicit value", async () => { - try { - const result = await client.withQueryApiVersion({ - apiVersion: "2022-12-01-preview" - }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.withQueryApiVersion({ + apiVersion: "2022-12-01-preview" + }); + assert.isUndefined(result); }); it("should work with path param", async () => { - try { - const result = await client.withPathApiVersion("2022-12-01-preview"); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.withPathApiVersion("2022-12-01-preview"); + assert.isUndefined(result); }); it("should work with param with old value", async () => { - try { - const result = await client.withQueryOldApiVersion({ - apiVersion: "2021-01-01-preview" - }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.withQueryOldApiVersion({ + apiVersion: "2021-01-01-preview" + }); + assert.isUndefined(result); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/serverEndpointNotDefined.spec.ts b/packages/typespec-ts/test/modularIntegration/serverEndpointNotDefined.spec.ts index 358248dace..7c38eaaa51 100644 --- a/packages/typespec-ts/test/modularIntegration/serverEndpointNotDefined.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/serverEndpointNotDefined.spec.ts @@ -11,11 +11,7 @@ describe("NotDefined Server Endpoint Client", () => { }); it("should work with not defined endpoint", async () => { - try { - const result = await client.valid(); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.valid(); + assert.isUndefined(result); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/specialWords.spec.ts b/packages/typespec-ts/test/modularIntegration/specialWords.spec.ts index c33cc2b578..b36c762520 100644 --- a/packages/typespec-ts/test/modularIntegration/specialWords.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/specialWords.spec.ts @@ -12,979 +12,475 @@ describe("Special Words Client", () => { }); it("should post modelProperties sameAsModel", async () => { - try { - const result = await client.modelProperties.sameAsModel({ - sameAsModel: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.modelProperties.sameAsModel({ + sameAsModel: "ok" + }); + assert.equal(result, undefined); }); - it("should get operations And", async () => { - try { - const result = await client.operations.and(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.and(); + assert.equal(result, undefined); }); - it("should get operations As", async () => { - try { - const result = await client.operations.as(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.as(); + assert.equal(result, undefined); }); - it("should get operations Assert", async () => { - try { - const result = await client.operations.assert(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.assert(); + assert.equal(result, undefined); }); - it("should get operations Async", async () => { - try { - const result = await client.operations.async(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.async(); + assert.equal(result, undefined); }); - it("should get operations Await", async () => { - try { - const result = await client.operations.await(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.await(); + assert.equal(result, undefined); }); - it("should get operations Break", async () => { - try { - const result = await client.operations.break(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.break(); + assert.equal(result, undefined); }); - it("should get operations Class", async () => { - try { - const result = await client.operations.class(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.class(); + assert.equal(result, undefined); }); - it("should get operations Constructor", async () => { - try { - const result = await client.operations.constructor(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.constructor(); + assert.equal(result, undefined); }); - it("should get operations Continue", async () => { - try { - const result = await client.operations.continue(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.continue(); + assert.equal(result, undefined); }); - it("should get operations Def", async () => { - try { - const result = await client.operations.def(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.def(); + assert.equal(result, undefined); }); - it("should get operations Del", async () => { - try { - const result = await client.operations.del(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.del(); + assert.equal(result, undefined); }); - it("should get operations Elif", async () => { - try { - const result = await client.operations.elif(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.elif(); + assert.equal(result, undefined); }); - it("should get operations Else", async () => { - try { - const result = await client.operations.else(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.else(); + assert.equal(result, undefined); }); - it("should get operations Except", async () => { - try { - const result = await client.operations.except(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.except(); + assert.equal(result, undefined); }); - it("should get operations Exec", async () => { - try { - const result = await client.operations.exec(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.exec(); + assert.equal(result, undefined); }); - it("should get operations Finally", async () => { - try { - const result = await client.operations.finally(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.finally(); + assert.equal(result, undefined); }); - it("should get operations For", async () => { - try { - const result = await client.operations.for(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.for(); + assert.equal(result, undefined); }); - it("should get operations From", async () => { - try { - const result = await client.operations.from(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.from(); + assert.equal(result, undefined); }); - it("should get operations Global", async () => { - try { - const result = await client.operations.global(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.global(); + assert.equal(result, undefined); }); - it("should get operations If", async () => { - try { - const result = await client.operations.if(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.if(); + assert.equal(result, undefined); }); - it("should get operations Import", async () => { - try { - const result = await client.operations.import(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.import(); + assert.equal(result, undefined); }); - it("should get operations In", async () => { - try { - const result = await client.operations.in(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.in(); + assert.equal(result, undefined); }); - it("should get operations Is", async () => { - try { - const result = await client.operations.is(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.is(); + assert.equal(result, undefined); }); - it("should get operations Lambda", async () => { - try { - const result = await client.operations.lambda(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.lambda(); + assert.equal(result, undefined); }); - it("should get operations Not", async () => { - try { - const result = await client.operations.not(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.not(); + assert.equal(result, undefined); }); - it("should get operations Or", async () => { - try { - const result = await client.operations.or(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.or(); + assert.equal(result, undefined); }); - it("should get operations Pass", async () => { - try { - const result = await client.operations.pass(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.pass(); + assert.equal(result, undefined); }); - it("should get operations Raise", async () => { - try { - const result = await client.operations.raise(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.raise(); + assert.equal(result, undefined); }); - it("should get operations Return", async () => { - try { - const result = await client.operations.return(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.return(); + assert.equal(result, undefined); }); - it("should get operations Try", async () => { - try { - const result = await client.operations.try(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.try(); + assert.equal(result, undefined); }); - it("should get operations While", async () => { - try { - const result = await client.operations.while(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.while(); + assert.equal(result, undefined); }); - it("should get operations With", async () => { - try { - const result = await client.operations.with(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.with(); + assert.equal(result, undefined); }); - it("should get operations Yield", async () => { - try { - const result = await client.operations.yield(); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.operations.yield(); + assert.equal(result, undefined); }); - it("should post parameters withAnd", async () => { - try { - const result = await client.parameters.withAnd("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withAnd("ok"); + assert.equal(result, undefined); }); - it("should post parameters withAs", async () => { - try { - const result = await client.parameters.withAs("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withAs("ok"); + assert.equal(result, undefined); }); - it("should post parameters withAssert", async () => { - try { - const result = await client.parameters.withAssert("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withAssert("ok"); + assert.equal(result, undefined); }); - it("should post parameters withAsync", async () => { - try { - const result = await client.parameters.withAsync("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withAsync("ok"); + assert.equal(result, undefined); }); - it("should post parameters withAwait", async () => { - try { - const result = await client.parameters.withAwait("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withAwait("ok"); + assert.equal(result, undefined); }); - it("should post parameters withBreak", async () => { - try { - const result = await client.parameters.withBreak("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withBreak("ok"); + assert.equal(result, undefined); }); - it("should post parameters withClass", async () => { - try { - const result = await client.parameters.withClass("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withClass("ok"); + assert.equal(result, undefined); }); - it("should post parameters withConstructor", async () => { - try { - const result = await client.parameters.withConstructor("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withConstructor("ok"); + assert.equal(result, undefined); }); - it("should post parameters withContinue", async () => { - try { - const result = await client.parameters.withContinue("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withContinue("ok"); + assert.equal(result, undefined); }); - it("should post parameters withDef", async () => { - try { - const result = await client.parameters.withDef("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withDef("ok"); + assert.equal(result, undefined); }); - it("should post parameters withDel", async () => { - try { - const result = await client.parameters.withDel("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withDel("ok"); + assert.equal(result, undefined); }); - it("should post parameters withElif", async () => { - try { - const result = await client.parameters.withElif("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withElif("ok"); + assert.equal(result, undefined); }); - it("should post parameters withElse", async () => { - try { - const result = await client.parameters.withElse("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withElse("ok"); + assert.equal(result, undefined); }); - it("should post parameters withExcept", async () => { - try { - const result = await client.parameters.withExcept("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withExcept("ok"); + assert.equal(result, undefined); }); - it("should post parameters withExec", async () => { - try { - const result = await client.parameters.withExec("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withExec("ok"); + assert.equal(result, undefined); }); - it("should post parameters withFinally", async () => { - try { - const result = await client.parameters.withFinally("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withFinally("ok"); + assert.equal(result, undefined); }); - it("should post parameters withFor", async () => { - try { - const result = await client.parameters.withFor("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withFor("ok"); + assert.equal(result, undefined); }); - it("should post parameters withFrom", async () => { - try { - const result = await client.parameters.withFrom("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withFrom("ok"); + assert.equal(result, undefined); }); - it("should post parameters withGlobal", async () => { - try { - const result = await client.parameters.withGlobal("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withGlobal("ok"); + assert.equal(result, undefined); }); - it("should post parameters withIf", async () => { - try { - const result = await client.parameters.withIf("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withIf("ok"); + assert.equal(result, undefined); }); - it("should post parameters withImport", async () => { - try { - const result = await client.parameters.withImport("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withImport("ok"); + assert.equal(result, undefined); }); - it("should post parameters withIn", async () => { - try { - const result = await client.parameters.withIn("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withIn("ok"); + assert.equal(result, undefined); }); - it("should post parameters withIs", async () => { - try { - const result = await client.parameters.withIs("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withIs("ok"); + assert.equal(result, undefined); }); - it("should post parameters withLambda", async () => { - try { - const result = await client.parameters.withLambda("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withLambda("ok"); + assert.equal(result, undefined); }); - it("should post parameters withNot", async () => { - try { - const result = await client.parameters.withNot("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withNot("ok"); + assert.equal(result, undefined); }); - it("should post parameters withOr", async () => { - try { - const result = await client.parameters.withOr("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withOr("ok"); + assert.equal(result, undefined); }); - it("should post parameters withPass", async () => { - try { - const result = await client.parameters.withPass("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withPass("ok"); + assert.equal(result, undefined); }); - it("should post parameters withRaise", async () => { - try { - const result = await client.parameters.withRaise("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withRaise("ok"); + assert.equal(result, undefined); }); - it("should post parameters withReturn", async () => { - try { - const result = await client.parameters.withReturn("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withReturn("ok"); + assert.equal(result, undefined); }); - it("should post parameters withTry", async () => { - try { - const result = await client.parameters.withTry("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withTry("ok"); + assert.equal(result, undefined); }); - it("should post parameters withWhile", async () => { - try { - const result = await client.parameters.withWhile("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withWhile("ok"); + assert.equal(result, undefined); }); - it("should post parameters withWith", async () => { - try { - const result = await client.parameters.withWith("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withWith("ok"); + assert.equal(result, undefined); }); - it("should post parameters withYield", async () => { - try { - const result = await client.parameters.withYield("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withYield("ok"); + assert.equal(result, undefined); }); - it("should post parameters withCancellationToken", async () => { - try { - const result = await client.parameters.withCancellationToken("ok"); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.parameters.withCancellationToken("ok"); + assert.equal(result, undefined); }); - it("should post models withAnd", async () => { - try { - const result = await client.models.withAnd({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withAnd({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withAs", async () => { - try { - const result = await client.models.withAs({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withAs({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withAssert", async () => { - try { - const result = await client.models.withAssert({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withAssert({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withAsync", async () => { - try { - const result = await client.models.withAsync({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withAsync({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withAwait", async () => { - try { - const result = await client.models.withAwait({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withAwait({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withBreak", async () => { - try { - const result = await client.models.withBreak({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withBreak({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withClass", async () => { - try { - const result = await client.models.withClass({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withClass({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withConstructor", async () => { - try { - const result = await client.models.withConstructor({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withConstructor({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withContinue", async () => { - try { - const result = await client.models.withContinue({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withContinue({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withDef", async () => { - try { - const result = await client.models.withDef({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withDef({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withDel", async () => { - try { - const result = await client.models.withDel({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withDel({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withElif", async () => { - try { - const result = await client.models.withElif({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withElif({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withElse", async () => { - try { - const result = await client.models.withElse({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withElse({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withExcept", async () => { - try { - const result = await client.models.withExcept({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withExcept({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withExec", async () => { - try { - const result = await client.models.withExec({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withExec({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withFinally", async () => { - try { - const result = await client.models.withFinally({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withFinally({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withFor", async () => { - try { - const result = await client.models.withFor({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withFor({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withFrom", async () => { - try { - const result = await client.models.withFrom({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withFrom({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withGlobal", async () => { - try { - const result = await client.models.withGlobal({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withGlobal({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withIf", async () => { - try { - const result = await client.models.withIf({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withIf({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withImport", async () => { - try { - const result = await client.models.withImport({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withImport({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withIn", async () => { - try { - const result = await client.models.withIn({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withIn({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withIs", async () => { - try { - const result = await client.models.withIs({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withIs({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withLambda", async () => { - try { - const result = await client.models.withLambda({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withLambda({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withNot", async () => { - try { - const result = await client.models.withNot({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withNot({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withOr", async () => { - try { - const result = await client.models.withOr({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withOr({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withPass", async () => { - try { - const result = await client.models.withPass({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withPass({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withRaise", async () => { - try { - const result = await client.models.withRaise({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withRaise({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withReturn", async () => { - try { - const result = await client.models.withReturn({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withReturn({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withTry", async () => { - try { - const result = await client.models.withTry({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withTry({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withWhile", async () => { - try { - const result = await client.models.withWhile({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withWhile({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withWith", async () => { - try { - const result = await client.models.withWith({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withWith({ + name: "ok" + }); + assert.equal(result, undefined); }); - it("should post models withYield", async () => { - try { - const result = await client.models.withYield({ - name: "ok" - }); - assert.equal(result, undefined); - } catch (err) { - assert.fail(err as string); - } + const result = await client.models.withYield({ + name: "ok" + }); + assert.equal(result, undefined); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/spreadParameters.spec.ts b/packages/typespec-ts/test/modularIntegration/spreadParameters.spec.ts index 0a729203cb..fd25140233 100644 --- a/packages/typespec-ts/test/modularIntegration/spreadParameters.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/spreadParameters.spec.ts @@ -11,122 +11,82 @@ describe("SpreadClient Client", () => { }); it("should spread named model", async () => { - try { - const result = await client.model.spreadAsRequestBody("foo"); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.model.spreadAsRequestBody("foo"); + assert.isUndefined(result); }); it("should spread alias with only body param", async () => { - try { - const result = await client.alias.spreadAsRequestBody("foo"); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.alias.spreadAsRequestBody("foo"); + assert.isUndefined(result); }); it("should spread model composite request only with body", async () => { - try { - const result = await client.model.spreadCompositeRequestOnlyWithBody({ - name: "foo" - }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.model.spreadCompositeRequestOnlyWithBody({ + name: "foo" + }); + assert.isUndefined(result); }); it("should spread model composite request without body", async () => { - try { - const result = await client.model.spreadCompositeRequestWithoutBody( - "foo", - "bar" - ); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.model.spreadCompositeRequestWithoutBody( + "foo", + "bar" + ); + assert.isUndefined(result); }); it("should spread model composite request ", async () => { - try { - const result = await client.model.spreadCompositeRequest("foo", "bar", { - name: "foo" - }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.model.spreadCompositeRequest("foo", "bar", { + name: "foo" + }); + assert.isUndefined(result); }); it("should spread model composite request mix", async () => { - try { - const result = await client.model.spreadCompositeRequestMix( - "foo", - "bar", - "foo" - ); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.model.spreadCompositeRequestMix( + "foo", + "bar", + "foo" + ); + assert.isUndefined(result); }); it("should spread alias with mixed params", async () => { - try { - const result = await client.alias.spreadAsRequestParameter( - "1", - "bar", - "foo" - ); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.alias.spreadAsRequestParameter( + "1", + "bar", + "foo" + ); + assert.isUndefined(result); }); it("should spread alias with multiple-parameters", async () => { - try { - const result = await client.alias.spreadWithMultipleParameters( - "1", - "bar", - "foo", - [1, 2], - { optionalInt: 1, optionalStringList: ["foo", "bar"] } - ); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.alias.spreadWithMultipleParameters( + "1", + "bar", + "foo", + [1, 2], + { optionalInt: 1, optionalStringList: ["foo", "bar"] } + ); + assert.isUndefined(result); }); it("should spread alias with inner-model-parameter", async () => { - try { - const result = await client.alias.spreadParameterWithInnerModel( - "1", - "bar", - "foo" - ); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.alias.spreadParameterWithInnerModel( + "1", + "bar", + "foo" + ); + assert.isUndefined(result); }); it("should spread alias with inner-alias-parameter", async () => { - try { - const result = await client.alias.spreadParameterWithInnerAlias( - "1", - "bar", - "foo", - 1 - ); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.alias.spreadParameterWithInnerAlias( + "1", + "bar", + "foo", + 1 + ); + assert.isUndefined(result); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/unions.spec.ts b/packages/typespec-ts/test/modularIntegration/unions.spec.ts index 89baaadee0..a1426e50e5 100644 --- a/packages/typespec-ts/test/modularIntegration/unions.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/unions.spec.ts @@ -14,208 +14,129 @@ describe("Type Union Client", () => { }); it("should get strings only union", async () => { - try { - const result = await client.stringsOnly.get(); - assert.strictEqual(result.prop, "b"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.stringsOnly.get(); + assert.strictEqual(result.prop, "b"); }); it("should send strings only union", async () => { - try { - const result = await client.stringsOnly.send("b"); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.stringsOnly.send("b"); + assert.isUndefined(result); }); it("should get strings extensible union", async () => { - try { - const result = await client.stringExtensible.get(); - assert.strictEqual(result.prop, "custom"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.stringExtensible.get(); + assert.strictEqual(result.prop, "custom"); }); it("should send strings extensible union", async () => { - try { - const result = await client.stringExtensible.send("custom"); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.stringExtensible.send("custom"); + assert.isUndefined(result); }); it("should get strings extensible named union", async () => { - try { - const result = await client.stringExtensibleNamed.get(); - assert.strictEqual(result.prop, "custom"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.stringExtensibleNamed.get(); + assert.strictEqual(result.prop, "custom"); }); it("should send strings extensible union", async () => { - try { - const result = await client.stringExtensibleNamed.send("custom"); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.stringExtensibleNamed.send("custom"); + assert.isUndefined(result); }); it("should get ints only union", async () => { - try { - const result = await client.intsOnly.get(); - assert.strictEqual(result.prop, 2); - } catch (err) { - assert.fail(err as string); - } + const result = await client.intsOnly.get(); + assert.strictEqual(result.prop, 2); }); it("should send ints only union", async () => { - try { - const result = await client.intsOnly.send(2); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.intsOnly.send(2); + assert.isUndefined(result); }); it("should get floats only union", async () => { - try { - const result = await client.floatsOnly.get(); - assert.strictEqual(result.prop, 2.2); - } catch (err) { - assert.fail(err as string); - } + const result = await client.floatsOnly.get(); + assert.strictEqual(result.prop, 2.2); }); it("should send floats only union", async () => { - try { - const result = await client.floatsOnly.send(2.2); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.floatsOnly.send(2.2); + assert.isUndefined(result); }); it("should get models only union", async () => { - try { - const result = await client.modelsOnly.get(); - assert.strictEqual( - JSON.stringify(result.prop), - JSON.stringify({ name: "test" }) - ); - } catch (err) { - assert.fail(err as string); - } + const result = await client.modelsOnly.get(); + assert.strictEqual( + JSON.stringify(result.prop), + JSON.stringify({ name: "test" }) + ); }); it("should send models only union", async () => { - try { - const result = await client.modelsOnly.send({ name: "test" }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.modelsOnly.send({ name: "test" }); + assert.isUndefined(result); }); it("should get enums only union", async () => { - try { - const result = await client.enumsOnly.get(); - assert.strictEqual(result.prop.lr, "right"); - assert.strictEqual(result.prop.ud, "up"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.enumsOnly.get(); + assert.strictEqual(result.prop.lr, "right"); + assert.strictEqual(result.prop.ud, "up"); }); it("should send enums only union", async () => { - try { - const result = await client.enumsOnly.send({ lr: "right", ud: "up" }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.enumsOnly.send({ lr: "right", ud: "up" }); + assert.isUndefined(result); }); it("should get string and array union", async () => { - try { - const result = await client.stringAndArray.get(); - assert.strictEqual(result.prop.string, "test"); - assert.strictEqual(result.prop.array[0], "test1"); - assert.strictEqual(result.prop.array[1], "test2"); - } catch (err) { - assert.fail(err as string); - } + const result = await client.stringAndArray.get(); + assert.strictEqual(result.prop.string, "test"); + assert.strictEqual(result.prop.array[0], "test1"); + assert.strictEqual(result.prop.array[1], "test2"); }); it("should send string and array union", async () => { - try { - const result = await client.stringAndArray.send({ - string: "test", - array: ["test1", "test2"] - }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.stringAndArray.send({ + string: "test", + array: ["test1", "test2"] + }); + assert.isUndefined(result); }); it("should get mixed literals union", async () => { - try { - const result = await client.mixedLiterals.get(); - assert.strictEqual(result.prop.stringLiteral, "a"); - assert.strictEqual(result.prop.intLiteral, 2); - assert.strictEqual(result.prop.floatLiteral, 3.3); - assert.strictEqual(result.prop.booleanLiteral, true); - } catch (err) { - assert.fail(err as string); - } + const result = await client.mixedLiterals.get(); + assert.strictEqual(result.prop.stringLiteral, "a"); + assert.strictEqual(result.prop.intLiteral, 2); + assert.strictEqual(result.prop.floatLiteral, 3.3); + assert.strictEqual(result.prop.booleanLiteral, true); }); it("should send mixed literals union", async () => { - try { - const result = await client.mixedLiterals.send({ - stringLiteral: "a", - intLiteral: 2, - floatLiteral: 3.3, - booleanLiteral: true - }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.mixedLiterals.send({ + stringLiteral: "a", + intLiteral: 2, + floatLiteral: 3.3, + booleanLiteral: true + }); + assert.isUndefined(result); }); it("should get mixed types union", async () => { - try { - const result = await client.mixedTypes.get(); - assert.strictEqual( - JSON.stringify(result.prop.model), - JSON.stringify({ name: "test" }) - ); - assert.strictEqual(result.prop.literal, "a"); - assert.strictEqual(result.prop.int, 2); - assert.strictEqual(result.prop.boolean, true); - } catch (err) { - assert.fail(err as string); - } + const result = await client.mixedTypes.get(); + assert.strictEqual( + JSON.stringify(result.prop.model), + JSON.stringify({ name: "test" }) + ); + assert.strictEqual(result.prop.literal, "a"); + assert.strictEqual(result.prop.int, 2); + assert.strictEqual(result.prop.boolean, true); + }); it("should send mixed types union", async () => { - try { - const result = await client.mixedTypes.send({ - model: { name: "test" }, - literal: "a", - int: 2, - boolean: true, - array: [ - { - name: "test" - }, - "a", - 2, - true - ] - }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.mixedTypes.send({ + model: { name: "test" }, + literal: "a", + int: 2, + boolean: true, + array: [ + { + name: "test" + }, + "a", + 2, + true + ] + }); + assert.isUndefined(result); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/usage.spec.ts b/packages/typespec-ts/test/modularIntegration/usage.spec.ts index f9a373b0e4..6d24695add 100644 --- a/packages/typespec-ts/test/modularIntegration/usage.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/usage.spec.ts @@ -19,34 +19,22 @@ describe("UsageContext Classical Client", () => { }); it("should input", async () => { - try { - const result = await client.input({ requiredProp: EXPECTED_VALUE }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await client.input({ requiredProp: EXPECTED_VALUE }); + assert.isUndefined(result); }); it("should output", async () => { - try { - const result = await client.output(); - assert.isNotNull(result); - assert.strictEqual(result.requiredProp, EXPECTED_VALUE); - } catch (err) { - assert.fail(err as string); - } + const result = await client.output(); + assert.isNotNull(result); + assert.strictEqual(result.requiredProp, EXPECTED_VALUE); }); it("should inputAndOutput", async () => { - try { - const result = await client.inputAndOutput({ - requiredProp: EXPECTED_VALUE - }); - assert.isNotNull(result); - assert.strictEqual(result.requiredProp, EXPECTED_VALUE); - } catch (err) { - assert.fail(err as string); - } + const result = await client.inputAndOutput({ + requiredProp: EXPECTED_VALUE + }); + assert.isNotNull(result); + assert.strictEqual(result.requiredProp, EXPECTED_VALUE); }); }); @@ -61,33 +49,21 @@ describe("UsageContext API Operations", () => { }); it("should input", async () => { - try { - const result = await input(context, { requiredProp: EXPECTED_VALUE }); - assert.isUndefined(result); - } catch (err) { - assert.fail(err as string); - } + const result = await input(context, { requiredProp: EXPECTED_VALUE }); + assert.isUndefined(result); }); it("should inputAndOutput", async () => { - try { - const result = await inputAndOutput(context, { - requiredProp: EXPECTED_VALUE - }); - assert.isNotNull(result); - assert.strictEqual(result.requiredProp, EXPECTED_VALUE); - } catch (err) { - assert.fail(err as string); - } + const result = await inputAndOutput(context, { + requiredProp: EXPECTED_VALUE + }); + assert.isNotNull(result); + assert.strictEqual(result.requiredProp, EXPECTED_VALUE); }); it("should output", async () => { - try { - const result = await output(context); - assert.isNotNull(result); - assert.strictEqual(result.requiredProp, EXPECTED_VALUE); - } catch (err) { - assert.fail(err as string); - } + const result = await output(context); + assert.isNotNull(result); + assert.strictEqual(result.requiredProp, EXPECTED_VALUE); }); }); diff --git a/packages/typespec-ts/test/modularIntegration/versioningRemoved.spec.ts b/packages/typespec-ts/test/modularIntegration/versioningRemoved.spec.ts index 2f34691bd6..20d99d3076 100644 --- a/packages/typespec-ts/test/modularIntegration/versioningRemoved.spec.ts +++ b/packages/typespec-ts/test/modularIntegration/versioningRemoved.spec.ts @@ -2,16 +2,24 @@ import { assert } from "chai"; import { RemovedClient } from "./generated/versioning/removed/src/index.js"; describe("VersioningRemoved Rest Client", () => { - let client: RemovedClient; + let client1: RemovedClient; + let client2: RemovedClient; + let clientPreview: RemovedClient; beforeEach(() => { - client = new RemovedClient("http://localhost:3002", "v2", { + client1 = new RemovedClient("http://localhost:3002", "v1", { + allowInsecureConnection: true + }); + client2 = new RemovedClient("http://localhost:3002", "v2", { + allowInsecureConnection: true + }); + clientPreview = new RemovedClient("http://localhost:3002", "v2preview", { allowInsecureConnection: true }); }); - it("versioning removed test", async () => { - const result = await client.v2({ + it("versioning removed test v2", async () => { + const result = await client2.v2({ prop: "foo", enumProp: "enumMemberV2", unionProp: "bar" @@ -20,4 +28,30 @@ describe("VersioningRemoved Rest Client", () => { assert.strictEqual(result.enumProp, "enumMemberV2"); assert.strictEqual(result.unionProp, "bar"); }); + + it("versioning removed test modelV3", async () => { + const result = await client1.modelV3({ + id: "123", + enumProp: "enumMemberV1", + }); + assert.strictEqual(result.id, "123"); + assert.strictEqual(result.enumProp, "enumMemberV1"); + }); + + it("versioning removed test modelV3_V2", async () => { + const result = await client2.modelV3({ + id: "123", + enumProp: "enumMemberV1", + }); + assert.strictEqual(result.id, "123"); + assert.strictEqual(result.enumProp, "enumMemberV1"); + }); + + it("versioning removed test modelV33_V2preview", async () => { + const result = await clientPreview.modelV3({ + id: "123", + enumProp: "enumMemberV1", + }); + assert.strictEqual(result.id, "123"); + }); });