js_examples: Migrate and test get_events example.

This also adds "queue_id" to the response parameters and in the example
for GET /events in zulip.yaml.
This commit is contained in:
Kartik Srivastava
2020-06-29 21:44:47 +05:30
committed by Tim Abbott
parent cbd73a6dc1
commit 87787efa81
3 changed files with 35 additions and 24 deletions

View File

@@ -52,6 +52,7 @@ const ExamplesHandler = function () {
await generate_validation_data(client, examples.remove_subscriptions);
await generate_validation_data(client, examples.update_message_flags);
await generate_validation_data(client, examples.update_message);
await generate_validation_data(client, examples.get_events);
console.log(JSON.stringify(response_data));
return;
@@ -324,4 +325,32 @@ add_example('update_message', '/messages/{message_id}:patch', 200, async (client
// {code_example|end}
});
add_example('get_events', '/events:get', 200, async (client) => {
// Register queue to receive messages for user.
const queueParams = {
event_types: ['message'],
};
const res = await client.queues.register(queueParams);
const queue_id = res.queue_id;
// For setup, we send a message to ensure there are events in the
// queue; this lets the automated tests complete quickly.
const params = {
to: 'social',
type: 'stream',
topic: 'Castle',
content: 'I come not, friends, to steal away your hearts.',
};
client.messages.send(params);
// {code_example|start}
// Retrieve events from a queue with given "queue_id"
const eventParams = {
queue_id: queue_id,
last_event_id: -1,
};
return await client.events.retrieve(eventParams);
// {code_example|end}
});
main();

View File

@@ -158,8 +158,13 @@ paths:
items:
type: object
additionalProperties: false
queue_id:
type: string
description: |
The ID of the registered queue.
- example:
{
"queue_id": "1375801870:2942",
"events": [
{
"id": 0,