Client(agent)

Show:

new Client(agent)

Constructs a new agent for making HTTP requests to the MediaWiki action API.

Constructs a new agent for making HTTP requests to the MediaWiki action API. The agent acts like a browser session and has its own cookie jar.

Pass in an optional supertest agent to use for making requests where the client wants to behave as a logged in user. If not supplied, client behaves like an "anonymous" user until account() is used to attach the client to a user account.

Note that all anonymous users share the same IP address, even though they don't share a browser session (cookie jar). This means that are treated as the same user in some respects, but not in others.

Parameters:
Name Type Description
agent Object

supertest agent

Source:

Methods

(async) account(name, passwd) → {Promise.<Client>}

Attaches this API client to a user account.

Attaches this API client to a user account.

A login for this user is performed, and the corresponding server session is associated with this client. This should only be used when instantiating fixtures.

If no password is given, a new user account is created with a random password and a random suffix appended to the user name. The new user is then logged in. This should be used to construct a temporary unique user account that can be modified and destroyed by tests.

Parameters:
Name Type Default Description
name string
passwd string | null null
Source:
Returns:
Type
Promise.<Client>

(async) action(actionName, params, post) → {Promise.<Object>}

Executes an HTTP request to the action API and returns the parsed response body.

Executes an HTTP request to the action API and returns the parsed response body. Will fail if the response contains an error code.

Parameters:
Name Type Default Description
actionName string
params Object
post boolean | string false
Source:
Returns:
Type
Promise.<Object>

(async) actionError(actionName, params, post) → {Promise.<Object>}

Executes an HTTP request to the action API and returns the error stanza of the response body.

Executes an HTTP request to the action API and returns the error stanza of the response body. Will fail if there is no error stanza. This is intended as an easy way to test for expected errors.

Parameters:
Name Type Default Description
actionName string
params Object
post boolean | string false
Source:
Returns:
Type
Promise.<Object>

(async) actionWithErrors(actionName, params, post, allowErrors) → {Promise.<Object>}

Executes an HTTP request to the action API and returns the parsed response body.

Executes an HTTP request to the action API and returns the parsed response body. Will fail if the response contains an unexpected error code.

Parameters:
Name Type Default Description
actionName string
params Object
post boolean | string false
allowErrors Array.<string>

allow matching errors to pass through without assertion failure

Source:
Returns:
Type
Promise.<Object>

(async) addGroups(userName, groups) → {Promise.<Object>}

...
Parameters:
Name Type Description
userName string
groups Array.<string>
Source:
Returns:
Type
Promise.<Object>

(async) createAccount(params) → {Promise.<Object>}

...
Parameters:
Name Type Description
params Object
Source:
Returns:
Type
Promise.<Object>

(async) edit(pageTitle, params) → {Promise.<Object>}

Performs an edit on a page.

Performs an edit on a page.

Parameters:
Name Type Description
pageTitle string
params Object
Source:
Returns:
Type
Promise.<Object>

(async) getChangeEntry(params) → {Promise.<Object>}

Returns the newest recent changes entry matching the given parameters.

Returns the newest recent changes entry matching the given parameters.

Parameters:
Name Type Description
params Object
Source:
Returns:
Type
Promise.<Object>

(async) getLogEntry(params) → {Promise.<Object>}

Returns the newest log entry matching the given parameters.

Returns the newest log entry matching the given parameters.

Parameters:
Name Type Description
params Object
Source:
Returns:
Type
Promise.<Object>

(async) getRevision(pageTitle, revid) → {Promise.<Object>}

Returns a revision record of the given page.

Returns a revision record of the given page. If revid is not given or 0, the latest revision is returned.

Parameters:
Name Type Default Description
pageTitle string
revid number 0
Source:
Returns:
Type
Promise.<Object>

(async) list(list, params) → {Promise.<Array>}

Executes a list query

.

Executes a list query

Parameters:
Name Type Description
list string
params Object
Source:
Returns:
Type
Promise.<Array>

(async) loadTokens(ttypes) → {Promise.<Object>}

Loads the given tokens.

Loads the given tokens. Any cached tokens are reset.

Parameters:
Name Type Description
ttypes Array.<string>
Source:
Returns:
Type
Promise.<Object>

(async) login(username, password) → {Promise.<Object>}

Logs this agent in as the given user.

Logs this agent in as the given user.

Parameters:
Name Type Description
username string
password string
Source:
Returns:
Type
Promise.<Object>

(async) meta(meta, params, field) → {Promise.<Object>}

Executes a meta query

.

Executes a meta query

Parameters:
Name Type Default Description
meta string
params Object
field string null
Source:
Returns:
Type
Promise.<Object>

(async) prop(prop, titles, params) → {Promise.<Array>}

Executes a prop query

.

Executes a prop query

Parameters:
Name Type Description
prop string | Array
titles string | Array
params Object
Source:
Returns:
Type
Promise.<Array>

(async) request(params, post, endpoint) → {Promise.<*>}

Constructs an HTTP request to the action API and returns the corresponding supertest Test object, which behaves like a superagent Request.

Constructs an HTTP request to the action API and returns the corresponding supertest Test object, which behaves like a superagent Request. It can be used like a Promise that resolves to a Response.

Call end(), then(), or use await to send the request.

Parameters:
Name Type Default Description
params Object
post boolean | string false
endpoint string api.php
Source:
Returns:
Type
Promise.<*>

(async) token(ttype) → {Promise.<string>}

Returns the given token.

Returns the given token. If the token is not cached, it is requested and then cached.

Parameters:
Name Type Default Description
ttype string csrf
Source:
Returns:
Type
Promise.<string>

(async) upload(params, file, endpoint) → {Promise.<*>}

Executes an upload request

.

Executes an upload request

Parameters:
Name Type Default Description
params Object
file string | ArrayBuffer

file path or Buffer object.

endpoint string api.php
Source:
Returns:
Type
Promise.<*>