| 1 | 'use strict'; |
| 2 | |
| 3 | const { action, assert, utils } = require( 'api-testing' ); |
| 4 | |
| 5 | describe( 'The patrol action', () => { |
| 6 | let alice, mindy, edit, rc; |
| 7 | const pageTitle = utils.title( 'Patroll_' ); |
| 8 | |
| 9 | before( async () => { |
| 10 | [ alice, mindy ] = await Promise.all( [ |
| 11 | action.alice(), |
| 12 | action.mindy() |
| 13 | ] ); |
| 14 | } ); |
| 15 | |
| 16 | it( 'doesn\'t allow a users to patrol their own edit', async () => { |
| 17 | edit = await alice.edit( pageTitle, { text: 'One', summary: 'first' } ); |
| 18 | |
| 19 | const error = await alice.actionError( |
| 20 | 'patrol', |
| 21 | { |
| 22 | title: pageTitle, |
| 23 | revid: edit.newrevid, |
| 24 | token: await alice.token( 'patrol' ) |
| 25 | }, |
| 26 | 'POST' |
| 27 | ); |
| 28 | assert.equal( error.code, 'permissiondenied' ); |
| 29 | |
| 30 | rc = await mindy.getChangeEntry( |
| 31 | { |
| 32 | rctitle: pageTitle, |
| 33 | rcprop: 'ids|flags|patrolled' |
| 34 | } |
| 35 | ); |
| 36 | |
| 37 | assert.equal( rc.type, 'new' ); |
| 38 | assert.notExists( rc.autopatrolled ); |
| 39 | assert.notExists( rc.patrolled ); |
| 40 | assert.exists( rc.unpatrolled ); |
| 41 | } ); |
| 42 | |
| 43 | it( 'allows sysops to patrol an edit', async () => { |
| 44 | const result = await mindy.action( |
| 45 | 'patrol', |
| 46 | { |
| 47 | title: pageTitle, |
| 48 | revid: edit.newrevid, |
| 49 | token: await mindy.token( 'patrol' ) |
| 50 | }, |
| 51 | 'POST' |
| 52 | ); |
| 53 | assert.equal( result.patrol.rcid, rc.rcid ); |
| 54 | |
| 55 | rc = ( await mindy.getChangeEntry( |
| 56 | { |
| 57 | rctitle: pageTitle, |
| 58 | rcprop: 'ids|flags|patrolled' |
| 59 | } |
| 60 | ) ); |
| 61 | |
| 62 | assert.equal( rc.type, 'new' ); |
| 63 | assert.exists( rc.patrolled ); |
| 64 | assert.notExists( rc.unpatrolled ); |
| 65 | } ); |
| 66 | |
| 67 | it( 'doesn\'t allow regular users to see the patrol flags', async () => { |
| 68 | const error = await alice.actionError( |
| 69 | 'query', |
| 70 | { |
| 71 | list: 'recentchanges', |
| 72 | rctitle: pageTitle, |
| 73 | rcprop: 'ids|flags|patrolled' |
| 74 | } |
| 75 | ); |
| 76 | |
| 77 | assert.equal( error.code, 'permissiondenied' ); |
| 78 | } ); |
| 79 | } ); |