From a1f6540ceceb5ac9018d49ec9daade7f87863601 Mon Sep 17 00:00:00 2001 From: Kartik Srivastava Date: Mon, 22 Jun 2020 02:48:59 +0530 Subject: [PATCH] js_examples: Migrate and test render_message example. --- templates/zerver/api/render-message.md | 17 +---------------- zerver/openapi/javascript_examples.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/templates/zerver/api/render-message.md b/templates/zerver/api/render-message.md index 66f6c50f50..540e9646e7 100644 --- a/templates/zerver/api/render-message.md +++ b/templates/zerver/api/render-message.md @@ -12,23 +12,8 @@ {tab|js} More examples and documentation can be found [here](https://github.com/zulip/zulip-js). -```js -const zulip = require('zulip-js'); -// Pass the path to your zuliprc file here. -const config = { - zuliprc: 'zuliprc', -}; - -zulip(config).then((client) => { - // Render a message - const params = { - content: '**foo**', - }; - - client.messages.render(params).then(console.log); -}); -``` +{generate_code_example(javascript)|/messages/render:post|example} {tab|curl} diff --git a/zerver/openapi/javascript_examples.js b/zerver/openapi/javascript_examples.js index 292f7db262..964dc3559d 100644 --- a/zerver/openapi/javascript_examples.js +++ b/zerver/openapi/javascript_examples.js @@ -46,6 +46,7 @@ const ExamplesHandler = function () { await generate_validation_data(client, examples.get_subscriptions); await generate_validation_data(client, examples.get_users); await generate_validation_data(client, examples.register_queue); + await generate_validation_data(client, examples.render_message); console.log(JSON.stringify(response_data)); return; @@ -200,4 +201,15 @@ add_example('register_queue', '/register:post', 200, async (client) => { // {code_example|end} }); +add_example('render_message', '/messages/render:post', 200, async (client) => { + // {code_example|start} + // Render a message + const params = { + content: '**foo**', + }; + + return await client.messages.render(params); + // {code_example|end} +}); + main();