Skip to content

Commit 17e6dcb

Browse files
fix(js): manually added decompression logic to node http requester (generated)
Co-authored-by: eric-zaharia <zahariaeric@gmail.com>
1 parent e20c15e commit 17e6dcb

File tree

22 files changed

+698
-38
lines changed

22 files changed

+698
-38
lines changed

tests/output/csharp/src/generated/client/Composition.test.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,38 @@ public async Task ApiTest2()
9191
);
9292
}
9393

94+
[Fact(DisplayName = "test the response decompression strategy")]
95+
public async Task ApiTest3()
96+
{
97+
CompositionConfig _config = new CompositionConfig("test-app-id", "test-api-key")
98+
{
99+
CustomHosts = new List<StatefulHost>
100+
{
101+
new()
102+
{
103+
Scheme = HttpScheme.Http,
104+
Url =
105+
Environment.GetEnvironmentVariable("CI") == "true"
106+
? "localhost"
107+
: "host.docker.internal",
108+
Port = 6691,
109+
Up = true,
110+
LastUse = DateTime.UtcNow,
111+
Accept = CallType.Read | CallType.Write,
112+
},
113+
},
114+
};
115+
var client = new CompositionClient(_config);
116+
117+
var res = await client.CustomGetAsync("1/test/gzip-response");
118+
119+
JsonAssert.EqualOverrideDefault(
120+
"{\"message\":\"ok decompression test server response\",\"data\":\"Lorem ipsum dolor sit amet, consectetur adipiscing elit.\"}",
121+
JsonSerializer.Serialize(res, JsonConfig.Options),
122+
new JsonDiffConfig(false)
123+
);
124+
}
125+
94126
[Fact(DisplayName = "calls api with correct user agent")]
95127
public async Task CommonApiTest0()
96128
{

tests/output/csharp/src/generated/client/Search.test.cs

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,40 @@ public async Task ApiTest6()
247247
);
248248
}
249249

250-
[Fact(DisplayName = "calls api with default read timeouts")]
250+
[Fact(DisplayName = "test the response decompression strategy")]
251251
public async Task ApiTest7()
252+
{
253+
SearchConfig _config = new SearchConfig("test-app-id", "test-api-key")
254+
{
255+
CustomHosts = new List<StatefulHost>
256+
{
257+
new()
258+
{
259+
Scheme = HttpScheme.Http,
260+
Url =
261+
Environment.GetEnvironmentVariable("CI") == "true"
262+
? "localhost"
263+
: "host.docker.internal",
264+
Port = 6691,
265+
Up = true,
266+
LastUse = DateTime.UtcNow,
267+
Accept = CallType.Read | CallType.Write,
268+
},
269+
},
270+
};
271+
var client = new SearchClient(_config);
272+
273+
var res = await client.CustomGetAsync("1/test/gzip-response");
274+
275+
JsonAssert.EqualOverrideDefault(
276+
"{\"message\":\"ok decompression test server response\",\"data\":\"Lorem ipsum dolor sit amet, consectetur adipiscing elit.\"}",
277+
JsonSerializer.Serialize(res, JsonConfig.Options),
278+
new JsonDiffConfig(false)
279+
);
280+
}
281+
282+
[Fact(DisplayName = "calls api with default read timeouts")]
283+
public async Task ApiTest8()
252284
{
253285
var client = new SearchClient(new SearchConfig("appId", "apiKey"), _echo);
254286
await client.CustomGetAsync("1/test");
@@ -259,7 +291,7 @@ public async Task ApiTest7()
259291
}
260292

261293
[Fact(DisplayName = "calls api with default write timeouts")]
262-
public async Task ApiTest8()
294+
public async Task ApiTest9()
263295
{
264296
var client = new SearchClient(new SearchConfig("appId", "apiKey"), _echo);
265297
await client.CustomPostAsync("1/test");
@@ -270,7 +302,7 @@ public async Task ApiTest8()
270302
}
271303

