|
1 | | -var Request = require("../src/base-request"); |
| 1 | +var Request = require('../src/base-request'); |
2 | 2 |
|
3 | | -describe("Create Requests", () => { |
4 | | - test("Should create host, port, and scheme", () => { |
| 3 | +describe('Create Requests', () => { |
| 4 | + test('Should create host, port, and scheme', () => { |
5 | 5 | var request = Request.builder() |
6 | | - .withHost("such.api.wow") |
| 6 | + .withHost('such.api.wow') |
7 | 7 | .withPort(1337) |
8 | | - .withScheme("http") |
| 8 | + .withScheme('http') |
9 | 9 | .build(); |
10 | 10 |
|
11 | | - expect(request.getHost()).toBe("such.api.wow"); |
| 11 | + expect(request.getHost()).toBe('such.api.wow'); |
12 | 12 | expect(request.getPort()).toBe(1337); |
13 | | - expect(request.getScheme()).toBe("http"); |
| 13 | + expect(request.getScheme()).toBe('http'); |
14 | 14 | }); |
15 | 15 |
|
16 | | - test("Should add query parameters", () => { |
| 16 | + test('Should add query parameters', () => { |
17 | 17 | var request = Request.builder() |
18 | | - .withHost("such.api.wow") |
| 18 | + .withHost('such.api.wow') |
19 | 19 | .withPort(1337) |
20 | | - .withScheme("http") |
| 20 | + .withScheme('http') |
21 | 21 | .withQueryParameters({ |
22 | 22 | oneParameter: 1, |
23 | 23 | anotherParameter: true, |
24 | | - thirdParameter: "hello", |
| 24 | + thirdParameter: 'hello' |
25 | 25 | }) |
26 | 26 | .build(); |
27 | 27 |
|
28 | 28 | expect(request.getQueryParameters().oneParameter).toBe(1); |
29 | 29 | expect(request.getQueryParameters().anotherParameter).toBe(true); |
30 | | - expect(request.getQueryParameters().thirdParameter).toBe("hello"); |
| 30 | + expect(request.getQueryParameters().thirdParameter).toBe('hello'); |
31 | 31 | }); |
32 | 32 |
|
33 | | - test("Should add query parameters (multiple calls)", () => { |
| 33 | + test('Should add query parameters (multiple calls)', () => { |
34 | 34 | var request = Request.builder() |
35 | | - .withHost("such.api.wow") |
| 35 | + .withHost('such.api.wow') |
36 | 36 | .withPort(1337) |
37 | | - .withScheme("http") |
| 37 | + .withScheme('http') |
38 | 38 | .withQueryParameters({ |
39 | 39 | oneParameter: 1, |
40 | | - anotherParameter: true, |
| 40 | + anotherParameter: true |
41 | 41 | }) |
42 | 42 | .withQueryParameters({ |
43 | | - thirdParameter: "hello", |
| 43 | + thirdParameter: 'hello' |
44 | 44 | }) |
45 | 45 | .build(); |
46 | 46 |
|
47 | 47 | expect(request.getQueryParameters().oneParameter).toBe(1); |
48 | 48 | expect(request.getQueryParameters().anotherParameter).toBe(true); |
49 | | - expect(request.getQueryParameters().thirdParameter).toBe("hello"); |
| 49 | + expect(request.getQueryParameters().thirdParameter).toBe('hello'); |
50 | 50 | }); |
51 | 51 |
|
52 | | - test("Should add query parameters (combine calls)", () => { |
| 52 | + test('Should add query parameters (combine calls)', () => { |
53 | 53 | var request = Request.builder() |
54 | | - .withHost("such.api.wow") |
| 54 | + .withHost('such.api.wow') |
55 | 55 | .withPort(1337) |
56 | | - .withScheme("http") |
| 56 | + .withScheme('http') |
57 | 57 | .withQueryParameters( |
58 | 58 | { |
59 | 59 | oneParameter: 1, |
60 | | - anotherParameter: true, |
| 60 | + anotherParameter: true |
61 | 61 | }, |
62 | 62 | { |
63 | | - thirdParameter: "hello", |
| 63 | + thirdParameter: 'hello' |
64 | 64 | } |
65 | 65 | ) |
66 | 66 | .build(); |
67 | 67 |
|
68 | 68 | expect(request.getQueryParameters().oneParameter).toBe(1); |
69 | 69 | expect(request.getQueryParameters().anotherParameter).toBe(true); |
70 | | - expect(request.getQueryParameters().thirdParameter).toBe("hello"); |
| 70 | + expect(request.getQueryParameters().thirdParameter).toBe('hello'); |
71 | 71 | }); |
72 | 72 |
|
73 | | - test("Should add body parameters", () => { |
| 73 | + test('Should add body parameters', () => { |
74 | 74 | var request = Request.builder() |
75 | | - .withHost("such.api.wow") |
| 75 | + .withHost('such.api.wow') |
76 | 76 | .withPort(1337) |
77 | | - .withScheme("http") |
| 77 | + .withScheme('http') |
78 | 78 | .withBodyParameters({ |
79 | 79 | one: 1, |
80 | 80 | two: true, |
81 | | - three: "world", |
| 81 | + three: 'world' |
82 | 82 | }) |
83 | 83 | .build(); |
84 | 84 |
|
85 | 85 | expect(request.getBodyParameters().one).toBe(1); |
86 | 86 | expect(request.getBodyParameters().two).toBe(true); |
87 | | - expect(request.getBodyParameters().three).toBe("world"); |
| 87 | + expect(request.getBodyParameters().three).toBe('world'); |
88 | 88 | }); |
89 | 89 |
|
90 | | - test("Should add array to body parameters", () => { |
| 90 | + test('Should add array to body parameters', () => { |
91 | 91 | var request = Request.builder() |
92 | | - .withHost("such.api.wow") |
| 92 | + .withHost('such.api.wow') |
93 | 93 | .withPort(1337) |
94 | | - .withScheme("http") |
95 | | - .withBodyParameters(["3VNWq8rTnQG6fM1eldSpZ0"]) |
| 94 | + .withScheme('http') |
| 95 | + .withBodyParameters(['3VNWq8rTnQG6fM1eldSpZ0']) |
96 | 96 | .build(); |
97 | 97 |
|
98 | | - expect(request.getBodyParameters()).toEqual(["3VNWq8rTnQG6fM1eldSpZ0"]); |
| 98 | + expect(request.getBodyParameters()).toEqual(['3VNWq8rTnQG6fM1eldSpZ0']); |
99 | 99 | }); |
100 | 100 |
|
101 | | - test("Should add header parameters", () => { |
| 101 | + test('Should add header parameters', () => { |
102 | 102 | var request = Request.builder() |
103 | | - .withHost("such.api.wow") |
| 103 | + .withHost('such.api.wow') |
104 | 104 | .withPort(1337) |
105 | | - .withScheme("http") |
| 105 | + .withScheme('http') |
106 | 106 | .withHeaders({ |
107 | | - Authorization: "Basic WOOP", |
108 | | - "Content-Type": "application/lol", |
| 107 | + Authorization: 'Basic WOOP', |
| 108 | + 'Content-Type': 'application/lol' |
109 | 109 | }) |
110 | 110 | .build(); |
111 | 111 |
|
112 | | - expect(request.getHeaders().Authorization).toBe("Basic WOOP"); |
113 | | - expect(request.getHeaders()["Content-Type"]).toBe("application/lol"); |
| 112 | + expect(request.getHeaders().Authorization).toBe('Basic WOOP'); |
| 113 | + expect(request.getHeaders()['Content-Type']).toBe('application/lol'); |
114 | 114 | }); |
115 | 115 |
|
116 | | - test("Should add path", () => { |
| 116 | + test('Should add path', () => { |
117 | 117 | var request = Request.builder() |
118 | | - .withHost("such.api.wow") |
| 118 | + .withHost('such.api.wow') |
119 | 119 | .withPort(1337) |
120 | | - .withPath("/v1/users/meriosweg") |
| 120 | + .withPath('/v1/users/meriosweg') |
121 | 121 | .build(); |
122 | 122 |
|
123 | | - expect(request.getPath()).toBe("/v1/users/meriosweg"); |
| 123 | + expect(request.getPath()).toBe('/v1/users/meriosweg'); |
124 | 124 | }); |
125 | 125 |
|
126 | | - test("Should build URI", () => { |
| 126 | + test('Should build URI', () => { |
127 | 127 | var request = Request.builder() |
128 | | - .withHost("such.api.wow") |
129 | | - .withScheme("https") |
| 128 | + .withHost('such.api.wow') |
| 129 | + .withScheme('https') |
130 | 130 | .withPort(1337) |
131 | | - .withPath("/v1/users/meriosweg") |
| 131 | + .withPath('/v1/users/meriosweg') |
132 | 132 | .build(); |
133 | 133 |
|
134 | 134 | expect(request.getURI()).toBe( |
135 | | - "https://such.api.wow:1337/v1/users/meriosweg" |
| 135 | + 'https://such.api.wow:1337/v1/users/meriosweg' |
136 | 136 | ); |
137 | 137 | }); |
138 | 138 |
|
139 | | - test("Should construct empty query paramaters string", () => { |
| 139 | + test('Should construct empty query paramaters string', () => { |
140 | 140 | var request = Request.builder().withQueryParameters({}).build(); |
141 | 141 |
|
142 | 142 | expect(request.getQueryParameterString()).toBeFalsy(); |
143 | 143 | }); |
144 | 144 |
|
145 | | - test("Should construct query paramaters string for one parameter", () => { |
| 145 | + test('Should construct query paramaters string for one parameter', () => { |
146 | 146 | var request = Request.builder() |
147 | 147 | .withQueryParameters({ |
148 | | - one: 1, |
| 148 | + one: 1 |
149 | 149 | }) |
150 | 150 | .build(); |
151 | 151 |
|
152 | | - expect(request.getQueryParameterString()).toBe("?one=1"); |
| 152 | + expect(request.getQueryParameterString()).toBe('?one=1'); |
153 | 153 | }); |
154 | 154 |
|
155 | | - test("Should construct query paramaters string for multiple parameters", () => { |
| 155 | + test('Should construct query paramaters string for multiple parameters', () => { |
156 | 156 | var request = Request.builder() |
157 | 157 | .withQueryParameters({ |
158 | 158 | one: 1, |
159 | 159 | two: true, |
160 | | - three: "world", |
| 160 | + three: 'world' |
161 | 161 | }) |
162 | 162 | .build(); |
163 | 163 |
|
164 | 164 | expect(request.getQueryParameterString()).toBe( |
165 | | - "?one=1&two=true&three=world" |
| 165 | + '?one=1&two=true&three=world' |
166 | 166 | ); |
167 | 167 | }); |
168 | 168 |
|
169 | | - test("Should construct query paramaters string and exclude undefined values", () => { |
| 169 | + test('Should construct query paramaters string and exclude undefined values', () => { |
170 | 170 | var request = Request.builder() |
171 | 171 | .withQueryParameters({ |
172 | 172 | one: 1, |
173 | 173 | two: undefined, |
174 | | - three: "world", |
| 174 | + three: 'world' |
175 | 175 | }) |
176 | 176 | .build(); |
177 | 177 |
|
178 | | - expect(request.getQueryParameterString()).toBe("?one=1&three=world"); |
| 178 | + expect(request.getQueryParameterString()).toBe('?one=1&three=world'); |
179 | 179 | }); |
180 | 180 | }); |
0 commit comments