-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
endpoint enhancement: Add endpoint for mark messages.
Implement endpoints for mark all messages, mark messages in stream and mark messages in topic.
- Loading branch information
1 parent
db9b0e4
commit 34cdc46
Showing
6 changed files
with
119 additions
and
8 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,25 @@ | ||
const zulip = require('../lib'); | ||
|
||
const config = { | ||
username: process.env.ZULIP_USERNAME, | ||
apiKey: process.env.ZULIP_API_KEY, | ||
realm: process.env.ZULIP_REALM, | ||
}; | ||
|
||
(async () => { | ||
const z = await zulip(config); | ||
// Mark all messages as read | ||
console.log(await z.mark.all()); | ||
|
||
// Mark all the unread messages in a stream as read | ||
const streamParams = { | ||
stream_id: 1, | ||
}; | ||
console.log(await z.mark.stream(streamParams)); | ||
// Mark all the unread messages in a topic as read | ||
const topicParams = { | ||
stream_id: 1, | ||
topic_name: 'Testing zulip-js', | ||
}; | ||
console.log(await z.mark.topic(topicParams)); | ||
})(); |
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,20 @@ | ||
const api = require('../api'); | ||
|
||
function mark(config) { | ||
return { | ||
all: (params) => { | ||
const url = `${config.apiURL}/mark_all_as_read`; | ||
return api(url, config, 'POST', params); | ||
}, | ||
stream: (params) => { | ||
const url = `${config.apiURL}/mark_stream_as_read`; | ||
return api(url, config, 'POST', params); | ||
}, | ||
topic: (params) => { | ||
const url = `${config.apiURL}/mark_topic_as_read`; | ||
return api(url, config, 'POST', params); | ||
}, | ||
}; | ||
} | ||
|
||
module.exports = mark; |
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,59 @@ | ||
const chai = require('chai'); | ||
const mark = require('../../lib/resources/mark'); | ||
const common = require('../common'); | ||
|
||
chai.should(); | ||
|
||
describe('Mark', () => { | ||
it('should mark all messages as read', async () => { | ||
const validator = (url, options) => { | ||
url.should.contain(`${common.config.apiURL}/mark_all_as_read`); | ||
Object.keys(options.body.data).length.should.equal(0); | ||
options.method.should.be.equal('POST'); | ||
}; | ||
const output = { | ||
msg: '', | ||
result: 'success', | ||
}; | ||
common.stubNetwork(validator, output); | ||
const data = await mark(common.config).all(); | ||
data.should.have.property('result', 'success'); | ||
}); | ||
|
||
it('should mark all messages in a stream as read', async () => { | ||
const paramsStream = { | ||
stream_id: 15, | ||
}; | ||
const validator = (url, options) => { | ||
url.should.contain(`${common.config.apiURL}/mark_stream_as_read`); | ||
Object.keys(options.body.data).length.should.equal(1); | ||
options.method.should.be.equal('POST'); | ||
}; | ||
const outputStream = { | ||
msg: '', | ||
result: 'success', | ||
}; | ||
common.stubNetwork(validator, outputStream); | ||
const dataStream = await mark(common.config).stream(paramsStream); | ||
dataStream.should.have.property('result', 'success'); | ||
}); | ||
|
||
it('should mark all messages in a topic as read', async () => { | ||
const paramsTopic = { | ||
stream_id: 15, | ||
topic_name: 'Denmark1', | ||
}; | ||
const validator = (url, options) => { | ||
url.should.contain(`${common.config.apiURL}/mark_topic_as_read`); | ||
Object.keys(options.body.data).length.should.equal(2); | ||
options.method.should.be.equal('POST'); | ||
}; | ||
const outputTopic = { | ||
msg: '', | ||
result: 'success', | ||
}; | ||
common.stubNetwork(validator, outputTopic); | ||
const dataTopic = await mark(common.config).topic(paramsTopic); | ||
dataTopic.should.have.property('result', 'success'); | ||
}); | ||
}); |