logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

users.spec.js (3419B)


  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('merging array field in new information for old users', () => {
  18. const state = cloneDeep(defaultState)
  19. const user = {
  20. id: '1',
  21. fields: [
  22. { name: 'Label 1', value: 'Content 1' }
  23. ]
  24. }
  25. const firstModUser = {
  26. id: '1',
  27. fields: [
  28. { name: 'Label 2', value: 'Content 2' },
  29. { name: 'Label 3', value: 'Content 3' }
  30. ]
  31. }
  32. const secondModUser = {
  33. id: '1',
  34. fields: [
  35. { name: 'Label 4', value: 'Content 4' }
  36. ]
  37. }
  38. mutations.addNewUsers(state, [user])
  39. expect(state.users[0].fields).to.have.length(1)
  40. expect(state.users[0].fields[0].name).to.eql('Label 1')
  41. mutations.addNewUsers(state, [firstModUser])
  42. expect(state.users[0].fields).to.have.length(2)
  43. expect(state.users[0].fields[0].name).to.eql('Label 2')
  44. expect(state.users[0].fields[1].name).to.eql('Label 3')
  45. mutations.addNewUsers(state, [secondModUser])
  46. expect(state.users[0].fields).to.have.length(1)
  47. expect(state.users[0].fields[0].name).to.eql('Label 4')
  48. })
  49. })
  50. describe('findUser', () => {
  51. it('does not return user with matching screen_name', () => {
  52. const user = { screen_name: 'Guy', id: '1' }
  53. const state = {
  54. usersObject: {
  55. 1: user
  56. },
  57. usersByNameObject: {
  58. guy: user
  59. }
  60. }
  61. const name = 'Guy'
  62. expect(getters.findUser(state)(name)).to.eql(undefined)
  63. })
  64. it('returns user with matching id', () => {
  65. const user = { screen_name: 'Guy', id: '1' }
  66. const state = {
  67. usersObject: {
  68. 1: user
  69. },
  70. usersByNameObject: {
  71. guy: user
  72. }
  73. }
  74. const id = '1'
  75. const expected = { screen_name: 'Guy', id: '1' }
  76. expect(getters.findUser(state)(id)).to.eql(expected)
  77. })
  78. })
  79. describe('findUserByName', () => {
  80. it('returns user with matching screen_name', () => {
  81. const user = { screen_name: 'Guy', id: '1' }
  82. const state = {
  83. usersObject: {
  84. 1: user
  85. },
  86. usersByNameObject: {
  87. guy: user
  88. }
  89. }
  90. const name = 'Guy'
  91. const expected = { screen_name: 'Guy', id: '1' }
  92. expect(getters.findUserByName(state)(name)).to.eql(expected)
  93. })
  94. it('does not return user with matching id', () => {
  95. const user = { screen_name: 'Guy', id: '1' }
  96. const state = {
  97. usersObject: {
  98. 1: user
  99. },
  100. usersByNameObject: {
  101. guy: user
  102. }
  103. }
  104. const id = '1'
  105. expect(getters.findUserByName(state)(id)).to.eql(undefined)
  106. })
  107. })
  108. })