organizations.spec.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {fetchOrganizations} from 'sentry/actionCreators/organizations';
  3. import ConfigStore from 'sentry/stores/configStore';
  4. describe('fetchOrganizations', function () {
  5. const api = new MockApiClient();
  6. const usorg = OrganizationFixture({slug: 'us-org'});
  7. const deorg = OrganizationFixture({slug: 'de-org'});
  8. beforeEach(function () {
  9. MockApiClient.clearMockResponses();
  10. });
  11. it('fetches from multiple regions', async function () {
  12. ConfigStore.set('regions', [
  13. {name: 'us', url: 'https://us.example.org'},
  14. {name: 'de', url: 'https://de.example.org'},
  15. ]);
  16. const usMock = MockApiClient.addMockResponse({
  17. url: '/organizations/',
  18. body: [usorg],
  19. match: [
  20. function (_url: string, options: Record<string, any>) {
  21. return options.host === 'https://us.example.org';
  22. },
  23. ],
  24. });
  25. const deMock = MockApiClient.addMockResponse({
  26. url: '/organizations/',
  27. body: [deorg],
  28. match: [
  29. function (_url: string, options: Record<string, any>) {
  30. return options.host === 'https://de.example.org';
  31. },
  32. ],
  33. });
  34. const organizations = await fetchOrganizations(api);
  35. expect(organizations).toHaveLength(2);
  36. expect(usMock).toHaveBeenCalledTimes(1);
  37. expect(deMock).toHaveBeenCalledTimes(1);
  38. });
  39. });