organizationStore.spec.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import OrganizationStore from 'sentry/stores/organizationStore';
  2. import RequestError from 'sentry/utils/requestError/requestError';
  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 = TestStubs.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 = TestStubs.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 RequestError('GET', '/some/path', 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. });