api-testing
Advanced tools
Comparing version 1.0.4 to 1.1.0
@@ -8,3 +8,4 @@ 'use strict'; | ||
assert: require('./lib/assert').assert, | ||
wiki: require('./lib/wiki') | ||
wiki: require('./lib/wiki'), | ||
clientFactory: require('./lib/clientFactory') | ||
}; |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const { assert } = require('./assert'); | ||
@@ -2,0 +4,0 @@ const Client = require('./actionapi'); |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const { assert } = require('./assert'); | ||
@@ -13,4 +15,6 @@ const supertest = require('supertest'); | ||
* | ||
* Until account() is used to attach the client to a user account, | ||
* the client behaves like an "anonymous" user. | ||
* 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. | ||
* | ||
@@ -20,8 +24,15 @@ * Note that all anonymous users share the same IP address, even though they | ||
* as the same user in some respects, but not in others. | ||
* | ||
* @param {Object} agent supertest agent | ||
*/ | ||
constructor() { | ||
this.req = supertest.agent(config.base_uri); | ||
this.username = '<anon>'; | ||
this.userid = 0; | ||
constructor(agent) { | ||
if (agent) { | ||
this.req = agent.req; | ||
this.username = agent.username; | ||
this.userid = agent.userid; | ||
} else { | ||
this.req = supertest.agent(config.base_uri); | ||
this.username = '<anon>'; | ||
this.userid = 0; | ||
} | ||
} | ||
@@ -99,3 +110,3 @@ | ||
* Executes an HTTP request to the action API and returns the parsed | ||
* response body. Will fail if the reponse contains an error code. | ||
* response body. Will fail if the response contains an error code. | ||
* | ||
@@ -283,3 +294,3 @@ * @param {string} actionName | ||
}, | ||
'POST', | ||
'POST' | ||
); | ||
@@ -313,3 +324,3 @@ assert.equal(result.login.result, 'Success', | ||
// use a unique default text | ||
effectiveParams.text = effectiveParams.text || 'Lorem ipsum ' + utils.uniq(); // eslint-disable-line | ||
effectiveParams.text = effectiveParams.text || 'Lorem ipsum ' + utils.uniq(); | ||
@@ -336,3 +347,3 @@ effectiveParams.token = params.token || await this.token('csrf'); | ||
* @param {string} pageTitle | ||
* @param {int} revid | ||
* @param {number} revid | ||
* @return {Promise<Object>} | ||
@@ -339,0 +350,0 @@ */ |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const { use } = require('chai'); | ||
@@ -9,2 +11,3 @@ const utils = require('./utils'); | ||
* Compares two titles, applying some normalization | ||
* | ||
* @param {string} act | ||
@@ -11,0 +14,0 @@ * @param {string} exp |
@@ -25,3 +25,3 @@ 'use strict'; | ||
} else { | ||
// If .api-testing.config.json doesnt exist in root folder, throw helpful error | ||
// If .api-testing.config.json doesn't exist in root folder, throw helpful error | ||
const localConfigFile = '.api-testing.config.json'; | ||
@@ -28,0 +28,0 @@ requireFile = `${baseDir}/${localConfigFile}`; |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const supertest = require('supertest'); | ||
@@ -9,6 +11,19 @@ const config = require('./config')(); | ||
* cookie jar. | ||
* Pass in an optional supertest agent with user session information (cookie jar) | ||
* for the client to behave as a logged in user. | ||
* | ||
* @param {string} endpoint REST endpoint path | ||
* @param {Object} agent supertest agent | ||
*/ | ||
constructor(endpoint = 'rest.php/v1') { | ||
this.req = supertest.agent(config.base_uri + endpoint); | ||
constructor(endpoint = 'rest.php/v1', agent = null) { | ||
this.pathPrefix = endpoint; | ||
if (agent) { | ||
this.req = agent.req; | ||
this.username = agent.username; | ||
this.userid = agent.userid; | ||
} else { | ||
this.req = supertest.agent(config.base_uri); | ||
this.username = '<anon>'; | ||
this.userid = 0; | ||
} | ||
} | ||
@@ -34,2 +49,3 @@ | ||
let req; | ||
endpoint = this.pathPrefix + endpoint; | ||
switch (method.toUpperCase()) { | ||
@@ -36,0 +52,0 @@ case 'GET': |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
module.exports = { | ||
@@ -5,3 +7,3 @@ /** | ||
* | ||
* @param {int} n the desired number of characters | ||
* @param {number} n the desired number of characters | ||
* @return {string} | ||
@@ -31,3 +33,4 @@ */ | ||
* Returns a promise that will resolve in no less than the given number of milliseconds. | ||
* @param {int} ms wait time in milliseconds | ||
* | ||
* @param {number} ms wait time in milliseconds | ||
* @return {Promise<void>} | ||
@@ -41,2 +44,3 @@ */ | ||
* Converts a title string to DB key form by replacing any spaces with underscores. | ||
* | ||
* @param {string} title | ||
@@ -43,0 +47,0 @@ * @return {string} |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const supertest = require('supertest'); | ||
@@ -10,3 +12,3 @@ const crypto = require('crypto'); | ||
* | ||
* @param {int} n The number of jobs to run. | ||
* @param {number} n The number of jobs to run. | ||
* @return {Promise<number>} Zero if there are no more jobs to be run, | ||
@@ -27,3 +29,3 @@ * and a number grater than zero if there are more jobs ready to be run. | ||
for (var k of keys) { | ||
for (const k of keys) { | ||
data[k] = params[k]; | ||
@@ -30,0 +32,0 @@ } |
{ | ||
"name": "api-testing", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"test": "npm run lint && mocha", | ||
"lint": "eslint --cache --max-warnings 0 --ext .js ." | ||
"lint": "eslint --cache --max-warnings 0 ." | ||
}, | ||
@@ -25,7 +25,5 @@ "repository": { | ||
"devDependencies": { | ||
"eslint": "^5.16.0", | ||
"eslint-config-wikimedia": "^0.13.1", | ||
"eslint-plugin-jsdoc": "^15.8.0", | ||
"mocha": "^6.2.0" | ||
"eslint-config-wikimedia": "0.16.1", | ||
"mocha": "7.2.0" | ||
} | ||
} |
@@ -0,4 +1,7 @@ | ||
'use strict'; | ||
const { assert, utils } = require('../index'); | ||
const fs = require('fs'); | ||
const os = require('os'); | ||
// eslint-disable-next-line node/no-unsupported-features/node-builtins | ||
const fsp = fs.promises; | ||
@@ -41,5 +44,6 @@ | ||
const getConfig = require('../lib/config'); | ||
describe('Configuration', () => { | ||
let envVar; | ||
const getConfig = require('../lib/config'); | ||
@@ -46,0 +50,0 @@ before(async () => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2
60609
27
971
2