-
Notifications
You must be signed in to change notification settings - Fork 662
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.functions.* APIs.
- Loading branch information
Filip Maj
committed
Dec 7, 2023
1 parent
38dfcde
commit 692792f
Showing
3 changed files
with
82 additions
and
16 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,26 @@ | ||
import type { CursorPaginationEnabled, TokenOverridable } from '../common'; | ||
|
||
// https://api.slack.com/methods/admin.functions.list | ||
export interface AdminFunctionsListArguments extends TokenOverridable, CursorPaginationEnabled { | ||
/** @description Array of app IDs to get functions for; max 50. */ | ||
app_ids: string[]; | ||
/** @description The team context to retrieve functions from. */ | ||
team_id?: string; | ||
} | ||
|
||
// https://api.slack.com/methods/admin.functions.permissions.lookup | ||
export interface AdminFunctionsPermissionsLookupArguments | ||
extends TokenOverridable { | ||
/** @description An array of function IDs to get permissions for. */ | ||
function_ids: [string, ...string[]]; | ||
} | ||
|
||
// https://api.slack.com/methods/admin.functions.permissions.set | ||
export interface AdminFunctionsPermissionsSetArguments extends TokenOverridable { | ||
/** @description The function ID to set permissions for. */ | ||
function_id: string; | ||
/** @description The function visibility. */ | ||
visibility: 'everyone' | 'app_collaborators' | 'named_entities' | 'no_one'; | ||
/** @description List of user IDs to allow for `named_entities` visibility. */ | ||
user_ids?: string[]; | ||
} |
41 changes: 41 additions & 0 deletions
41
packages/web-api/test/types/methods/admin.functions.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,41 @@ | ||
import { expectAssignable, expectError } from 'tsd'; | ||
import { WebClient } from '../../../src/WebClient'; | ||
|
||
const web = new WebClient('TOKEN'); | ||
|
||
// admin.functions.list | ||
// -- sad path | ||
expectError(web.admin.functions.list()); // lacking argument | ||
expectError(web.admin.functions.list({})); // empty argument | ||
// -- happy path | ||
expectAssignable<Parameters<typeof web.admin.functions.list>>([{ | ||
app_ids: [], | ||
}]); | ||
|
||
// admin.functions.permissions.lookup | ||
// -- sad path | ||
expectError(web.admin.functions.permissions.lookup()); // lacking argument | ||
expectError(web.admin.functions.permissions.lookup({})); // empty argument | ||
expectError(web.admin.functions.permissions.lookup({ | ||
function_ids: [], // must provide at least 1 | ||
})); | ||
// -- happy path | ||
expectAssignable<Parameters<typeof web.admin.functions.permissions.lookup>>([{ | ||
function_ids: ['F1234'], | ||
}]); | ||
|
||
// admin.functions.permissions.set | ||
// -- sad path | ||
expectError(web.admin.functions.permissions.set()); // lacking argument | ||
expectError(web.admin.functions.permissions.set({})); // empty argument | ||
expectError(web.admin.functions.permissions.set({ | ||
function_id: 'F1234', // missing visibility | ||
})); | ||
expectError(web.admin.functions.permissions.set({ | ||
visibility: 'named_entities', // missing function_id | ||
})); | ||
// -- happy path | ||
expectAssignable<Parameters<typeof web.admin.functions.permissions.set>>([{ | ||
function_id: 'F1234', | ||
visibility: 'named_entities', | ||
}]); |