Skip to content

Commit

Permalink
test: change method of concurrently requests. Added type for response…
Browse files Browse the repository at this point in the history
… type
  • Loading branch information
WillianAgostini committed Aug 4, 2023
1 parent 1d5cc81 commit eb0ede7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,9 @@ export class NordusRequest {
}

private getBody(nordusConfig: NordusConfigApi) {
if (!nordusConfig?.body) return;

switch (nordusConfig.responseType) {
case "json":
return JSON.stringify(nordusConfig.body);
case "text":
return nordusConfig.body.toString();
default:
return nordusConfig.body;
}
Expand Down
13 changes: 8 additions & 5 deletions tests/concurrency.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ describe("concurrency", () => {
responseType: "json",
});

const instanceGet = await instance.get("todos/1");
const instancePost = await instance.post("todos/1", {});
const instancePut = await instance.put("todos/1", {});
const instancePatch = await instance.patch("todos/1", {});
const instanceDel = await instance.del("todos/1");
const [instanceGet, instancePost, instancePut, instancePatch, instanceDel] =
await Promise.all([
instance.get("todos/1"),
instance.post("todos/1", {}),
instance.put("todos/1", {}),
instance.patch("todos/1", {}),
instance.del("todos/1"),
]);

expect(instanceGet.data).toEqual({ method: "get" });
expect(instancePost.data).toEqual({ method: "post" });
Expand Down
2 changes: 1 addition & 1 deletion tests/get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe("interceptors", () => {
test: "test",
})
);
const response = await get("http://localhost:5000");
const response = await get<{ test: string }>("http://localhost:5000");

expect(response.data).toEqual({
test: "test",
Expand Down
19 changes: 15 additions & 4 deletions tests/post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ describe("interceptors", () => {
test: "test",
})
);
const response = await post("http://localhost:5000", {
body: {
const response = await post<{ test: string }, { test: any }>(
"http://localhost:5000",
{
test: "test",
},
});
}
);

expect(response.data).toEqual({
test: "test",
Expand Down Expand Up @@ -54,4 +55,14 @@ describe("interceptors", () => {
test: "test",
});
});

it("success post with null body", async () => {
fetchMock.mockResponseOnce("plan text");

const response = await post("http://localhost:5000", null, {
responseType: "text",
});

expect(response.data).toEqual("plan text");
});
});

0 comments on commit eb0ede7

Please sign in to comment.