Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4095334
Rollback.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
6 KB
Referenced Files
None
Subscribers
None
Rollback.js
View Options
'use strict'
;
const
{
action
,
assert
,
utils
,
wiki
}
=
require
(
'api-testing'
);
describe
(
'The rollback action'
,
()
=>
{
let
alice
,
bob
,
mindy
;
before
(
async
()
=>
{
[
alice
,
bob
,
mindy
]
=
await
Promise
.
all
(
[
action
.
alice
(),
action
.
bob
(),
action
.
mindy
()
]
);
}
);
it
(
'rolls back consecutive edits'
,
async
()
=>
{
const
title
=
utils
.
title
(
'Rollback_'
);
const
edits
=
{};
edits
.
alice1
=
await
alice
.
edit
(
title
,
{
text
:
'One'
,
summary
:
'first'
}
);
edits
.
bob2
=
await
bob
.
edit
(
title
,
{
text
:
'Two'
,
summary
:
'second'
}
);
edits
.
alice3
=
await
alice
.
edit
(
title
,
{
text
:
'Three'
,
summary
:
'third'
}
);
edits
.
bob4
=
await
bob
.
edit
(
title
,
{
text
:
'Four'
,
summary
:
'fourth'
}
);
edits
.
bob5
=
await
bob
.
edit
(
title
,
{
text
:
'Five'
,
summary
:
'fifth'
}
);
const
result
=
await
mindy
.
action
(
'rollback'
,
{
title
,
user
:
bob
.
username
,
summary
:
'revert vandalism'
,
token
:
await
mindy
.
token
(
'rollback'
)
},
'POST'
);
assert
.
sameTitle
(
result
.
rollback
.
title
,
title
);
assert
.
equal
(
result
.
rollback
.
old_revid
,
edits
.
bob5
.
newrevid
);
assert
.
equal
(
result
.
rollback
.
last_revid
,
edits
.
alice3
.
newrevid
);
const
rev
=
await
mindy
.
getRevision
(
title
);
assert
.
equal
(
rev
.
revid
,
result
.
rollback
.
revid
);
assert
.
equal
(
rev
.
slots
.
main
[
'*'
],
'Three'
);
assert
.
equal
(
rev
.
user
,
mindy
.
username
);
}
);
it
(
'doesn\'t roll back edits by another user'
,
async
()
=>
{
const
title
=
utils
.
title
(
'Rollback_'
);
await
alice
.
edit
(
title
,
{
text
:
'One'
,
summary
:
'first'
}
);
await
bob
.
edit
(
title
,
{
text
:
'Two'
,
summary
:
'second'
}
);
await
alice
.
edit
(
title
,
{
text
:
'Three'
,
summary
:
'third'
}
);
const
error
=
await
mindy
.
actionError
(
'rollback'
,
{
title
,
user
:
bob
.
username
,
summary
:
'revert vandalism'
,
token
:
await
mindy
.
token
(
'rollback'
)
},
'POST'
);
assert
.
equal
(
error
.
code
,
'alreadyrolled'
);
}
);
it
(
'doesn\'t allow a regular user to roll back edits'
,
async
()
=>
{
const
title
=
utils
.
title
(
'Rollback_'
);
await
alice
.
edit
(
title
,
{
text
:
'One'
,
summary
:
'first'
}
);
await
bob
.
edit
(
title
,
{
text
:
'Two'
,
summary
:
'second'
}
);
const
error
=
await
alice
.
actionError
(
'rollback'
,
{
title
,
user
:
bob
.
username
,
summary
:
'revert vandalism'
,
token
:
await
alice
.
token
(
'rollback'
)
},
'POST'
);
assert
.
equal
(
error
.
code
,
'permissiondenied'
);
}
);
it
(
'should undo the last edit on the page using the pageid parameter'
,
async
()
=>
{
const
title
=
utils
.
title
(
'Rollback_'
);
const
firstEdit
=
await
alice
.
edit
(
title
,
{
text
:
'One'
,
summary
:
'first'
}
);
const
secondEdit
=
await
bob
.
edit
(
title
,
{
text
:
'Two'
,
summary
:
'second'
}
);
const
result
=
await
mindy
.
action
(
'rollback'
,
{
pageid
:
firstEdit
.
pageid
,
user
:
bob
.
username
,
summary
:
'revert'
,
token
:
await
mindy
.
token
(
'rollback'
)
},
'POST'
);
const
rev
=
await
mindy
.
getRevision
(
title
);
assert
.
sameTitle
(
result
.
rollback
.
title
,
title
);
assert
.
equal
(
result
.
rollback
.
old_revid
,
secondEdit
.
newrevid
);
assert
.
equal
(
rev
.
revid
,
result
.
rollback
.
revid
);
}
);
it
(
'should throw an error with code missingparam when neither pageid nor title is provided for a rollback action'
,
async
()
=>
{
const
title
=
utils
.
title
(
'Rollback_'
);
await
alice
.
edit
(
title
,
{
text
:
'One'
,
summary
:
'first'
}
);
await
bob
.
edit
(
title
,
{
text
:
'Two'
,
summary
:
'second'
}
);
const
error
=
await
mindy
.
actionError
(
'rollback'
,
{
user
:
bob
.
username
,
summary
:
'revert'
,
token
:
await
mindy
.
token
(
'rollback'
)
},
'POST'
);
assert
.
equal
(
error
.
code
,
'missingparam'
);
}
);
it
(
'should throw an error with code notoken when the token parameter is not provided for a rollback action'
,
async
()
=>
{
const
title
=
utils
.
title
(
'Rollback_'
);
await
alice
.
edit
(
title
,
{
text
:
'One'
,
summary
:
'first'
}
);
await
bob
.
edit
(
title
,
{
text
:
'Two'
,
summary
:
'second'
}
);
const
error
=
await
mindy
.
actionError
(
'rollback'
,
{
title
:
title
,
user
:
bob
.
username
,
summary
:
'revert'
},
'POST'
);
assert
.
equal
(
error
.
code
,
'missingparam'
);
}
);
it
(
'should throw an error with code nouser when a user is not provided for a rollback action'
,
async
()
=>
{
const
title
=
utils
.
title
(
'Rollback_'
);
await
alice
.
edit
(
title
,
{
text
:
'One'
,
summary
:
'first'
}
);
await
bob
.
edit
(
title
,
{
text
:
'Two'
,
summary
:
'second'
}
);
const
error
=
await
mindy
.
actionError
(
'rollback'
,
{
title
:
title
,
summary
:
'revert'
,
token
:
await
mindy
.
token
(
'rollback'
)
},
'POST'
);
assert
.
equal
(
error
.
code
,
'missingparam'
);
}
);
it
(
'should throw an error with code onlyauthor if the page has only one author'
,
async
()
=>
{
const
title
=
utils
.
title
(
'Rollback_'
);
await
alice
.
edit
(
title
,
{
text
:
'One'
,
summary
:
'first'
}
);
const
error
=
await
mindy
.
actionError
(
'rollback'
,
{
title
:
title
,
user
:
alice
.
username
,
summary
:
'revert'
,
token
:
await
mindy
.
token
(
'rollback'
)
},
'POST'
);
assert
.
equal
(
error
.
code
,
'onlyauthor'
);
}
);
it
(
'should throw an error with code mustpostparams when the request to the API is not a post request'
,
async
()
=>
{
const
title
=
utils
.
title
(
'Rollback_'
);
await
alice
.
edit
(
title
,
{
text
:
'One'
,
summary
:
'first'
}
);
await
bob
.
edit
(
title
,
{
text
:
'Two'
,
summary
:
'second'
}
);
const
error
=
await
mindy
.
actionError
(
'rollback'
,
{
title
:
title
,
user
:
bob
.
username
,
summary
:
'revert'
,
token
:
await
mindy
.
token
(
'rollback'
)
}
);
assert
.
equal
(
error
.
code
,
'mustpostparams'
);
}
);
it
(
'should mark the revert as a bot edit'
,
async
()
=>
{
const
title
=
utils
.
title
(
'Rollback_'
);
const
firstEdit
=
await
alice
.
edit
(
title
,
{
text
:
'One'
,
summary
:
'first'
}
);
const
secondEdit
=
await
bob
.
edit
(
title
,
{
text
:
'Two'
,
summary
:
'second'
}
);
const
result
=
await
mindy
.
action
(
'rollback'
,
{
pageid
:
firstEdit
.
pageid
,
user
:
bob
.
username
,
summary
:
'revert'
,
markbot
:
true
,
token
:
await
mindy
.
token
(
'rollback'
)
},
'POST'
);
await
wiki
.
runAllJobs
();
const
recentChanges
=
await
mindy
.
getChangeEntry
(
{
rctitle
:
title
}
);
assert
.
exists
(
recentChanges
.
bot
);
assert
.
sameTitle
(
result
.
rollback
.
title
,
title
);
assert
.
equal
(
result
.
rollback
.
old_revid
,
secondEdit
.
newrevid
);
assert
.
equal
(
recentChanges
.
revid
,
result
.
rollback
.
revid
);
}
);
}
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Aug 18, 13:49 (4 w, 11 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
cb/22/f5697cdde9d35d28e253ff5f7e93
Default Alt Text
Rollback.js (6 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment