Skip to content

Commit 3adf8b4

Browse files
authored
Add url encoding test for C#,Go,Java,Kotlin and Typescript (#1762)
2 parents 3a0bbfc + 9c6be06 commit 3adf8b4

File tree

5 files changed

+90
-0
lines changed

5 files changed

+90
-0
lines changed

csharp/Svix.Tests/WiremockTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,5 +244,23 @@ public void ListResponseApplicationOutWorksCorrectly()
244244
);
245245
client.Application.List();
246246
}
247+
248+
[Fact]
249+
public void UrlEncodedOctothorpe()
250+
{
251+
stub.Given(Request.Create().WithPath("/api/v1/app/app_id/msg"))
252+
.RespondWith(
253+
Response
254+
.Create()
255+
.WithStatusCode(200)
256+
.WithBody("""{"data":[],"iterator":null,"prevIterator":null,"done":true}""")
257+
);
258+
client.Message.List("app_id", new MessageListOptions { Tag = "test#test" });
259+
Assert.Equal(1, stub.LogEntries.Count);
260+
Assert.EndsWith(
261+
"/api/v1/app/app_id/msg?tag=test%23test",
262+
stub.LogEntries[0].RequestMessage.Url
263+
);
264+
}
247265
}
248266
}

go/svix_http_client_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,27 @@ func TestQueryParamListSerialization(t *testing.T) {
195195
t.Error(err)
196196
}
197197
}
198+
199+
func TestOctothorpeUrlParam(t *testing.T) {
200+
svx := newMockClient()
201+
httpmock.Activate()
202+
defer httpmock.DeactivateAndReset()
203+
204+
httpmock.RegisterResponder("GET", "http://testapi.test/api/v1/app/random_app_id/msg",
205+
func(r *http.Request) (*http.Response, error) {
206+
if !reflect.DeepEqual(r.URL.RawQuery, "tag=test%23test") {
207+
t.Errorf("Unexpected MessageListOptions serialization, got: %v", r.URL.RawQuery)
208+
}
209+
210+
return httpmock.NewStringResponse(200, msgListOut), nil
211+
},
212+
)
213+
tag := "test#test"
214+
listOpts := svix.MessageListOptions{
215+
Tag: &tag,
216+
}
217+
_, err := svx.Message.List(context.Background(), "random_app_id", &listOpts)
218+
if err != nil {
219+
t.Error(err)
220+
}
221+
}

java/lib/src/test/com/svix/test/WiremockTests.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,4 +435,21 @@ public void msgInRaw() throws Exception {
435435
postRequestedFor(urlEqualTo("/api/v1/app/app1/msg"))
436436
.withRequestBody(equalTo(expectedBody)));
437437
}
438+
439+
@Test
440+
public void octothorpeInUrlQuery() throws Exception {
441+
Svix svx = testClient();
442+
wireMockRule.stubFor(
443+
WireMock.get(urlEqualTo("/api/v1/app/app1/msg?tag=test%23test"))
444+
.willReturn(WireMock.ok().withBodyFile("ListResponseMessageOut.json")));
445+
446+
MessageListOptions opts = new MessageListOptions();
447+
opts.setTag("test#test");
448+
svx.getMessage().list("app1", opts);
449+
450+
wireMockRule.verify(
451+
1,
452+
getRequestedFor(urlEqualTo("/api/v1/app/app1/msg?tag=test%23test")));
453+
}
454+
438455
}

javascript/src/mockttp.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,4 +336,17 @@ describe("mockttp tests", () => {
336336
const requests = await endpointMock.getSeenRequests();
337337
expect(requests.length).toBe(1);
338338
});
339+
340+
test("octothorpe in url query", async () => {
341+
const endpointMock = await mockServer
342+
.forGet("/api/v1/app/app1/msg")
343+
.thenReply(200, ListResponseMessageOut);
344+
const svx = new Svix("token.eu", { serverUrl: mockServer.url });
345+
346+
await svx.message.list("app1", { tag: "test#test" });
347+
348+
const requests = await endpointMock.getSeenRequests();
349+
expect(requests.length).toBe(1);
350+
expect(requests[0].url.endsWith("api/v1/app/app1/msg?tag=test%23test")).toBe(true);
351+
});
339352
});

kotlin/lib/src/test/com/svix/kotlin/WiremockTests.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import kotlin.test.assertEquals
1616
import kotlinx.coroutines.runBlocking
1717
import kotlinx.datetime.Instant
1818
import org.junit.jupiter.api.*
19+
import kotlin.test.assertEquals
1920

2021
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
2122
class WiremockTests {
@@ -381,4 +382,21 @@ class WiremockTests {
381382
)
382383
runBlocking { svx.application.list() }
383384
}
385+
386+
@Test
387+
fun octothorpeInUrlQuery() {
388+
val svx = testClient()
389+
wireMockServer.stubFor(
390+
get(urlEqualTo("/api/v1/app/app1/msg?tag=test%23test"))
391+
.willReturn(ok().withBodyFile("ListResponseMessageOut.json"))
392+
)
393+
394+
runBlocking { svx.message.list("app1", MessageListOptions(tag = "test#test")) }
395+
396+
wireMockServer.verify(
397+
1,
398+
getRequestedFor(urlEqualTo("/api/v1/app/app1/msg?tag=test%23test"))
399+
)
400+
}
401+
384402
}

0 commit comments

Comments
 (0)