Skip to content

Black Friday

Annual Pro is $90 for the first year, normally $120. Or start monthly at $6 for two months, then $12.

Ends Dec 4, 11:59 PM PT.

Create an account
← Public packages

@kentcdodds/slack

Read Slack conversations and safely send messages as the authorizing user through the saved slack OAuth integration.

FollowFork

Files

slack-method.test.ts

26 lines · 906 B · TypeScript
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { assertSlackMethod, isValidSlackMethod } from '../src/validation.ts'

test('accepts real Slack Web API method names, including camelCase', () => {
  for (const method of [
    'chat.postMessage',
    'chat.postEphemeral',
    'conversations.history',
    'conversations.replies',
    'conversations.list',
    'users.info',
    'users.list',
    'auth.test',
  ]) {
    assert.equal(isValidSlackMethod(method), true, method)
    assert.equal(assertSlackMethod(method), method)
  }
})

test('rejects invalid method names', () => {
  for (const method of ['', 'a', '../x', 'Chat.post', '.chat', 'chat/post', 'chat.post?x=1', 'chat post', undefined, null, 42]) {
    assert.equal(isValidSlackMethod(method), false, String(method))
    assert.throws(() => assertSlackMethod(method), /Invalid Slack Web API method name\./)
  }
})