-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9307b0f
commit be030bb
Showing
2 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
'use strict'; | ||
|
||
const { bot, expect, loginBefore, logoutAfter} = require('./test_base'); | ||
|
||
|
||
describe('bot emergency shutoff', async function() { | ||
this.timeout(10000); | ||
|
||
before('logs in and gets token & namespaceInfo', loginBefore); | ||
after('logs out', logoutAfter); | ||
|
||
it('set shutoff=true on non-matching regex', async function () { | ||
bot.enableEmergencyShutoff({ | ||
page: 'SD0001test', | ||
intervalDuration: 1000, | ||
condition: /^\s*$/ | ||
}); | ||
await bot.save('SD0001test', 'shutoff', 'Testing bot shutoff (mwn)'); | ||
await bot.sleep(1500); // wait till we can be sure that shutoff check is queried | ||
expect(bot.shutoff.state).to.equal(true); | ||
bot.disableEmergencyShutoff(); | ||
}); | ||
|
||
it('set shutoff=true on condition function returns falsy value', async function () { | ||
bot.shutoff.state = false; // restore to default state | ||
|
||
bot.enableEmergencyShutoff({ | ||
page: 'SD0001test', | ||
intervalDuration: 1000, | ||
condition: function () { | ||
return false; // function returns false means bot would shut down | ||
} | ||
}); | ||
await bot.sleep(1500); // wait till we can be sure that shutoff check is queried | ||
expect(bot.shutoff.state).to.equal(true); | ||
bot.disableEmergencyShutoff(); | ||
}); | ||
|
||
it ('sets shutoff=true even if shutoff options are not configured in function', async function () { | ||
bot.shutoff.state = false; // restore to default state | ||
|
||
bot.options.shutoff.page = 'SD0001test'; | ||
bot.options.shutoff.intervalDuration = 1000; | ||
bot.options.shutoff.condition = /^\s*$/; | ||
bot.enableEmergencyShutoff(); | ||
await bot.save('SD0001test', 'shutoff', 'Testing bot shutoff (mwn)'); | ||
await bot.sleep(1500); // wait till we can be sure that shutoff check is queried | ||
expect(bot.shutoff.state).to.equal(true); | ||
bot.disableEmergencyShutoff(); | ||
}); | ||
|
||
it('refuses to do API requests when shut off', function () { | ||
bot.shutoff.state = true; | ||
return bot.request({action: 'query', titles: 'testtitle'}) | ||
.then(() => { | ||
expect(true).to.equal(false); // should never execute | ||
}, (err) => { | ||
expect(err.code).to.equal('bot-shutoff'); | ||
}); | ||
}); | ||
|
||
}); |