From 3663a1b539789215a9b90625e979a781bcb3612b Mon Sep 17 00:00:00 2001 From: Siddharth VP Date: Sun, 16 Jun 2024 23:15:17 +0530 Subject: [PATCH] core: add test for method option, bump package version --- package-lock.json | 16 ++++++++-------- package.json | 2 +- src/core.ts | 2 +- tests/core.test.js | 12 ++++++++++++ 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 87e50b2..84f0f44 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mwn", - "version": "2.0.2", + "version": "2.0.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "mwn", - "version": "2.0.2", + "version": "2.0.3", "license": "LGPL-3.0-or-later", "dependencies": { "@types/node": "^14.14.25", @@ -6901,9 +6901,9 @@ } }, "node_modules/psl": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", - "integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ==" + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", + "integrity": "sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==" }, "node_modules/pump": { "version": "3.0.0", @@ -14693,9 +14693,9 @@ "dev": true }, "psl": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", - "integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ==" + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", + "integrity": "sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==" }, "pump": { "version": "3.0.0", diff --git a/package.json b/package.json index c73f651..539c3a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mwn", - "version": "2.0.2", + "version": "2.0.3", "description": "JavaScript & TypeScript MediaWiki bot framework for Node.js", "main": "./build/bot.js", "types": "./build/bot.d.ts", diff --git a/src/core.ts b/src/core.ts index 757802f..54441e3 100644 --- a/src/core.ts +++ b/src/core.ts @@ -38,7 +38,7 @@ export class Request { } getMethod() { - if (this.requestParams.method !== undefined) { + if (this.requestParams.method) { return this.requestParams.method; } if (this.apiParams.action === 'query') { diff --git a/tests/core.test.js b/tests/core.test.js index 25eef55..d8059e0 100644 --- a/tests/core.test.js +++ b/tests/core.test.js @@ -46,6 +46,18 @@ describe('core', function () { expect(Response.prototype.handleRequestFailure).to.have.been.calledOnce; sinon.restore(); }); + + 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, '{}'); + await bot.request({ action: 'query' }, { method: 'post' }); + expect(Request.prototype.handlePost).to.have.been.calledOnce; + expect(Request.prototype.handleGet).to.not.have.been.called; + expect(scope.isDone()).to.be.true; + sinon.restore(); + nock.cleanAll(); + }); }); describe('Response', function () {