Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with getArticleInfo #332

Merged
merged 1 commit into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions lib/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,25 +471,27 @@ Bot.prototype = {
const params = {
action: 'query',
prop: 'info',
inprop: options.inprop.join( '|' )
inprop: options.inprop.join( '|' ),
titles: []
};
if ( options.intestactions.length !== 0 ) {

const titles = [];
if ( options.intestactions && options.intestactions.length !== 0 ) {
params.intestactions = options.intestactions.join( '|' );
}
if ( typeof title === 'string' ) {
title.push( title );
titles.push( title );
}
if ( typeof title === 'number' ) {
title.push( title );
titles.push( title );
}
if ( typeof title === 'object' ) {
let objTitle = title;
title = [];
for ( let key in objTitle ) {
title.push( objTitle[ key ] );
titles.push( objTitle[ key ] );
}
}
title.forEach( ( t ) => {
titles.forEach( ( t ) => {
if ( typeof t === 'string' ) {
params.titles.push( t );
}
Expand All @@ -502,7 +504,7 @@ Bot.prototype = {
params,
function ( batch ) {
const page = getFirstItem( batch.pages );
return page.revisions;
return page;
},
callback
);
Expand Down
15 changes: 15 additions & 0 deletions test/mediawiki-api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ vows.describe( 'Mediawiki API' ).addBatch( {
assert.equal( redirectInfo.from, 'Einstein' );
}
},
'getArticleInfo()': {
topic: function () {
client.getArticleInfo( ARTICLE, this.callback );
},
'valid content is passed to callback': function ( e, res ) {
assert.isArray( res );
assert.isTrue( res.length === 1 );

const data = res[ 0 ];
assert.isNumber( data.pageid );
assert.isString( data.title );
assert.isArray( data.protection );
assert.isTrue( data.title.includes( 'Albert Einstein' ) );
}
},
Comment on lines +88 to +102
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding a test case!

'getImagesFromArticle()': {
topic: function () {
client.getImagesFromArticle( ARTICLE, this.callback );
Expand Down