Skip to content

Commit

Permalink
Add test coverage for most of Body-* swaggers (Azure#587)
Browse files Browse the repository at this point in the history
* Add tests for BodyBoolean

* Add coverage for BodyBooleanQuirks

* Add coverage for bodyByte

* Add coverage for BodyDate

* Add coverage for BodyDateTime

* Add coverage for DateTimeRfc1123

* Update core-http version

* Add coverage for BodyDuration

* Add coverage for BodyInteger

* Add coverage for BodyNumber
  • Loading branch information
joheredi authored Mar 20, 2020
1 parent 8f5603f commit aa1c3e5
Show file tree
Hide file tree
Showing 120 changed files with 8,353 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/utils/nameUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { Operation, OperationGroup } from "@azure-tools/codemodel";
import { getLanguageMetadata } from "./languageHelpers";

const ReservedModelNames = ["Error"];
const ReservedModelNames = ["Error", "Date"];

export enum CasingConvention {
Pascal,
Expand Down
45 changes: 45 additions & 0 deletions test/integration/bodyBoolean.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { BodyBooleanClient } from "./generated/bodyBoolean/src/bodyBooleanClient";
import { expect } from "chai";
describe("Bool Client", function() {
let testClient: BodyBooleanClient;

beforeEach(() => {
testClient = new BodyBooleanClient();
});

it("should get true value", async () => {
const { body } = await testClient.bool.getTrue();
expect(body).to.equal(true);
});

it("should get false value", async () => {
const { body } = await testClient.bool.getFalse();
expect(body).to.equal(false);
});

it("should put true value", async () => {
const result = await testClient.bool.putTrue();
expect(result._response.status).to.equal(200);
});

it("should put false value", async () => {
const result = await testClient.bool.putFalse();
expect(result._response.status).to.equal(200);
});

it("should get null boolean value", async () => {
const { body } = await testClient.bool.getNull();
expect(body).to.equal(undefined);
});

it("should get invalid boolean value", async () => {
let failed = false;
try {
await testClient.bool.getInvalid();
} catch (error) {
failed = true;
} finally {
expect(failed).to.equal(true);
}
});
});
45 changes: 45 additions & 0 deletions test/integration/bodyBooleanQuirks.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { BodyBooleanQuirksClient } from "./generated/bodyBooleanQuirks/src/bodyBooleanQuirksClient";
import { expect } from "chai";
describe("Bool Quirks Client", function() {
let testClient: BodyBooleanQuirksClient;

beforeEach(() => {
testClient = new BodyBooleanQuirksClient();
});

it("should get true value", async () => {
const { body } = await testClient.bool.getTrue();
expect(body).to.equal(true);
});

it("should get false value", async () => {
const { body } = await testClient.bool.getFalse();
expect(body).to.equal(false);
});

it("should put true value", async () => {
const result = await testClient.bool.putTrue(true);
expect(result._response.status).to.equal(200);
});

it("should put false value", async () => {
const result = await testClient.bool.putFalse(false);
expect(result._response.status).to.equal(200);
});

it("should get null boolean value", async () => {
const { body } = await testClient.bool.getNull();
expect(body).to.equal(undefined);
});

it("should get invalid boolean value", async () => {
let failed = false;
try {
await testClient.bool.getInvalid();
} catch (error) {
failed = true;
} finally {
expect(failed).to.equal(true);
}
});
});
55 changes: 55 additions & 0 deletions test/integration/bodyByte.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { BodyByteClient } from "./generated/bodyByte/src/bodyByteClient";
import { expect } from "chai";
describe("Bool Quirks Client", function() {
let testClient: BodyByteClient;
const testBytes = new Uint8Array([
255,
254,
253,
252,
251,
250,
249,
248,
247,
246
]);

beforeEach(() => {
testClient = new BodyByteClient();
});

it("should get null value", async () => {
const { body } = await testClient.byte.getNull();
expect(body).to.equal(undefined);
});

it("should get empty value", async () => {
const { body } = await testClient.byte.getEmpty();
expect(body).to.be.instanceOf(Uint8Array);
expect(body.length).to.equal(0);
});

it("should get non-ascii value", async () => {
const { body } = await testClient.byte.getNonAscii();
expect(body.length).to.equal(testBytes.length);
for (let i = 0; i < testBytes.length; i++) {
expect(body[i]).to.equal(testBytes[i]);
}
});

it("should put non-ascii value", async () => {
const result = await testClient.byte.putNonAscii(testBytes);
expect(result._response.status).to.equal(200);
});

it("should get invalid value", async () => {
// Output of Buffer.from(':::SWAGGER::::', 'base64')
const expected = new Uint8Array([73, 96, 6, 24, 68]);

const { body } = await testClient.byte.getInvalid();
for (let i = 0; i < body.length; i++) {
expect(body[i]).to.equal(expected[i]);
}
});
});
63 changes: 63 additions & 0 deletions test/integration/bodyDate.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { BodyDateClient } from "./generated/bodyDate/src/bodyDateClient";
import { expect } from "chai";
describe("BodyDateClient", function() {
let testClient: BodyDateClient;

beforeEach(() => {
testClient = new BodyDateClient();
});

it("should get min date", async () => {
const { body: date } = await testClient.date.getMinDate();
expect(date.getUTCFullYear()).to.equal(1);
expect(date.getUTCMonth()).to.equal(0);
expect(date.getUTCDate()).to.equal(1);
expect(date.getUTCHours()).to.equal(0);
expect(date.getUTCMinutes()).to.equal(0);
expect(date.getUTCSeconds()).to.equal(0);
expect(date.getUTCMilliseconds()).to.equal(0);
});

it("should get max date", async () => {
const { body: date } = await testClient.date.getMaxDate();
expect(date.getUTCFullYear()).to.equal(9999);
expect(date.getUTCMonth()).to.equal(11);
expect(date.getUTCDate()).to.equal(31);
expect(date.getUTCHours()).to.equal(0);
expect(date.getUTCMinutes()).to.equal(0);
expect(date.getUTCSeconds()).to.equal(0);
expect(date.getUTCMilliseconds()).to.equal(0);
});

it("should handle overflow date", async () => {
const { body: date } = await testClient.date.getOverflowDate();
expect(isNaN(date.valueOf())).to.equal(true);
});

it("should handle undeflow date", async () => {
const { body: date } = await testClient.date.getUnderflowDate();
expect(isNaN(date.valueOf())).to.equal(true);
});

it("should get a null value", async () => {
const { body: date } = await testClient.date.getNull();
expect(date).to.equal(undefined);
});

it("should get an invalid value", async () => {
const { body: date } = await testClient.date.getInvalidDate();
expect(isNaN(date.valueOf())).to.equal(true);
});

it("should put max date", async () => {
const maxDate = new Date("9999-12-31");
const result = await testClient.date.putMaxDate(maxDate);
expect(result._response.status).to.equal(200);
});

it("should put min date", async () => {
const minDate = new Date("0001-01-01");
const result = await testClient.date.putMinDate(minDate);
expect(result._response.status).to.equal(200);
});
});
Loading

0 comments on commit aa1c3e5

Please sign in to comment.