2016-11-30 17:29:44 +00:00
|
|
|
import { cloneDeep } from 'lodash'
|
|
|
|
|
2018-12-31 01:57:22 +00:00
|
|
|
import { defaultState, mutations, getters } from '../../../../src/modules/users.js'
|
2016-11-30 17:29:44 +00:00
|
|
|
|
|
|
|
describe('The users module', () => {
|
2018-12-31 01:57:22 +00:00
|
|
|
describe('mutations', () => {
|
|
|
|
it('adds new users to the set, merging in new information for old users', () => {
|
|
|
|
const state = cloneDeep(defaultState)
|
2019-01-11 00:38:23 +00:00
|
|
|
const user = { id: '1', name: 'Guy' }
|
|
|
|
const modUser = { id: '1', name: 'Dude' }
|
2018-12-31 01:57:22 +00: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')
|
|
|
|
})
|
2019-11-17 13:34:00 +00:00
|
|
|
|
|
|
|
it('merging array field in new information for old users', () => {
|
|
|
|
const state = cloneDeep(defaultState)
|
|
|
|
const user = {
|
|
|
|
id: '1',
|
|
|
|
fields: [
|
|
|
|
{ name: 'Label 1', value: 'Content 1' }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
const firstModUser = {
|
|
|
|
id: '1',
|
|
|
|
fields: [
|
|
|
|
{ name: 'Label 2', value: 'Content 2' },
|
|
|
|
{ name: 'Label 3', value: 'Content 3' }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
const secondModUser = {
|
|
|
|
id: '1',
|
|
|
|
fields: [
|
|
|
|
{ name: 'Label 4', value: 'Content 4' }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
mutations.addNewUsers(state, [user])
|
|
|
|
expect(state.users[0].fields).to.have.length(1)
|
|
|
|
expect(state.users[0].fields[0].name).to.eql('Label 1')
|
|
|
|
|
|
|
|
mutations.addNewUsers(state, [firstModUser])
|
|
|
|
expect(state.users[0].fields).to.have.length(2)
|
|
|
|
expect(state.users[0].fields[0].name).to.eql('Label 2')
|
|
|
|
expect(state.users[0].fields[1].name).to.eql('Label 3')
|
|
|
|
|
|
|
|
mutations.addNewUsers(state, [secondModUser])
|
|
|
|
expect(state.users[0].fields).to.have.length(1)
|
|
|
|
expect(state.users[0].fields[0].name).to.eql('Label 4')
|
|
|
|
})
|
2018-12-31 01:57:22 +00:00
|
|
|
})
|
|
|
|
|
2019-03-09 00:47:20 +00:00
|
|
|
describe('findUser', () => {
|
2022-08-10 16:17:18 +00:00
|
|
|
it('does not return user with matching screen_name', () => {
|
2019-03-09 00:47:20 +00:00
|
|
|
const user = { screen_name: 'Guy', id: '1' }
|
2018-12-31 01:57:22 +00:00
|
|
|
const state = {
|
2019-03-09 00:47:20 +00:00
|
|
|
usersObject: {
|
2022-08-10 16:17:18 +00:00
|
|
|
1: user
|
|
|
|
},
|
|
|
|
usersByNameObject: {
|
2019-03-11 00:17:49 +00:00
|
|
|
guy: user
|
2019-03-09 00:47:20 +00:00
|
|
|
}
|
2018-12-31 01:57:22 +00:00
|
|
|
}
|
|
|
|
const name = 'Guy'
|
2022-08-10 16:17:18 +00:00
|
|
|
expect(getters.findUser(state)(name)).to.eql(undefined)
|
2018-12-31 01:57:22 +00:00
|
|
|
})
|
2019-01-28 19:21:11 +00:00
|
|
|
|
2018-12-31 01:57:22 +00:00
|
|
|
it('returns user with matching id', () => {
|
2019-03-09 00:47:20 +00:00
|
|
|
const user = { screen_name: 'Guy', id: '1' }
|
2018-12-31 01:57:22 +00:00
|
|
|
const state = {
|
2019-03-09 00:47:20 +00:00
|
|
|
usersObject: {
|
2022-08-10 16:17:18 +00:00
|
|
|
1: user
|
|
|
|
},
|
|
|
|
usersByNameObject: {
|
2019-03-11 00:17:49 +00:00
|
|
|
guy: user
|
2019-03-09 00:47:20 +00:00
|
|
|
}
|
2018-12-31 01:57:22 +00:00
|
|
|
}
|
2019-01-11 00:38:23 +00:00
|
|
|
const id = '1'
|
|
|
|
const expected = { screen_name: 'Guy', id: '1' }
|
2019-03-08 20:40:57 +00:00
|
|
|
expect(getters.findUser(state)(id)).to.eql(expected)
|
2018-12-31 01:57:22 +00:00
|
|
|
})
|
2017-02-13 22:22:32 +00:00
|
|
|
})
|
2022-08-10 16:17:18 +00:00
|
|
|
|
|
|
|
describe('findUserByName', () => {
|
|
|
|
it('returns user with matching screen_name', () => {
|
|
|
|
const user = { screen_name: 'Guy', id: '1' }
|
|
|
|
const state = {
|
|
|
|
usersObject: {
|
|
|
|
1: user
|
|
|
|
},
|
|
|
|
usersByNameObject: {
|
|
|
|
guy: user
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const name = 'Guy'
|
|
|
|
const expected = { screen_name: 'Guy', id: '1' }
|
|
|
|
expect(getters.findUserByName(state)(name)).to.eql(expected)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('does not return user with matching id', () => {
|
|
|
|
const user = { screen_name: 'Guy', id: '1' }
|
|
|
|
const state = {
|
|
|
|
usersObject: {
|
|
|
|
1: user
|
|
|
|
},
|
|
|
|
usersByNameObject: {
|
|
|
|
guy: user
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const id = '1'
|
|
|
|
expect(getters.findUserByName(state)(id)).to.eql(undefined)
|
|
|
|
})
|
|
|
|
})
|
2016-11-30 17:29:44 +00:00
|
|
|
})
|