diff --git a/src/resources/objects/interfaces.ts b/src/resources/objects/interfaces.ts index a6f361d..86f9556 100644 --- a/src/resources/objects/interfaces.ts +++ b/src/resources/objects/interfaces.ts @@ -41,11 +41,11 @@ export interface ListObjectOptions extends PaginationOptions { } export interface ListObjectSubscriptionsOptions extends PaginationOptions { - recipients?: Map; + recipients?: {[key: string]: Recipient}; } export interface GetObjectSubscriptionsOptions extends PaginationOptions { - objects?: Map; + objects?: {[key: string]: ObjectRef}; } export interface ObjectSubscription { diff --git a/src/resources/users/index.ts b/src/resources/users/index.ts index 5352c79..e192574 100644 --- a/src/resources/users/index.ts +++ b/src/resources/users/index.ts @@ -16,7 +16,7 @@ import { WorkflowPreferenceSetting, } from "../preferences/interfaces"; import { ListMessagesOptions, Message } from "../messages/interfaces"; -import { ListSchedulesProps, Schedule } from "../workflows/interfaces"; +import { ListUserSchedulesProps, Schedule } from "../workflows/interfaces"; import { DEFAULT_PREFERENCE_SET_ID, buildUpdateParam, @@ -354,7 +354,7 @@ export class Users { async getSchedules( userId: string, - filteringOptions: ListSchedulesProps = {}, + filteringOptions: ListUserSchedulesProps = {}, ): Promise> { if (!userId) { throw new Error(`Incomplete arguments. You must provide a 'userId'`); diff --git a/src/resources/users/interfaces.ts b/src/resources/users/interfaces.ts index 2140aab..e9d8ddc 100644 --- a/src/resources/users/interfaces.ts +++ b/src/resources/users/interfaces.ts @@ -40,5 +40,5 @@ export interface ListUserOptions extends PaginationOptions { } export interface ListSubscriptionsOptions extends PaginationOptions { - objects?: Map; + objects?: {[key: string]: ObjectRef}; } diff --git a/src/resources/workflows/interfaces.ts b/src/resources/workflows/interfaces.ts index c0e2093..6f4d368 100644 --- a/src/resources/workflows/interfaces.ts +++ b/src/resources/workflows/interfaces.ts @@ -59,8 +59,13 @@ export interface UpdateSchedulesProps schedule_ids: string[]; } +export interface ListUserSchedulesProps extends PaginationOptions { + recipients?: {[key: string]: Recipient}; + tenant?: string; +} + export interface ListSchedulesProps extends PaginationOptions { - recipients?: Map; + recipients?: Recipient[]; tenant?: string; } diff --git a/test/resources/workflows.test.ts b/test/resources/workflows.test.ts index d3601c0..6b7f903 100644 --- a/test/resources/workflows.test.ts +++ b/test/resources/workflows.test.ts @@ -2,7 +2,7 @@ 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"; +import { ListSchedulesProps, ListUserSchedulesProps } from "../../src/resources/workflows/interfaces"; const restHandlers = [ http.get("http://api.knock.test/v1/schedules", () => { @@ -17,6 +17,18 @@ const restHandlers = [ }, }); }), + http.get("http://api.knock.test/v1/users/:userID/schedules", () => { + return HttpResponse.json({ + entries: [], + page_info: { + __typename: "PageInfo", + after: null, + before: null, + page_size: 50, + total_count: 0, + }, + }); + }), ]; const server = setupServer(...restHandlers); @@ -34,6 +46,22 @@ 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&recipients[]=2&recipients[]=3&workflow=test-workflow' + expect(url).toBe( + "http://api.knock.test/v1/schedules?recipients%5B%5D=1&recipients%5B%5D=2&recipients%5B%5D=3&workflow=test-workflow", + ); + }); + + test("it can list schedules for a given user", async () => { + const params: ListUserSchedulesProps = { recipients: { "0": "user_id", "1": { @@ -42,15 +70,14 @@ describe("schedules", () => { } }, }; - const { url } = await knock.get("/v1/schedules", { + const { url } = await knock.get("/v1/users/user_id/schedules", { ...params, - workflow: "test-workflow", }); - // Formats recipients as a URL-encoded map - // http://api.knock.test/v1/schedules?recipients[0]=user_id&recipients[1][collection]=object_collection&recipients[1][id]=object_id&workflow=test-workflow + // Formats recipients list as a URL-encoded array + // 'http://api.knock.test/v1/users/user_id/schedules?recipients[0]=user_id&recipients[1][collection]=object_collection&recipients[1][id]=object_id' expect(url).toBe( - "http://api.knock.test/v1/schedules?recipients%5B0%5D=user_id&recipients%5B1%5D%5Bcollection%5D=object_collection&recipients%5B1%5D%5Bid%5D=object_id&workflow=test-workflow", + "http://api.knock.test/v1/users/user_id/schedules?recipients%5B0%5D=user_id&recipients%5B1%5D%5Bcollection%5D=object_collection&recipients%5B1%5D%5Bid%5D=object_id", ); }); });