organizationStore.spec.jsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {Organization} from 'fixtures/js-stubs/organization';
  2. import OrganizationStore from 'sentry/stores/organizationStore';
  3. describe('OrganizationStore', function () {
  4. beforeEach(function () {
  5. OrganizationStore.reset();
  6. });
  7. it('starts with loading state', function () {
  8. expect(OrganizationStore.get()).toMatchObject({
  9. loading: true,
  10. error: null,
  11. errorType: null,
  12. organization: null,
  13. dirty: false,
  14. });
  15. });
  16. it('updates correctly', function () {
  17. const organization = Organization();
  18. OrganizationStore.onUpdate(organization);
  19. expect(OrganizationStore.get()).toMatchObject({
  20. loading: false,
  21. error: null,
  22. errorType: null,
  23. organization,
  24. dirty: false,
  25. });
  26. // updates
  27. organization.slug = 'a new slug';
  28. OrganizationStore.onUpdate(organization);
  29. expect(OrganizationStore.get()).toMatchObject({
  30. loading: false,
  31. error: null,
  32. errorType: null,
  33. organization,
  34. dirty: false,
  35. });
  36. });
  37. it('updates correctly from setting changes', function () {
  38. const organization = Organization();
  39. OrganizationStore.onUpdate(organization);
  40. expect(OrganizationStore.get()).toMatchObject({
  41. loading: false,
  42. error: null,
  43. errorType: null,
  44. organization,
  45. dirty: false,
  46. });
  47. });
  48. it('errors correctly', function () {
  49. const error = new Error('uh-oh');
  50. error.status = 404;
  51. OrganizationStore.onFetchOrgError(error);
  52. expect(OrganizationStore.get()).toMatchObject({
  53. loading: false,
  54. error,
  55. errorType: 'ORG_NOT_FOUND',
  56. organization: null,
  57. dirty: false,
  58. });
  59. });
  60. });