session.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. window.onload = function() {
  2. QUnit.test('test current user behaviour by updating session user via assets', assert => {
  3. // Wenn App.User updated through asset and set as session user
  4. // expect App.Session.get with new values
  5. App.User.refresh([{
  6. "login": "hh@example.com",
  7. "firstname": "Harald",
  8. "lastname": "Habebe",
  9. "email": "hh@example.com",
  10. "role_ids": [ 1, 2, 4 ],
  11. "group_ids": [ 1 ],
  12. "active": true,
  13. "updated_at": "2017-02-09T09:17:04.770Z",
  14. "address": "",
  15. "vip": false,
  16. "custom_key": undefined,
  17. "asdf": "",
  18. "id": 6
  19. }]);
  20. App.Session.set(6)
  21. assert.equal(App.Session.get('id'), 6)
  22. assert.equal(App.Session.get('login'), 'hh@example.com')
  23. assert.equal(App.Session.get('vip'), false)
  24. assert.equal(App.Session.get('custom_key'), undefined)
  25. assert.equal(App.Session.get().id, 6)
  26. assert.equal(App.Session.get().login, 'hh@example.com')
  27. assert.equal(App.Session.get().custom_key, undefined)
  28. assert.equal(App.Session.get().not_existing, undefined)
  29. // Wenn App.User updated through asset
  30. // expect App.Session.get with new values
  31. App.User.refresh([{
  32. "login": "hh_new@example.com",
  33. "firstname": "Harald",
  34. "lastname": "Habebe",
  35. "email": "hh_new@example.com",
  36. "role_ids": [ 1, 2, 4 ],
  37. "group_ids": [ 1 ],
  38. "active": true,
  39. "updated_at": "2017-02-09T09:17:04.770Z",
  40. "address": "",
  41. "vip": false,
  42. "custom_key": undefined,
  43. "asdf": "",
  44. "id": 6
  45. }]);
  46. assert.equal(App.Session.get('id'), 6)
  47. assert.equal(App.Session.get('login'), 'hh_new@example.com')
  48. assert.equal(App.Session.get('vip'), false)
  49. assert.equal(App.Session.get('custom_key'), undefined)
  50. assert.equal(App.Session.get().id, 6)
  51. assert.equal(App.Session.get().login, 'hh_new@example.com')
  52. assert.equal(App.Session.get().custom_key, undefined)
  53. assert.equal(App.Session.get().not_existing, undefined)
  54. // Wenn App.Session is reseted to inital
  55. // expect undefined for all
  56. App.Session.init()
  57. assert.equal(App.Session.get(), undefined)
  58. assert.equal(App.Session.get('id'), undefined)
  59. assert.equal(App.Session.get('login'), undefined)
  60. assert.equal(App.Session.get('vip'), undefined)
  61. assert.equal(App.Session.get('custom_key'), undefined)
  62. // When App.Session is set and set to undefined or null,
  63. // expect @current() to return null
  64. App.Session.set(6)
  65. App.Session.set(undefined)
  66. assert.equal(App.User.current(), null, 'with no active session')
  67. App.Session.set(null)
  68. assert.equal(App.User.current(), null, 'with no active session')
  69. // When App.Session is set with an invalid (not existing) user ID,
  70. // expect @current() to return null
  71. App.Session.set(100)
  72. assert.equal(App.User.current(), null, 'with invalid session user ID')
  73. });
  74. }