Debian Codegraph @

tests/selenium/wdio-mediawiki/Api.js

raw symbols SCIP
1 'use strict';
2
3 const MWBot = require( 'mwbot' );
4
5 module.exports = {
6 /**
7 * Get a logged-in instance of `MWBot` with edit token already set up.
8 * Default username, password and base URL is used unless specified.
9 *
10 * @since 0.5.0
11 * @param {string} username - Optional
12 * @param {string} password - Optional
13 * @param {string} baseUrl - Optional
14 * @return {Promise<MWBot>}
15 */
16 async bot(
17 username = browser.config.mwUser,
18 password = browser.config.mwPwd,
19 baseUrl = browser.config.baseUrl
20 ) {
21 const bot = new MWBot();
22
23 await bot.loginGetEditToken( {
24 apiUrl: `${ baseUrl }/api.php`,
25 username: username,
26 password: password
27 } );
28 return bot;
29 },
30
31 /**
32 * Shortcut for `MWBot#request( { acount: 'createaccount', .. } )`.
33 *
34 * @since 0.1.0
35 * @see <https://www.mediawiki.org/wiki/API:Account_creation>
36 * @param {MWBot} adminBot
37 * @param {string} username New user name
38 * @param {string} password New user password
39 * @return {Object} Promise for API action=createaccount response data.
40 */
41 async createAccount( adminBot, username, password ) {
42 await adminBot.getCreateaccountToken();
43
44 // Create the new account
45 return await adminBot.request( {
46 action: 'createaccount',
47 createreturnurl: browser.config.baseUrl,
48 createtoken: adminBot.createaccountToken,
49 username: username,
50 password: password,
51 retype: password
52 } );
53 },
54
55 /**
56 * Shortcut for `MWBot#request( { action: 'block', .. } )`.
57 *
58 * @since 0.3.0
59 * @see <https://www.mediawiki.org/wiki/API:Block>
60 * @param {MWBot} adminBot
61 * @param {string} [username] defaults to blocking the admin user
62 * @param {string} [expiry] default is not set. For format see API docs
63 * @return {Object} Promise for API action=block response data.
64 */
65 async blockUser( adminBot, username, expiry ) {
66 return await adminBot.request( {
67 action: 'block',
68 user: username || browser.config.mwUser,
69 reason: 'browser test',
70 token: adminBot.editToken,
71 expiry
72 } );
73 },
74
75 /**
76 * Shortcut for `MWBot#request( { action: 'unblock', .. } )`.
77 *
78 * @since 0.3.0
79 * @see <https://www.mediawiki.org/wiki/API:Block>
80 * @param {MWBot} adminBot
81 * @param {string} [username] defaults to unblocking the admin user
82 * @return {Object} Promise for API action=unblock response data.
83 */
84 async unblockUser( adminBot, username ) {
85 return await adminBot.request( {
86 action: 'unblock',
87 user: username || browser.config.mwUser,
88 reason: 'browser test done',
89 token: adminBot.editToken
90 } );
91 }
92 };