Debian Codegraph @

tests/api-testing/action/Rollback.js

raw symbols SCIP
1 'use strict';
2
3 const { action, assert, utils, wiki } = require( 'api-testing' );
4
5 describe( 'The rollback action', () => {
6 let alice, bob, mindy;
7
8 before( async () => {
9 [ alice, bob, mindy ] = await Promise.all( [
10 action.alice(),
11 action.bob(),
12 action.mindy()
13 ] );
14 } );
15
16 it( 'rolls back consecutive edits', async () => {
17 const title = utils.title( 'Rollback_' );
18 const edits = {};
19
20 edits.alice1 = await alice.edit( title, { text: 'One', summary: 'first' } );
21 edits.bob2 = await bob.edit( title, { text: 'Two', summary: 'second' } );
22 edits.alice3 = await alice.edit( title, { text: 'Three', summary: 'third' } );
23 edits.bob4 = await bob.edit( title, { text: 'Four', summary: 'fourth' } );
24 edits.bob5 = await bob.edit( title, { text: 'Five', summary: 'fifth' } );
25
26 const result = await mindy.action( 'rollback', {
27 title,
28 user: bob.username,
29 summary: 'revert vandalism',
30 token: await mindy.token( 'rollback' )
31 }, 'POST' );
32
33 assert.sameTitle( result.rollback.title, title );
34 assert.equal( result.rollback.old_revid, edits.bob5.newrevid );
35 assert.equal( result.rollback.last_revid, edits.alice3.newrevid );
36
37 const rev = await mindy.getRevision( title );
38 assert.equal( rev.revid, result.rollback.revid );
39 assert.equal( rev.slots.main[ '*' ], 'Three' );
40 assert.equal( rev.user, mindy.username );
41 } );
42
43 it( 'doesn\'t roll back edits by another user', async () => {
44 const title = utils.title( 'Rollback_' );
45
46 await alice.edit( title, { text: 'One', summary: 'first' } );
47 await bob.edit( title, { text: 'Two', summary: 'second' } );
48 await alice.edit( title, { text: 'Three', summary: 'third' } );
49
50 const error = await mindy.actionError( 'rollback', {
51 title,
52 user: bob.username,
53 summary: 'revert vandalism',
54 token: await mindy.token( 'rollback' )
55 }, 'POST' );
56
57 assert.equal( error.code, 'alreadyrolled' );
58 } );
59
60 it( 'doesn\'t allow a regular user to roll back edits', async () => {
61 const title = utils.title( 'Rollback_' );
62
63 await alice.edit( title, { text: 'One', summary: 'first' } );
64 await bob.edit( title, { text: 'Two', summary: 'second' } );
65
66 const error = await alice.actionError( 'rollback', {
67 title,
68 user: bob.username,
69 summary: 'revert vandalism',
70 token: await alice.token( 'rollback' )
71 }, 'POST' );
72
73 assert.equal( error.code, 'permissiondenied' );
74 } );
75
76 it( 'should undo the last edit on the page using the pageid parameter', async () => {
77 const title = utils.title( 'Rollback_' );
78
79 const firstEdit = await alice.edit( title, { text: 'One', summary: 'first' } );
80 const secondEdit = await bob.edit( title, { text: 'Two', summary: 'second' } );
81
82 const result = await mindy.action( 'rollback', {
83 pageid: firstEdit.pageid,
84 user: bob.username,
85 summary: 'revert',
86 token: await mindy.token( 'rollback' )
87 }, 'POST' );
88
89 const rev = await mindy.getRevision( title );
90
91 assert.sameTitle( result.rollback.title, title );
92 assert.equal( result.rollback.old_revid, secondEdit.newrevid );
93 assert.equal( rev.revid, result.rollback.revid );
94 } );
95
96 it( 'should throw an error with code missingparam when neither pageid nor title is provided for a rollback action', async () => {
97 const title = utils.title( 'Rollback_' );
98
99 await alice.edit( title, { text: 'One', summary: 'first' } );
100 await bob.edit( title, { text: 'Two', summary: 'second' } );
101
102 const error = await mindy.actionError( 'rollback', {
103 user: bob.username,
104 summary: 'revert',
105 token: await mindy.token( 'rollback' )
106 }, 'POST' );
107
108 assert.equal( error.code, 'missingparam' );
109 } );
110
111 it( 'should throw an error with code notoken when the token parameter is not provided for a rollback action', async () => {
112 const title = utils.title( 'Rollback_' );
113
114 await alice.edit( title, { text: 'One', summary: 'first' } );
115 await bob.edit( title, { text: 'Two', summary: 'second' } );
116
117 const error = await mindy.actionError( 'rollback', {
118 title: title,
119 user: bob.username,
120 summary: 'revert'
121 }, 'POST' );
122
123 assert.equal( error.code, 'missingparam' );
124 } );
125
126 it( 'should throw an error with code nouser when a user is not provided for a rollback action', async () => {
127 const title = utils.title( 'Rollback_' );
128
129 await alice.edit( title, { text: 'One', summary: 'first' } );
130 await bob.edit( title, { text: 'Two', summary: 'second' } );
131
132 const error = await mindy.actionError( 'rollback', {
133 title: title,
134 summary: 'revert',
135 token: await mindy.token( 'rollback' )
136 }, 'POST' );
137
138 assert.equal( error.code, 'missingparam' );
139 } );
140
141 it( 'should throw an error with code onlyauthor if the page has only one author', async () => {
142 const title = utils.title( 'Rollback_' );
143
144 await alice.edit( title, { text: 'One', summary: 'first' } );
145
146 const error = await mindy.actionError( 'rollback', {
147 title: title,
148 user: alice.username,
149 summary: 'revert',
150 token: await mindy.token( 'rollback' )
151 }, 'POST' );
152
153 assert.equal( error.code, 'onlyauthor' );
154 } );
155
156 it( 'should throw an error with code mustpostparams when the request to the API is not a post request', async () => {
157 const title = utils.title( 'Rollback_' );
158
159 await alice.edit( title, { text: 'One', summary: 'first' } );
160 await bob.edit( title, { text: 'Two', summary: 'second' } );
161
162 const error = await mindy.actionError( 'rollback', {
163 title: title,
164 user: bob.username,
165 summary: 'revert',
166 token: await mindy.token( 'rollback' )
167 } );
168
169 assert.equal( error.code, 'mustpostparams' );
170 } );
171
172 it( 'should mark the revert as a bot edit', async () => {
173 const title = utils.title( 'Rollback_' );
174
175 const firstEdit = await alice.edit( title, { text: 'One', summary: 'first' } );
176 const secondEdit = await bob.edit( title, { text: 'Two', summary: 'second' } );
177
178 const result = await mindy.action( 'rollback', {
179 pageid: firstEdit.pageid,
180 user: bob.username,
181 summary: 'revert',
182 markbot: true,
183 token: await mindy.token( 'rollback' )
184 }, 'POST' );
185
186 await wiki.runAllJobs();
187
188 const recentChanges = await mindy.getChangeEntry( { rctitle: title } );
189
190 assert.exists( recentChanges.bot );
191 assert.sameTitle( result.rollback.title, title );
192 assert.equal( result.rollback.old_revid, secondEdit.newrevid );
193 assert.equal( recentChanges.revid, result.rollback.revid );
194 } );
195 } );