users.spec.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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('getUserByName', () => {
  28. it('returns user with matching screen_name', () => {
  29. const state = {
  30. users: [
  31. { screen_name: 'Guy', id: '1' }
  32. ]
  33. }
  34. const name = 'Guy'
  35. const expected = { screen_name: 'Guy', id: '1' }
  36. expect(getters.userByName(state)(name)).to.eql(expected)
  37. })
  38. it('returns user with matching screen_name with different case', () => {
  39. const state = {
  40. users: [
  41. { screen_name: 'guy', id: '1' }
  42. ]
  43. }
  44. const name = 'Guy'
  45. const expected = { screen_name: 'guy', id: '1' }
  46. expect(getters.userByName(state)(name)).to.eql(expected)
  47. })
  48. })
  49. describe('getUserById', () => {
  50. it('returns user with matching id', () => {
  51. const state = {
  52. users: [
  53. { screen_name: 'Guy', id: '1' }
  54. ]
  55. }
  56. const id = '1'
  57. const expected = { screen_name: 'Guy', id: '1' }
  58. expect(getters.userById(state)(id)).to.eql(expected)
  59. })
  60. })
  61. })