| 1 | 'use strict'; |
| 2 | |
| 3 | const { action, assert } = require( 'api-testing' ); |
| 4 | |
| 5 | describe( 'Block', () => { |
| 6 | const ip = '::' + Math.floor( Math.random() * 65534 ).toString( 16 ); |
| 7 | it( 'should not allow multiblocks without newblock (T389028)', async () => { |
| 8 | const mindy = await action.mindy(); |
| 9 | const token = await mindy.token(); |
| 10 | const promises = [ |
| 11 | mindy.request( { action: 'block', user: ip, token: token }, 'POST' ), |
| 12 | mindy.request( { action: 'block', user: ip, token: token }, 'POST' ) |
| 13 | ]; |
| 14 | const res = await Promise.all( promises ); |
| 15 | assert.lengthOf( res, 2 ); |
| 16 | assert.equal( res[ 0 ].status, 200 ); |
| 17 | assert.equal( res[ 1 ].status, 200 ); |
| 18 | |
| 19 | const goodIndex = 'block' in res[ 0 ].body ? 0 : 1; |
| 20 | const goodBody = res[ goodIndex ].body; |
| 21 | const badBody = res[ +!goodIndex ].body; |
| 22 | |
| 23 | assert.property( goodBody, 'block' ); |
| 24 | assert.isOk( goodBody.block.id ); |
| 25 | |
| 26 | assert.property( badBody, 'error' ); |
| 27 | assert.equal( badBody.error.code, 'alreadyblocked' ); |
| 28 | } ); |
| 29 | } ); |