Skip to content

Commit

Permalink
tests: read local API url from a central file
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Jun 16, 2024
1 parent 3663a1b commit 71ec0c8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 4 additions & 2 deletions tests/base/local_wiki.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const { Mwn, log, expect, assert, sinon, verifyTokenAndSiteInfo } = require('./test_base');

const localApiUrl = 'http://localhost:8080/api.php';

const baseConfig = {
silent: true,
apiUrl: 'http://localhost:8080/api.php',
apiUrl: localApiUrl,
password: '12345678901234567890123456789012',
userAgent: 'mwn (https://github.com/siddharthvp/mwn)',
defaultParams: {
Expand Down Expand Up @@ -30,4 +32,4 @@ async function setup() {
async function teardown() {}

// Export everything
module.exports = { Mwn, bot, bot2, log, expect, assert, sinon, setup, teardown };
module.exports = { Mwn, bot, bot2, localApiUrl, log, expect, assert, sinon, setup, teardown };
6 changes: 3 additions & 3 deletions tests/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { MwnError } = require('../build/error');
const nock = require('nock');

const { expect, Mwn } = require('./base/test_base');
const { bot, setup, teardown, sinon } = require('./base/local_wiki');
const { bot, setup, teardown, sinon, localApiUrl } = require('./base/local_wiki');

describe('core', function () {
this.timeout(5000);
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('core', function () {
it('honours method passed in custom options', async function () {
sinon.spy(Request.prototype, 'handlePost');
sinon.spy(Request.prototype, 'handleGet');
let scope = nock('http://localhost:8080/api.php').post(/.*?/).times(1).reply(200, '{}');
let scope = nock(localApiUrl).post(/.*?/).times(1).reply(200, '{}');
await bot.request({ action: 'query' }, { method: 'post' });
expect(Request.prototype.handlePost).to.have.been.calledOnce;
expect(Request.prototype.handleGet).to.not.have.been.called;
Expand All @@ -65,7 +65,7 @@ describe('core', function () {
after('teardown', teardown);

it('logs on network errors and retries them', async function () {
nock('http://localhost:8080/api.php', { allowUnmocked: true }).get(/.*?/).times(1).reply(500, 'body', {});
nock(localApiUrl, { allowUnmocked: true }).get(/.*?/).times(1).reply(500, 'body', {});
sinon.spy(console, 'log');
await expect(bot.query({ action: 'query' })).to.be.eventually.deep.eq({ batchcomplete: true });
expect(console.log).to.have.been.calledTwice;
Expand Down
4 changes: 2 additions & 2 deletions tests/errors.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { sinon, bot, bot2, expect, setup, teardown } = require('./base/local_wiki');
const { sinon, bot, bot2, expect, setup, teardown, localApiUrl } = require('./base/local_wiki');
const nock = require('nock');
const { Request, Response } = require('../build/core');
const utils = require('../build/utils');
Expand Down Expand Up @@ -151,5 +151,5 @@ describe('testing for error recoveries', function () {
});

function mockApi(times, body, headers) {
nock('http://localhost:8080/api.php', { allowUnmocked: true }).get(/.*?/).times(times).reply(200, body, headers);
nock(localApiUrl, { allowUnmocked: true }).get(/.*?/).times(times).reply(200, body, headers);
}

0 comments on commit 71ec0c8

Please sign in to comment.