-
Notifications
You must be signed in to change notification settings - Fork 662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prep for major release of rtm-api #1764
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b265eb6
Prep for major release of rtm-api
filmaj ac507e0
rtm-api: added basic integration tests, decode websocket message (ws@8
filmaj 511ede7
rtm-api: fix for #842, explicit disconnect while disconnected should …
filmaj c6e4b87
forgot the mocha file
filmaj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"require": ["ts-node/register", "source-map-support/register"], | ||
"timeout": 3000 | ||
} |
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 |
---|---|---|
|
@@ -430,7 +430,7 @@ const rtm = new RTMClient(token, { | |
|
||
## Requirements | ||
|
||
This package supports Node v14 and higher. It's highly recommended to use [the latest LTS version of | ||
This package supports Node v18 and higher. It's highly recommended to use [the latest LTS version of | ||
node](https://github.com/nodejs/Release#release-schedule), and the documentation is written using syntax and features | ||
from that version. | ||
|
||
|
@@ -440,6 +440,3 @@ If you get stuck, we're here to help. The following are the best ways to get ass | |
|
||
* [Issue Tracker](http://github.com/slackapi/node-slack-sdk/issues) for questions, feature requests, bug reports and | ||
general discussion related to these packages. Try searching before you create a new issue. | ||
* [Email us](mailto:[email protected]) in Slack developer support: `[email protected]` | ||
* [Bot Developers Hangout](https://community.botkit.ai/): a Slack community for developers | ||
building all types of bots. You can find the maintainers and users of these packages in **#sdk-node-slack-sdk**. |
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,89 @@ | ||
const { assert } = require('chai'); | ||
const { RTMClient } = require('../src/RTMClient'); | ||
const { LogLevel } = require('../src/logger'); | ||
const { WebSocketServer} = require('ws'); | ||
const { createServer } = require('http'); | ||
const sinon = require('sinon'); | ||
|
||
const HTTP_PORT = 12345; | ||
const WSS_PORT = 23456; | ||
// Basic HTTP server to 'fake' behaviour of `apps.connections.open` endpoint | ||
let server = null; | ||
|
||
// Basic WS server to fake slack WS endpoint | ||
let wss = null; | ||
let exposed_ws_connection = null; | ||
|
||
// Socket mode client pointing to the above two posers | ||
let client = null; | ||
|
||
describe('Integration tests with a WebSocket server', () => { | ||
beforeEach(() => { | ||
server = createServer((req, res) => { | ||
res.writeHead(200, { 'content-type': 'application/json' }); | ||
res.end(JSON.stringify({ | ||
ok: true, | ||
url: `ws://localhost:${WSS_PORT}/`, | ||
self: { id: 'elclassico' }, | ||
team: { id: 'T12345' }, | ||
})); | ||
}); | ||
server.listen(HTTP_PORT); | ||
wss = new WebSocketServer({ port: WSS_PORT }); | ||
wss.on('connection', (ws) => { | ||
ws.on('error', (err) => { | ||
assert.fail(err); | ||
}); | ||
// Send `Event.ServerHello` | ||
ws.send(JSON.stringify({type: 'hello'})); | ||
exposed_ws_connection = ws; | ||
}); | ||
}); | ||
afterEach(() => { | ||
server.close(); | ||
server = null; | ||
wss.close(); | ||
wss = null; | ||
exposed_ws_connection = null; | ||
client = null; | ||
}); | ||
describe('establishing connection, receiving valid messages', () => { | ||
beforeEach(() => { | ||
client = new RTMClient('token', { | ||
slackApiUrl: `http://localhost:${HTTP_PORT}/`, | ||
logLevel: LogLevel.DEBUG, | ||
}); | ||
}); | ||
it('connects to a server via `start()` and gracefully disconnects via `disconnect()`', async () => { | ||
await client.start(); | ||
await sleep(50); // TODO: this is due to `start()` resolving once the authenticated event is raised | ||
// however, the handshake on the WS side still needs to complete at this point, so calling disconnect() | ||
// will raise an error. | ||
await client.disconnect(); | ||
}); | ||
it('can listen on slack event types and receive payload properties', async () => { | ||
client.on('connected', () => { | ||
exposed_ws_connection.send(JSON.stringify({ | ||
type: 'team_member_joined', | ||
envelope_id: 12345, | ||
})); | ||
}); | ||
await client.start(); | ||
await new Promise((res, _rej) => { | ||
client.on('team_member_joined', (evt) => { | ||
assert.equal(evt.envelope_id, 12345); | ||
res(); | ||
}); | ||
}); | ||
await client.disconnect(); | ||
}); | ||
it('should not raise an exception if calling disconnect() when already disconnected', async () => { | ||
// https://github.com/slackapi/node-slack-sdk/issues/842 | ||
await client.disconnect(); | ||
}); | ||
Comment on lines
+80
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sweeeeet |
||
}); | ||
}); | ||
|
||
function sleep(ms) { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! 🙌