Offer AFCH.consts.mockItUp for mocking requests, useful for development

This commit is contained in:
theopolisme 2014-03-05 01:07:52 -06:00
parent be2da65d1e
commit 7e9538848f
2 changed files with 17 additions and 0 deletions

View File

@ -19,6 +19,8 @@ Your contributions are welcome! Please add feature requests and bug reports as n
If you'd like to contribute directly to the code, that's great too! In order to maintain great code quality, please submit significant changes using pull requests so that a consistent code style can be maintained throughout the project. If you'd like to contribute directly to the code, that's great too! In order to maintain great code quality, please submit significant changes using pull requests so that a consistent code style can be maintained throughout the project.
**Protip for developers**: Set `AFCH.consts.mockItUp = true;` using your browser console and instead of making API requests which modify wiki content, the script will log what it *would have done* instead.
### Version history ### Version history
* 0.2 Egalitarian Elephant * 0.2 Egalitarian Elephant

View File

@ -41,6 +41,9 @@
// Add more constants // Add more constants
$.extend( AFCH.consts, { $.extend( AFCH.consts, {
// If true, the script will NOT modify actual wiki content and
// will instead mock all such API requests (success assumed)
mockItUp: false,
// Edit token used in api requests // Edit token used in api requests
editToken: mw.user.tokens.get( 'editToken' ), editToken: mw.user.tokens.get( 'editToken' ),
// Full page name, "Wikipedia talk:Articles for creation/sandbox" // Full page name, "Wikipedia talk:Articles for creation/sandbox"
@ -363,6 +366,12 @@
request[options.mode] = options.contents; request[options.mode] = options.contents;
} }
if ( AFCH.consts.mockItUp ) {
AFCH.log( request );
deferred.resolve();
return deferred;
}
AFCH.api.post( request ) AFCH.api.post( request )
.done( function ( data ) { .done( function ( data ) {
if ( data && data.edit && data.edit.result && data.edit.result === 'Success' ) { if ( data && data.edit && data.edit.result && data.edit.result === 'Success' ) {
@ -422,6 +431,12 @@
token: AFCH.consts.editToken // Move token === edit token token: AFCH.consts.editToken // Move token === edit token
}, additionalParameters ); }, additionalParameters );
if ( AFCH.consts.mockItUp ) {
AFCH.log( request );
deferred.resolve( { to: newTitle } );
return deferred;
}
AFCH.api.post( request ) AFCH.api.post( request )
.done( function ( data ) { .done( function ( data ) {
if ( data && data.move ) { if ( data && data.move ) {