| 1 | 'use strict'; |
| 2 | |
| 3 | const { action, assert } = require( 'api-testing' ); |
| 4 | |
| 5 | describe( "Changing a user's preferences", () => { |
| 6 | let alice; |
| 7 | let token; |
| 8 | |
| 9 | before( async () => { |
| 10 | alice = await action.alice(); |
| 11 | token = await alice.token(); |
| 12 | } ); |
| 13 | |
| 14 | it( 'should get users default date settings', async () => { |
| 15 | const info = await alice.meta( 'userinfo', { uiprop: 'options' } ); |
| 16 | assert.equal( info.options.date, 'default' ); |
| 17 | } ); |
| 18 | |
| 19 | it( 'should change date preference from default to dmy', async () => { |
| 20 | const result = await alice.action( 'options', { change: 'date=dmy', token }, 'POST' ); |
| 21 | |
| 22 | assert.equal( result.options, 'success' ); |
| 23 | } ); |
| 24 | |
| 25 | it( 'should get users updated date preference', async () => { |
| 26 | const info = await alice.meta( 'userinfo', { uiprop: 'options' } ); |
| 27 | assert.equal( info.options.date, 'dmy' ); |
| 28 | } ); |
| 29 | |
| 30 | it( 'should allow arbitrary userjs option', async () => { |
| 31 | const result = await alice.action( 'options', { |
| 32 | change: 'userjs-api-test=Hello World', |
| 33 | token |
| 34 | }, 'POST' ); |
| 35 | assert.equal( result.options, 'success' ); |
| 36 | |
| 37 | const info = await alice.meta( 'userinfo', { uiprop: 'options' } ); |
| 38 | assert.equal( info.options[ 'userjs-api-test' ], 'Hello World' ); |
| 39 | } ); |
| 40 | |
| 41 | it( 'should not be able to set arbitrary option', async () => { |
| 42 | await alice.action( 'options', { |
| 43 | change: 'api-test-yadda=Hello World', |
| 44 | token |
| 45 | }, 'POST' ); |
| 46 | |
| 47 | const info = await alice.meta( 'userinfo', { uiprop: 'options' } ); |
| 48 | assert.notProperty( info.options, 'api-test-yadda' ); |
| 49 | } ); |
| 50 | |
| 51 | } ); |