organizationStore.spec.tsx 1.8 KB

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