forked from Azure/autorest.typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheader.spec.ts
208 lines (167 loc) · 7.88 KB
/
header.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import * as coreHttp from "@azure/core-http";
import { should, assert } from "chai";
import { isEqual } from "lodash";
import { HeaderClient } from "./generated/header/src";
should();
describe("typescript", function() {
describe("Swagger Header BAT", function() {
describe("Basic Header Operations", function() {
let testClient: HeaderClient;
beforeEach(() => {
testClient = new HeaderClient({ allowInsecureConnection: true });
});
it("should override existing headers (nodejs only)", async function() {
if (!coreHttp.isNode) {
this.skip();
}
await testClient.header.paramExistingKey("overwrite");
const response = await testClient.header.responseExistingKey();
response.userAgent!.should.be.deep.equal("overwrite");
});
it("should throw on changing protected headers", async function() {
await testClient.header.paramProtectedKey("text/html");
const response = await testClient.header.responseProtectedKey();
response.contentType!.should.be.deep.equal("text/html; charset=utf-8");
});
it("should send and receive integer type headers", async function() {
await testClient.header.paramInteger("positive", 1);
await testClient.header.paramInteger("negative", -2);
const response1 = await testClient.header.responseInteger("positive");
response1.value!.should.be.deep.equal(1);
const response2 = await testClient.header.responseInteger("negative");
response2.value!.should.be.deep.equal(-2);
});
it("should send and receive long type headers", async function() {
await testClient.header.paramLong("positive", 105);
await testClient.header.paramLong("negative", -2);
const response1 = await testClient.header.responseLong("positive");
response1.value!.should.be.deep.equal(105);
const response2 = await testClient.header.responseLong("negative");
response2.value!.should.be.deep.equal(-2);
});
it("should send and receive float type headers", async function() {
await testClient.header.paramFloat("positive", 0.07);
await testClient.header.paramFloat("negative", -3.0);
const response1 = await testClient.header.responseFloat("positive");
response1.value!.should.be.deep.equal(0.07);
const response2 = await testClient.header.responseFloat("negative");
response2.value!.should.be.deep.equal(-3.0);
});
it("should send and receive double type headers", async function() {
await testClient.header.paramDouble("positive", 7e120);
await testClient.header.paramDouble("negative", -3.0);
const response1 = await testClient.header.responseDouble("positive");
response1.value!.should.be.deep.equal(7e120);
const response2 = await testClient.header.responseDouble("negative");
response2.value!.should.be.deep.equal(-3.0);
});
it("should send and receive boolean type headers", async function() {
await testClient.header.paramBool("true", true);
await testClient.header.paramBool("false", false);
const response1 = await testClient.header.responseBool("true");
response1.value!.should.be.deep.equal(true);
const response2 = await testClient.header.responseBool("false");
response2.value!.should.be.deep.equal(false);
});
it.skip("should send and receive string type headers", async function() {
await testClient.header.paramString("valid", {
value: "The quick brown fox jumps over the lazy dog"
});
await testClient.header.paramString("null", { value: null as any });
await testClient.header.paramString("empty", { value: "" });
const response1 = await testClient.header.responseString("valid");
response1.value!.should.be.deep.equal(
"The quick brown fox jumps over the lazy dog"
);
// Note: Currently core-http wouldn't deserialize "null" as null when coming from headers
// all other languages are doing the same for now. Filed https://github.com/Azure/autorest.typescript/issues/739
// to track this.
const response2 = await testClient.header.responseString("null");
response2.value!.should.be.deep.equal("null");
const response3 = await testClient.header.responseString("empty");
assert.equal(response3.value, undefined);
});
it.skip("should send and receive enum type headers", async function() {
await testClient.header.paramEnum("valid", { value: "GREY" });
await testClient.header.paramEnum("null", { value: null as any });
const response1 = await testClient.header.responseEnum("valid");
response1.value!.should.be.deep.equal("GREY");
const response2 = await testClient.header.responseEnum("null");
assert.equal(response2.value, undefined);
});
it("should send and receive date type headers", async function() {
await testClient.header.paramDate("valid", new Date("2010-01-01"));
await testClient.header.paramDate("min", new Date("0001-01-01"));
const response1 = await testClient.header.responseDate("valid");
isEqual(
new Date(response1.value!),
new Date("2010-01-01")
).should.be.deep.equal(true);
const response2 = await testClient.header.responseDate("min");
isEqual(response2.value!, new Date("0001-01-01")).should.be.deep.equal(
true
);
});
it("should send and receive datetime type headers", async function() {
await testClient.header.paramDatetime(
"valid",
new Date("2010-01-01T12:34:56Z")
);
await testClient.header.paramDatetime(
"min",
new Date("0001-01-01T00:00:00Z")
);
const response1 = await testClient.header.responseDatetime("valid");
isEqual(
response1.value!,
new Date("2010-01-01T12:34:56Z")
).should.be.deep.equal(true);
const response2 = await testClient.header.responseDatetime("min");
isEqual(
response2.value!,
new Date("0001-01-01T00:00:00Z")
).should.be.deep.equal(true);
});
it("should send and receive datetimerfc1123 type headers", async function() {
await testClient.header.paramDatetimeRfc1123("valid", {
value: new Date("2010-01-01T12:34:56Z")
});
await testClient.header.paramDatetimeRfc1123("min", {
value: new Date("0001-01-01T00:00:00Z")
});
const response1 = await testClient.header.responseDatetimeRfc1123(
"valid"
);
isEqual(
response1.value,
new Date("Fri, 01 Jan 2010 12:34:56 GMT")
).should.be.deep.equal(true);
const response2 = await testClient.header.responseDatetimeRfc1123(
"min"
);
isEqual(
response2.value,
new Date("Mon, 01 Jan 0001 00:00:00 GMT")
).should.be.deep.equal(true);
});
it("should send and receive duration type headers", async function() {
const duration = "P123DT22H14M12.011S";
await testClient.header.paramDuration("valid", duration);
const response = await testClient.header.responseDuration("valid");
isEqual(response.value!, "P123DT22H14M12.011S").should.be.deep.equal(
true
);
});
it("should send and receive byte array type headers", async function() {
const value = "啊齄丂狛狜隣郎隣兀﨩";
const bytes = Buffer.from(value, "utf8");
await testClient.header.paramByte("valid", bytes);
const response = await testClient.header.responseByte("valid");
response.value!.length.should.equal(bytes.length);
for (let i = 0; i < bytes.length; i++) {
response.value![i].should.equal(bytes[i]);
}
});
});
});
});