wdio-mediawiki 2.6.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/Api.js +38 -0
  2. package/README.md +1 -0
  3. package/package.json +1 -1
package/Api.js CHANGED
@@ -88,5 +88,43 @@ module.exports = {
88
88
  reason: 'browser test done',
89
89
  token: adminBot.editToken
90
90
  } );
91
+ },
92
+
93
+ /**
94
+ * Assign a new user group to the given username.
95
+ *
96
+ * @since 2.7.0
97
+ * @param {MWBot} adminBot
98
+ * @param {string} username
99
+ * @param {string} groupName
100
+ */
101
+ async addUserToGroup( adminBot, username, groupName ) {
102
+ const userGroupsResponse = await adminBot.request( {
103
+ action: 'query',
104
+ list: 'users',
105
+ usprop: 'groups',
106
+ ususers: username,
107
+ formatversion: 2
108
+ } );
109
+
110
+ if (
111
+ userGroupsResponse.query.users.length &&
112
+ userGroupsResponse.query.users[ 0 ].groups.includes( groupName )
113
+ ) {
114
+ return;
115
+ }
116
+ const tokenResponse = await adminBot.request( {
117
+ action: 'query',
118
+ meta: 'tokens',
119
+ type: 'userrights'
120
+ } );
121
+ await adminBot.request( {
122
+ action: 'userrights',
123
+ user: username,
124
+ token: tokenResponse.query.tokens.userrightstoken,
125
+ add: groupName,
126
+ reason: 'Selenium testing'
127
+ } );
128
+ // If there is an error, the above already throws.
91
129
  }
92
130
  };
package/README.md CHANGED
@@ -26,6 +26,7 @@ which typically come from `MEDIAWIKI_USER` and `MEDIAWIKI_PASSWORD` environment
26
26
  * `createAccount(MWBot bot, string username, string password)`
27
27
  * `blockUser(MWBot bot, [ string username [, string expiry ] ])`
28
28
  * `unblockUser(MWBot bot, [ string username ])`
29
+ * `addUserToGroup(MWBot bot, string username, string groupName)`
29
30
 
30
31
  Example:
31
32
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wdio-mediawiki",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "WebdriverIO plugin for testing a MediaWiki site.",
5
5
  "homepage": "https://gerrit.wikimedia.org/g/mediawiki/core/+/master/tests/selenium/wdio-mediawiki",
6
6
  "license": "MIT",