Merge "wdio-mediawiki: fix @since versions"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 17 Sep 2019 19:06:31 +0000 (19:06 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 17 Sep 2019 19:06:31 +0000 (19:06 +0000)
1  2 
tests/selenium/wdio-mediawiki/Api.js

@@@ -3,37 -3,11 +3,37 @@@ const MWBot = require( 'mwbot' )
  // TODO: Once we require Node 7 or later, we can use async-await.
  
  module.exports = {
 +      /**
 +       * Get a logged-in instance of `MWBot` with edit token already set up.
 +       * Default username, password and base URL is used unless specified.
 +       *
 +       * @since 0.5.0
 +       * @param {string} username - Optional
 +       * @param {string} password - Optional
 +       * @param {string} baseUrl - Optional
 +       * @return {Promise<MWBot>}
 +       */
 +      bot(
 +              username = browser.options.username,
 +              password = browser.options.password,
 +              baseUrl = browser.options.baseUrl
 +      ) {
 +              const bot = new MWBot();
 +
 +              return bot.loginGetEditToken( {
 +                      apiUrl: `${baseUrl}/api.php`,
 +                      username: username,
 +                      password: password
 +              } ).then( function () {
 +                      return bot;
 +              } );
 +      },
 +
        /**
         * Shortcut for `MWBot#edit( .. )`.
         * Default username, password and base URL is used unless specified
         *
-        * @since 1.0.0
+        * @since 0.1.0
         * @see <https://www.mediawiki.org/wiki/API:Edit>
         * @param {string} title
         * @param {string} content
                password = browser.options.password,
                baseUrl = browser.options.baseUrl
        ) {
 -              const bot = new MWBot();
 -
 -              return bot.loginGetEditToken( {
 -                      apiUrl: `${baseUrl}/api.php`,
 -                      username: username,
 -                      password: password
 -              } ).then( function () {
 -                      return bot.edit( title, content, `Created or updated page with "${content}"` );
 -              } );
 +              return this.bot( username, password, baseUrl )
 +                      .then( function ( bot ) {
 +                              return bot.edit( title, content, `Created or updated page with "${content}"` );
 +                      } );
        },
  
        /**
         * Shortcut for `MWBot#delete( .. )`.
         *
-        * @since 1.0.0
+        * @since 0.1.0
         * @see <https://www.mediawiki.org/wiki/API:Delete>
         * @param {string} title
         * @param {string} reason
         * @return {Object} Promise for API action=delete response data.
         */
        delete( title, reason ) {
 -              const bot = new MWBot();
 -
 -              return bot.loginGetEditToken( {
 -                      apiUrl: `${browser.options.baseUrl}/api.php`,
 -                      username: browser.options.username,
 -                      password: browser.options.password
 -              } ).then( function () {
 -                      return bot.delete( title, reason );
 -              } );
 +              return this.bot()
 +                      .then( function ( bot ) {
 +                              return bot.delete( title, reason );
 +                      } );
        },
  
        /**
         * Shortcut for `MWBot#request( { acount: 'createaccount', .. } )`.
         *
-        * @since 1.0.0
+        * @since 0.1.0
         * @see <https://www.mediawiki.org/wiki/API:Account_creation>
         * @param {string} username
         * @param {string} password
         * @return {Object} Promise for API action=block response data.
         */
        blockUser( username, expiry ) {
 -              const bot = new MWBot();
 -
 -              // Log in as admin
 -              return bot.loginGetEditToken( {
 -                      apiUrl: `${browser.options.baseUrl}/api.php`,
 -                      username: browser.options.username,
 -                      password: browser.options.password
 -              } ).then( () => {
 -                      // block user. default = admin
 -                      return bot.request( {
 -                              action: 'block',
 -                              user: username || browser.options.username,
 -                              reason: 'browser test',
 -                              token: bot.editToken,
 -                              expiry
 +              return this.bot()
 +                      .then( function ( bot ) {
 +                              // block user. default = admin
 +                              return bot.request( {
 +                                      action: 'block',
 +                                      user: username || browser.options.username,
 +                                      reason: 'browser test',
 +                                      token: bot.editToken,
 +                                      expiry
 +                              } );
                        } );
 -              } );
        },
  
        /**
         * @return {Object} Promise for API action=unblock response data.
         */
        unblockUser( username ) {
 -              const bot = new MWBot();
 -
 -              // Log in as admin
 -              return bot.loginGetEditToken( {
 -                      apiUrl: `${browser.options.baseUrl}/api.php`,
 -                      username: browser.options.username,
 -                      password: browser.options.password
 -              } ).then( () => {
 -                      // unblock user. default = admin
 -                      return bot.request( {
 -                              action: 'unblock',
 -                              user: username || browser.options.username,
 -                              reason: 'browser test done',
 -                              token: bot.editToken
 +              return this.bot()
 +                      .then( function ( bot ) {
 +                              // unblock user. default = admin
 +                              return bot.request( {
 +                                      action: 'unblock',
 +                                      user: username || browser.options.username,
 +                                      reason: 'browser test done',
 +                                      token: bot.editToken
 +                              } );
                        } );
 -              } );
        }
  };