From 203b72262442e83ecd16f1a45e63369b0e6d0ffa Mon Sep 17 00:00:00 2001 From: Rohitt Vashishtha Date: Sun, 17 May 2020 10:26:12 +0000 Subject: [PATCH] js-api: Migrate and test create-user example. --- templates/zerver/api/create-user.md | 19 +------------------ zerver/openapi/javascript_examples.js | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/templates/zerver/api/create-user.md b/templates/zerver/api/create-user.md index 25be85c1c9..9f80a57dab 100644 --- a/templates/zerver/api/create-user.md +++ b/templates/zerver/api/create-user.md @@ -14,25 +14,8 @@ {tab|js} More examples and documentation can be found [here](https://github.com/zulip/zulip-js). -```js -const zulip = require('zulip-js'); -// The user for this zuliprc file must be an organization administrator. -const config = { - zuliprc: 'zuliprc-admin', -}; - -zulip(config).then((client) => { - // Create a user - const params = { - email: 'newbie@zulip.com', - password: 'temp', - full_name: 'New User', - short_name: 'newbie' - }; - client.users.create(params).then(console.log); -}); -``` +{generate_code_example(javascript)|/users:post|example(admin_config=True)} {tab|curl} diff --git a/zerver/openapi/javascript_examples.js b/zerver/openapi/javascript_examples.js index 240673ec69..13a7d13572 100644 --- a/zerver/openapi/javascript_examples.js +++ b/zerver/openapi/javascript_examples.js @@ -58,8 +58,21 @@ const ExamplesHandler = function () { }; }; -const {main} = ExamplesHandler(); +const {main, add_example} = ExamplesHandler(); // Declare all the examples below. +add_example('create_user', '/users:post', 200, async (client) => { + // {code_example|start} + const params = { + email: 'newbie@zulip.com', + password: 'temp', + full_name: 'New User', + short_name: 'newbie', + }; + + return await client.users.create(params); + // {code_example|end} +}); + main();