-
Notifications
You must be signed in to change notification settings - Fork 664
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor arguments and type tests for admin.workflows.* APIs.
- Loading branch information
Filip Maj
committed
Dec 12, 2023
1 parent
260e242
commit a193b6e
Showing
7 changed files
with
164 additions
and
56 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
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,44 @@ | ||
import type { AppID, CursorPaginationEnabled, SortDir, TokenOverridable } from '../common'; | ||
|
||
interface CollaboratorIDs { | ||
/** @description Array of collaborators (encoded user IDs) - maximum of 50 items. */ | ||
collaborator_ids: [string, ...string[]]; | ||
} | ||
|
||
interface WorkflowIDs { | ||
/** @description Array of workflow IDs - maximum of 50 items. */ | ||
workflow_ids: [string, ...string[]]; | ||
} | ||
|
||
// https://api.slack.com/methods/admin.workflows.collaborators.add | ||
export interface AdminWorkflowsCollaboratorsAddArguments extends CollaboratorIDs, WorkflowIDs, TokenOverridable {} | ||
|
||
// https://api.slack.com/methods/admin.workflows.collaborators.remove | ||
export interface AdminWorkflowsCollaboratorsRemoveArguments extends CollaboratorIDs, WorkflowIDs, TokenOverridable {} | ||
|
||
// https://api.slack.com/methods/admin.workflows.permissions.lookup | ||
export interface AdminWorkflowsPermissionsLookupArguments extends WorkflowIDs, TokenOverridable { | ||
/** | ||
* @description Maximum number of triggers to fetch for each workflow when determining overall run permissions. | ||
* Defaults to `100`. Maximum of `1000`. | ||
*/ | ||
max_workflow_triggers?: number; | ||
} | ||
|
||
// https://api.slack.com/methods/admin.workflows.search | ||
export interface AdminWorkflowsSearchArguments extends Partial<AppID>, Partial<CollaboratorIDs>, SortDir, | ||
TokenOverridable, CursorPaginationEnabled { | ||
/** @description Only include workflows with no collaborators in the result; default is `false`. */ | ||
no_collaborators?: boolean; | ||
/** @description Number of trigger IDs to fetch for each workflow; default is `0`. */ | ||
num_trigger_ids?: number; | ||
/** @description A search query to filter for workflow name or description. */ | ||
query?: string; | ||
/** @description The field used to sort the returned workflows. Currently only `premium_runs` is supported. */ | ||
sort?: 'premium_runs'; | ||
/** @description Source of workflow creation, either from `code` or `workflow_builder`. */ | ||
source?: 'code' | 'workflow_builder'; | ||
} | ||
|
||
// https://api.slack.com/methods/admin.workflows.unpublish | ||
export interface AdminWorkflowsUnpublishArguments extends WorkflowIDs, TokenOverridable {} |
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
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
84 changes: 84 additions & 0 deletions
84
packages/web-api/test/types/methods/admin.workflows.test-d.ts
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,84 @@ | ||
import { expectAssignable, expectError } from 'tsd'; | ||
import { WebClient } from '../../../src/WebClient'; | ||
|
||
const web = new WebClient('TOKEN'); | ||
|
||
// admin.workflows.collaborators.add | ||
// -- sad path | ||
expectError(web.admin.workflows.collaborators.add()); // lacking argument | ||
expectError(web.admin.workflows.collaborators.add({})); // empty argument | ||
expectError(web.admin.workflows.collaborators.add({ | ||
collaborator_ids: ['U1234'], // missing workflow_ids | ||
})); | ||
expectError(web.admin.workflows.collaborators.add({ | ||
workflow_ids: ['Wf1234'], // missing user_ids | ||
})); | ||
expectError(web.admin.workflows.collaborators.add({ | ||
collaborator_ids: ['U1234'], | ||
workflow_ids: [], // must provide at least 1 id | ||
})); | ||
expectError(web.admin.workflows.collaborators.add({ | ||
workflow_ids: ['Wf1234'], | ||
collaborator_ids: [], // must provide at least 1 id | ||
})); | ||
// -- happy path | ||
expectAssignable<Parameters<typeof web.admin.workflows.collaborators.add>>([{ | ||
collaborator_ids: ['U1234'], | ||
workflow_ids: ['Wf1234'], | ||
}]); | ||
|
||
// admin.workflows.collaborators.remove | ||
// -- sad path | ||
expectError(web.admin.workflows.collaborators.remove()); // lacking argument | ||
expectError(web.admin.workflows.collaborators.remove({})); // empty argument | ||
expectError(web.admin.workflows.collaborators.remove({ | ||
collaborator_ids: ['U1234'], // missing workflow_ids | ||
})); | ||
expectError(web.admin.workflows.collaborators.remove({ | ||
workflow_ids: ['Wf1234'], // missing user_ids | ||
})); | ||
expectError(web.admin.workflows.collaborators.remove({ | ||
collaborator_ids: ['U1234'], | ||
workflow_ids: [], // must provide at least 1 id | ||
})); | ||
expectError(web.admin.workflows.collaborators.remove({ | ||
workflow_ids: ['Wf1234'], | ||
collaborator_ids: [], // must provide at least 1 id | ||
})); | ||
// -- happy path | ||
expectAssignable<Parameters<typeof web.admin.workflows.collaborators.remove>>([{ | ||
collaborator_ids: ['U1234'], | ||
workflow_ids: ['Wf1234'], | ||
}]); | ||
|
||
// admin.workflows.permissions.lookup | ||
// -- sad path | ||
expectError(web.admin.workflows.permissions.lookup()); // lacking argument | ||
expectError(web.admin.workflows.permissions.lookup({})); // empty argument | ||
expectError(web.admin.workflows.permissions.lookup({ | ||
workflow_ids: [], // must provide at least 1 id | ||
})); | ||
// -- happy path | ||
expectAssignable<Parameters<typeof web.admin.workflows.permissions.lookup>>([{ | ||
workflow_ids: ['Wf1234'], | ||
}]); | ||
|
||
// admin.workflows.search | ||
// -- sad path | ||
expectError(web.admin.workflows.search()); // lacking argument | ||
expectError(web.admin.workflows.search({ | ||
collaborator_ids: [], // must provide at least 1 ID | ||
})); | ||
// -- happy path | ||
expectAssignable<Parameters<typeof web.admin.workflows.search>>([{}]); // all optional args OK | ||
|
||
// admin.workflows.unpublish | ||
// -- sad path | ||
expectError(web.admin.workflows.unpublish()); // lacking argument | ||
expectError(web.admin.workflows.unpublish({ | ||
workflow_ids: [], // must provide at least 1 ID | ||
})); | ||
// -- happy path | ||
expectAssignable<Parameters<typeof web.admin.workflows.unpublish>>([{ | ||
workflow_ids: ['Wf1234'], | ||
}]); |