Skip to content

Commit

Permalink
bot: add saveOption, saveOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Mar 8, 2021
1 parent 24508ca commit 2243cf7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,18 @@ export class mwn {
});
}

saveOption(option: string, value: string) {
return this.saveOptions({ [option]: value });
}

saveOptions(options: Record<string, string>) {
return this.request({
action: 'options',
change: Object.entries(options).map(([key, val]) => key + '=' + val),
token: this.csrfToken
});
}

/**
* Convenience method for `action=rollback`.
*
Expand Down
14 changes: 14 additions & 0 deletions tests/edit.bot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ describe('methods which modify the wiki', function() {
.that.has.property('code').which.equals('userexists');
});

it('changes user options', async () => {
await bot.saveOptions({
'userjs-mwntest': 'lorem ipsum',
'userjs-mwntestwithpipe': 'with|pipe'
});
await bot.saveOption('userjs-single', 'single');
const options = (await bot.userinfo({
uiprop: ["options"]
})).options;
expect(options).to.have.property('userjs-mwntest').that.equals('lorem ipsum');
expect(options).to.have.property('userjs-mwntestwithpipe').that.equals('with|pipe');
expect(options).to.have.property('userjs-single').that.equals('single');
});

describe('image uploads', function() {

it('successfully upload image from URL', function() {
Expand Down

0 comments on commit 2243cf7

Please sign in to comment.