Skellington-Closet / slack-mock

A Slack API mocker for Slack bot integration tests.
MIT License
64 stars 15 forks source link

Example usage with `@slack/client` #31

Open timkinnane opened 5 years ago

timkinnane commented 5 years ago

Hi, this looks like a great utility, but I'm having trouble getting it working with the Slack SDK, as opposed to the more bespoke solutions in the examples. Below is my attempt, but I'm getting this error: @slack/client:RTMClient2 unable to RTM start: Cannot read property 'id' of undefined

const { expect } = require('chai')
const { RTMClient } = require('@slack/client')
const slackMock = require('slack-mock')()
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
const token = process.env.BOT_SLACK_USER_TOKEN

describe('[client]', () => {
  before(() => {
    slackMock.web.addResponse({
      url: 'https://slack.com/api/rtm.start',
      status: 200,
      body: {
        ok: true,
        self: { name: 'mockSelf', id: 'mself' },
        team: { name: 'mockTeam', id: 'mteam' }
      }
    })
    return delay(50)
  })
  beforeEach(() => {
    slackMock.reset()
  })
  after(() => {
    return slackMock.rtm.stopServer(token)
  })
  describe('connect', () => {
    it('is able to connect', async () => {
      const rtm = new RTMClient(token)
      const connection = await rtm.start({})
      expect(connection.ok).to.equal(true)
      expect(connection).to.include.keys(['team'])
    })
  })
})

p.s. The test works if I remove slack-mock.