2016-12-01 04:29:44 +11:00
|
|
|
import { cloneDeep } from 'lodash'
|
|
|
|
|
2018-12-31 12:57:22 +11:00
|
|
|
import { defaultState, mutations, getters } from '../../../../src/modules/users.js'
|
2016-12-01 04:29:44 +11:00
|
|
|
|
|
|
|
describe('The users module', () => {
|
2018-12-31 12:57:22 +11:00
|
|
|
describe('mutations', () => {
|
|
|
|
it('adds new users to the set, merging in new information for old users', () => {
|
|
|
|
const state = cloneDeep(defaultState)
|
2019-01-11 11:38:23 +11:00
|
|
|
const user = { id: '1', name: 'Guy' }
|
|
|
|
const modUser = { id: '1', name: 'Dude' }
|
2018-12-31 12:57:22 +11:00
|
|
|
|
|
|
|
mutations.addNewUsers(state, [user])
|
|
|
|
expect(state.users).to.have.length(1)
|
|
|
|
expect(state.users).to.eql([user])
|
|
|
|
|
|
|
|
mutations.addNewUsers(state, [modUser])
|
|
|
|
expect(state.users).to.have.length(1)
|
|
|
|
expect(state.users).to.eql([user])
|
|
|
|
expect(state.users[0].name).to.eql('Dude')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('sets a mute bit on users', () => {
|
|
|
|
const state = cloneDeep(defaultState)
|
2019-01-11 11:38:23 +11:00
|
|
|
const user = { id: '1', name: 'Guy' }
|
2017-02-14 09:22:32 +11:00
|
|
|
|
2018-12-31 12:57:22 +11:00
|
|
|
mutations.addNewUsers(state, [user])
|
2019-04-08 03:33:11 +10:00
|
|
|
mutations.setMuted(state, { user, muted: true })
|
2017-02-14 09:22:32 +11:00
|
|
|
|
2018-12-31 12:57:22 +11:00
|
|
|
expect(user.muted).to.eql(true)
|
2017-02-14 09:22:32 +11:00
|
|
|
|
2019-04-08 03:33:11 +10:00
|
|
|
mutations.setMuted(state, { user, muted: false })
|
2017-02-14 09:22:32 +11:00
|
|
|
|
2018-12-31 12:57:22 +11:00
|
|
|
expect(user.muted).to.eql(false)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-03-09 11:47:20 +11:00
|
|
|
describe('findUser', () => {
|
2018-12-31 12:57:22 +11:00
|
|
|
it('returns user with matching screen_name', () => {
|
2019-03-09 11:47:20 +11:00
|
|
|
const user = { screen_name: 'Guy', id: '1' }
|
2018-12-31 12:57:22 +11:00
|
|
|
const state = {
|
2019-03-09 11:47:20 +11:00
|
|
|
usersObject: {
|
|
|
|
1: user,
|
2019-03-11 11:17:49 +11:00
|
|
|
guy: user
|
2019-03-09 11:47:20 +11:00
|
|
|
}
|
2018-12-31 12:57:22 +11:00
|
|
|
}
|
|
|
|
const name = 'Guy'
|
2019-01-11 11:38:23 +11:00
|
|
|
const expected = { screen_name: 'Guy', id: '1' }
|
2019-03-09 07:40:57 +11:00
|
|
|
expect(getters.findUser(state)(name)).to.eql(expected)
|
2018-12-31 12:57:22 +11:00
|
|
|
})
|
2019-01-29 06:21:11 +11:00
|
|
|
|
2018-12-31 12:57:22 +11:00
|
|
|
it('returns user with matching id', () => {
|
2019-03-09 11:47:20 +11:00
|
|
|
const user = { screen_name: 'Guy', id: '1' }
|
2018-12-31 12:57:22 +11:00
|
|
|
const state = {
|
2019-03-09 11:47:20 +11:00
|
|
|
usersObject: {
|
|
|
|
1: user,
|
2019-03-11 11:17:49 +11:00
|
|
|
guy: user
|
2019-03-09 11:47:20 +11:00
|
|
|
}
|
2018-12-31 12:57:22 +11:00
|
|
|
}
|
2019-01-11 11:38:23 +11:00
|
|
|
const id = '1'
|
|
|
|
const expected = { screen_name: 'Guy', id: '1' }
|
2019-03-09 07:40:57 +11:00
|
|
|
expect(getters.findUser(state)(id)).to.eql(expected)
|
2018-12-31 12:57:22 +11:00
|
|
|
})
|
2017-02-14 09:22:32 +11:00
|
|
|
})
|
2016-12-01 04:29:44 +11:00
|
|
|
})
|