Skip to content

Commit

Permalink
core: add test for method option, bump package version
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Jun 16, 2024
1 parent 40fad44 commit 4291fb1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
12 changes: 12 additions & 0 deletions tests/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 4291fb1

Please sign in to comment.