From a881c1675f91cb58158b00947df7eb81b8ca3bd2 Mon Sep 17 00:00:00 2001 From: Thomas Arrow Date: Fri, 11 Jan 2019 17:36:12 +0000 Subject: [PATCH] Add block and unblock commands to WDIO Defaults to expiry time of never to mirror API default This leaves it up to individual test suite to assert that the user they use is in the right blocked/unblocked state Bug: T211038 Change-Id: Icf94458eb9c9a1fa25e5ef9291d9fc2c54a5567c --- tests/selenium/wdio-mediawiki/Api.js | 56 ++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/selenium/wdio-mediawiki/Api.js b/tests/selenium/wdio-mediawiki/Api.js index 40bce32edc..f68fee95bf 100644 --- a/tests/selenium/wdio-mediawiki/Api.js +++ b/tests/selenium/wdio-mediawiki/Api.js @@ -73,5 +73,61 @@ module.exports = { retype: password } ); } ); + }, + + /** + * Shortcut for `MWBot#request( { action: 'block', .. } )`. + * + * @since 0.3.0 + * @see + * @param {string} [username] defaults to user making the request + * @param {string} [expiry] default is not set. For format see API docs + * @return {Object} Promise for API action=block response data. + */ + blockUser( username, expiry ) { + let 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 + } ); + } ); + }, + + /** + * Shortcut for `MWBot#request( { action: 'unblock', .. } )`. + * + * @since 0.3.0 + * @see + * @param {string} [username] defaults to user making the request + * @return {Object} Promise for API action=unblock response data. + */ + unblockUser( username ) { + let 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 + } ); + } ); } }; -- 2.20.1