organizations.spec.tsx 1.3 KB

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