users.spec.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. })
  18. describe('findUser', () => {
  19. it('returns user with matching screen_name', () => {
  20. const user = { screen_name: 'Guy', id: '1' }
  21. const state = {
  22. usersObject: {
  23. 1: user,
  24. guy: user
  25. }
  26. }
  27. const name = 'Guy'
  28. const expected = { screen_name: 'Guy', id: '1' }
  29. expect(getters.findUser(state)(name)).to.eql(expected)
  30. })
  31. it('returns user with matching id', () => {
  32. const user = { screen_name: 'Guy', id: '1' }
  33. const state = {
  34. usersObject: {
  35. 1: user,
  36. guy: user
  37. }
  38. }
  39. const id = '1'
  40. const expected = { screen_name: 'Guy', id: '1' }
  41. expect(getters.findUser(state)(id)).to.eql(expected)
  42. })
  43. })
  44. })