-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: format url query params as array rather than comma-separated list
- Loading branch information
1 parent
4b8e172
commit 7d63ef3
Showing
2 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { afterAll, afterEach, beforeAll, describe, test, expect } from "vitest"; | ||
import { setupServer } from "msw/node"; | ||
import { HttpResponse, http } from "msw"; | ||
import { Knock } from "../../src/knock"; | ||
import { ListSchedulesProps } from "../../src/resources/workflows/interfaces"; | ||
|
||
const restHandlers = [ | ||
http.get("http://api.knock.test/v1/schedules", () => { | ||
return HttpResponse.json({ | ||
entries: [], | ||
page_info: { | ||
__typename: "PageInfo", | ||
after: null, | ||
before: null, | ||
page_size: 50, | ||
total_count: 0, | ||
}, | ||
}); | ||
}), | ||
]; | ||
|
||
const server = setupServer(...restHandlers); | ||
|
||
const knock = new Knock("sk_test_12345", { | ||
host: "http://api.knock.test", | ||
}); | ||
|
||
beforeAll(() => server.listen({ onUnhandledRequest: "error" })); | ||
|
||
afterAll(() => server.close()); | ||
|
||
afterEach(() => server.resetHandlers()); | ||
|
||
describe("schedules", () => { | ||
test("it can list schedules", async () => { | ||
const params: ListSchedulesProps = { | ||
recipients: ["1", "2", "3"], | ||
}; | ||
const { url } = await knock.get("/v1/schedules", { | ||
...params, | ||
workflow: "test-workflow", | ||
}); | ||
|
||
// Formats recipients list as a URL-encoded array | ||
// 'http://api.knock.test/v1/schedules?recipients=["1","2","3"]&workflow=test-workflow' | ||
expect(url).toBe( | ||
"http://api.knock.test/v1/schedules?recipients=%5B%221%22%2C%222%22%2C%223%22%5D&workflow=test-workflow", | ||
); | ||
}); | ||
}); |