272304
[Fact(DisplayName = "can handle unknown response fields")]
273-
public async Task ApiTest9()
305+
public async Task ApiTest10()
274306
{
275307
SearchConfig _config = new SearchConfig("test-app-id", "test-api-key")
276308
{
@@ -302,7 +334,7 @@ public async Task ApiTest9()
302334
}
303335

304336
[Fact(DisplayName = "can handle unknown response fields inside a nested oneOf")]
305-
public async Task ApiTest10()
337+
public async Task ApiTest11()
306338
{
307339
SearchConfig _config = new SearchConfig("test-app-id", "test-api-key")
308340
{
@@ -334,7 +366,7 @@ public async Task ApiTest10()
334366
}
335367

336368
[Fact(DisplayName = "does not retry on success")]
337-
public async Task ApiTest11()
369+
public async Task ApiTest12()
338370
{
339371
SearchConfig _config = new SearchConfig("test-app-id", "test-api-key")
340372
{

tests/output/dart/test/client/composition_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,29 @@ void main() {
7070
}
7171
});
7272

73+
test('test the response decompression strategy', () async {
74+
final requester = RequestInterceptor();
75+
final client = CompositionClient(
76+
appId: "test-app-id",
77+
apiKey: "test-api-key",
78+
options: ClientOptions(hosts: [
79+
Host.create(
80+
url:
81+
'${Platform.environment['CI'] == 'true' ? 'localhost' : 'host.docker.internal'}:6691',
82+
scheme: 'http'),
83+
]));
84+
requester.setOnRequest((request) {});
85+
try {
86+
final res = await client.customGet(
87+
path: "1/test/gzip-response",
88+
);
89+
expectBody(res,
90+
"""{"message":"ok decompression test server response","data":"Lorem ipsum dolor sit amet, consectetur adipiscing elit."}""");
91+
} on InterceptionException catch (_) {
92+
// Ignore InterceptionException
93+
}
94+
});
95+
7396
test('calls api with correct user agent', () async {
7497
final requester = RequestInterceptor();
7598
final client = CompositionClient(

tests/output/dart/test/client/search_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,29 @@ void main() {
173173
}
174174
});
175175

176+
test('test the response decompression strategy', () async {
177+
final requester = RequestInterceptor();
178+
final client = SearchClient(
179+
appId: "test-app-id",
180+
apiKey: "test-api-key",
181+
options: ClientOptions(hosts: [
182+
Host.create(
183+
url:
184+
'${Platform.environment['CI'] == 'true' ? 'localhost' : 'host.docker.internal'}:6691',
185+
scheme: 'http'),
186+
]));
187+
requester.setOnRequest((request) {});
188+
try {
189+
final res = await client.customGet(
190+
path: "1/test/gzip-response",
191+
);
192+
expectBody(res,
193+
"""{"message":"ok decompression test server response","data":"Lorem ipsum dolor sit amet, consectetur adipiscing elit."}""");
194+
} on InterceptionException catch (_) {
195+
// Ignore InterceptionException
196+
}
197+
});
198+
176199
test('calls api with default read timeouts', () async {
177200
final requester = RequestInterceptor();
178201
final client = SearchClient(

tests/output/go/tests/client/composition_test.go

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/output/go/tests/client/search_test.go

Lines changed: 43 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/output/java/src/test/java/com/algolia/client/Composition.test.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,37 @@ void apiTest2() {
133133
);
134134
}
135135

136+
@Test
137+
@DisplayName("test the response decompression strategy")
138+
void apiTest3() {
139+
CompositionClient client = new CompositionClient(
140+
"test-app-id",
141+
"test-api-key",
142+
withCustomHosts(
143+
Arrays.asList(
144+
new Host(
145+
"true".equals(System.getenv("CI")) ? "localhost" : "host.docker.internal",
146+
EnumSet.of(CallType.READ, CallType.WRITE),
147+
"http",
148+
6691
149+
)
150+
),
151+
false
152+
)
153+
);
154+
155+
Object res = client.customGet("1/test/gzip-response");
156+
157+
assertDoesNotThrow(() ->
158+
JSONAssert.assertEquals(
159+
"{\"message\":\"ok decompression test server response\",\"data\":\"Lorem ipsum" +
160+
" dolor sit amet, consectetur adipiscing elit.\"}",
161+
json.writeValueAsString(res),
162+
JSONCompareMode.STRICT
163+
)
164+
);
165+
}
166+
136167
@Test
137168
@DisplayName("calls api with correct user agent")
138169
void commonApiTest0() {

0 commit comments

Comments
 (0)