users.spec.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { cloneDeep } from 'lodash'
  2. import { defaultState, mutations, getters } from '../../../../src/modules/users.js'
  3. describe('The users module', () => {
  4. describe('mutations', () => {
  5. it('adds new users to the set, merging in new information for old users', () => {
  6. const state = cloneDeep(defaultState)
  7. const user = { id: '1', name: 'Guy' }
  8. const modUser = { id: '1', name: 'Dude' }
  9. mutations.addNewUsers(state, [user])
  10. expect(state.users).to.have.length(1)
  11. expect(state.users).to.eql([user])
  12. mutations.addNewUsers(state, [modUser])
  13. expect(state.users).to.have.length(1)
  14. expect(state.users).to.eql([user])
  15. expect(state.users[0].name).to.eql('Dude')
  16. })
  17. it('sets a mute bit on users', () => {
  18. const state = cloneDeep(defaultState)
  19. const user = { id: '1', name: 'Guy' }
  20. mutations.addNewUsers(state, [user])
  21. mutations.setMuted(state, { user, muted: true })
  22. expect(user.muted).to.eql(true)
  23. mutations.setMuted(state, { user, muted: false })
  24. expect(user.muted).to.eql(false)
  25. })
  26. })
  27. describe('findUser', () => {
  28. it('returns user with matching screen_name', () => {
  29. const user = { screen_name: 'Guy', id: '1' }
  30. const state = {
  31. usersObject: {
  32. 1: user,
  33. guy: user
  34. }
  35. }
  36. const name = 'Guy'
  37. const expected = { screen_name: 'Guy', id: '1' }
  38. expect(getters.findUser(state)(name)).to.eql(expected)
  39. })
  40. it('returns user with matching id', () => {
  41. const user = { screen_name: 'Guy', id: '1' }
  42. const state = {
  43. usersObject: {
  44. 1: user,
  45. guy: user
  46. }
  47. }
  48. const id = '1'
  49. const expected = { screen_name: 'Guy', id: '1' }
  50. expect(getters.findUser(state)(id)).to.eql(expected)
  51. })
  52. })
  53. })