Просмотр исходного кода

chore(ts): Remove usage of `TestStubs.Organization` (#57374)

Instead, import the factory object directly. This ended up being a big
one, but it's 90% search-and-replace the import.

The biggest change is a new `DetailedOrganization` interface. This is
what comes down when you pass `detailed=1` to the endpoint, and includes
`teams:` and `projects:` in the response. A lot of our tests are mocking
this, and passing those attributes. I thought it'd be more accurate to
add the new type and go from there. Otherwise, it's mostly just adding
missing fields here and there.

## Changes

- Replace all global refs of `Organization` stub
- Add more exact types
- Fix missing region URL
- Add missing name property
- Remove unnecessary deletes
- Add missing avatarUuid property
- Ensure project is defined
- Add missing name property
- Use enum
- Commit organization IDs to numbers
- Fix incorrect experiment stubs
- Specify features correctly
- Splat organizations correctly
- Add missing quota properties
- Correctly specify missing roles
George Gritsouk 1 год назад
Родитель
Сommit
7343643d84

+ 6 - 2
fixtures/js-stubs/organization.tsx

@@ -1,8 +1,10 @@
 import {OrgRoleList, TeamRoleList} from 'sentry-fixture/roleList';
 
-import type {Organization as TOrganization} from 'sentry/types';
+import type {DetailedOrganization} from 'sentry/types';
 
-export function Organization(params: Partial<TOrganization> = {}): TOrganization {
+export function Organization(
+  params: Partial<DetailedOrganization> = {}
+): DetailedOrganization {
   const slug = params.slug ?? 'org-slug';
   return {
     id: '3',
@@ -74,6 +76,8 @@ export function Organization(params: Partial<TOrganization> = {}): TOrganization
     sensitiveFields: [],
     storeCrashReports: 0,
     trustedRelays: [],
+    teams: [],
+    projects: [],
     ...params,
 
     orgRoleList: OrgRoleList(),

+ 3 - 1
static/app/actionCreators/events.spec.tsx

@@ -1,8 +1,10 @@
+import {Organization} from 'sentry-fixture/organization';
+
 import {doEventsRequest} from 'sentry/actionCreators/events';
 
 describe('Events ActionCreator', function () {
   const api = new MockApiClient();
-  const organization = TestStubs.Organization();
+  const organization = Organization();
   const project = TestStubs.Project();
   const opts = {
     organization,

+ 6 - 4
static/app/actionCreators/onboardingTasks.spec.tsx

@@ -1,3 +1,5 @@
+import {Organization} from 'sentry-fixture/organization';
+
 import {updateOnboardingTask} from 'sentry/actionCreators/onboardingTasks';
 import ConfigStore from 'sentry/stores/configStore';
 import OrganizationStore from 'sentry/stores/organizationStore';
@@ -11,7 +13,7 @@ describe('actionCreators/onboardingTasks', function () {
 
   describe('updateOnboardingTask', function () {
     it('Adds the task to the organization when task does not exists', async function () {
-      const detailedOrg = TestStubs.Organization({
+      const detailedOrg = Organization({
         teams: [TestStubs.Team()],
         projects: [TestStubs.Project()],
       });
@@ -39,10 +41,10 @@ describe('actionCreators/onboardingTasks', function () {
     });
 
     it('Updates existing onboarding task', async function () {
-      const detailedOrg = TestStubs.Organization({
+      const detailedOrg = Organization({
         teams: [TestStubs.Team()],
         projects: [TestStubs.Project()],
-        onboardingTasks: [{task: 'send_first_event', status: 'skipped'}],
+        onboardingTasks: [{task: OnboardingTaskKey.FIRST_EVENT, status: 'skipped'}],
       });
 
       const testTask = {
@@ -70,7 +72,7 @@ describe('actionCreators/onboardingTasks', function () {
     });
 
     it('Does not make API request without api object', async function () {
-      const detailedOrg = TestStubs.Organization({
+      const detailedOrg = Organization({
         teams: [TestStubs.Team()],
         projects: [TestStubs.Project()],
       });

+ 3 - 3
static/app/actionCreators/organization.spec.tsx

@@ -1,3 +1,5 @@
+import {Organization} from 'sentry-fixture/organization';
+
 import {fetchOrganizationDetails} from 'sentry/actionCreators/organization';
 import * as OrganizationsActionCreator from 'sentry/actionCreators/organizations';
 import OrganizationStore from 'sentry/stores/organizationStore';
@@ -6,9 +8,7 @@ import ProjectsStore from 'sentry/stores/projectsStore';
 import TeamStore from 'sentry/stores/teamStore';
 
 describe('OrganizationActionCreator', function () {
-  const org = TestStubs.Organization();
-  delete org.teams;
-  delete org.projects;
+  const org = Organization();
 
   const teams = [TestStubs.Team()];
   const projects = [TestStubs.Project()];

+ 4 - 2
static/app/actionCreators/organizations.spec.tsx

@@ -1,10 +1,12 @@
+import {Organization} from 'sentry-fixture/organization';
+
 import {fetchOrganizations} from 'sentry/actionCreators/organizations';
 import ConfigStore from 'sentry/stores/configStore';
 
 describe('fetchOrganizations', function () {
   const api = new MockApiClient();
-  const usorg = TestStubs.Organization({slug: 'us-org'});
-  const deorg = TestStubs.Organization({slug: 'de-org'});
+  const usorg = Organization({slug: 'us-org'});
+  const deorg = Organization({slug: 'de-org'});
 
   beforeEach(function () {
     MockApiClient.clearMockResponses();

+ 3 - 1
static/app/actionCreators/pageFilters.spec.tsx

@@ -1,3 +1,5 @@
+import {Organization} from 'sentry-fixture/organization';
+
 import {act} from 'sentry-test/reactTestingLibrary';
 
 import {
@@ -15,7 +17,7 @@ import localStorage from 'sentry/utils/localStorage';
 jest.mock('sentry/utils/localStorage');
 
 describe('PageFilters ActionCreators', function () {
-  const organization = TestStubs.Organization();
+  const organization = Organization();
 
   beforeEach(function () {
     jest.spyOn(PageFiltersStore, 'updateProjects');

+ 5 - 5
static/app/api.spec.tsx

@@ -1,3 +1,5 @@
+import {Organization} from 'sentry-fixture/organization';
+
 import {isSimilarOrigin, Request, resolveHostname} from 'sentry/api';
 import {PROJECT_MOVED} from 'sentry/constants/apiErrorCodes';
 
@@ -99,9 +101,7 @@ describe('resolveHostname', function () {
     configstate = ConfigStore.getState();
     devUi = window.__SENTRY_DEV_UI;
 
-    OrganizationStore.onUpdate(
-      TestStubs.Organization({features: ['frontend-domainsplit']})
-    );
+    OrganizationStore.onUpdate(Organization({features: ['frontend-domainsplit']}));
     ConfigStore.loadInitialData({
       ...configstate,
       links: {
@@ -120,7 +120,7 @@ describe('resolveHostname', function () {
 
   it('does nothing without feature', function () {
     // Org does not have the required feature.
-    OrganizationStore.onUpdate(TestStubs.Organization());
+    OrganizationStore.onUpdate(Organization());
 
     let result = resolveHostname(controlPath);
     expect(result).toBe(controlPath);
@@ -164,7 +164,7 @@ describe('resolveHostname', function () {
   it('removes sentryUrl from dev-ui mode requests when feature is off', function () {
     window.__SENTRY_DEV_UI = true;
     // Org does not have the required feature.
-    OrganizationStore.onUpdate(TestStubs.Organization());
+    OrganizationStore.onUpdate(Organization());
 
     let result = resolveHostname(controlPath);
     expect(result).toBe(controlPath);

+ 5 - 3
static/app/components/acl/access.spec.tsx

@@ -1,10 +1,12 @@
+import {Organization} from 'sentry-fixture/organization';
+
 import {render, screen} from 'sentry-test/reactTestingLibrary';
 
 import Access from 'sentry/components/acl/access';
 import ConfigStore from 'sentry/stores/configStore';
 
 describe('Access', function () {
-  const organization = TestStubs.Organization({
+  const organization = Organization({
     access: ['project:write', 'project:read'],
   });
   const routerContext = TestStubs.routerContext([{organization}]);
@@ -41,7 +43,7 @@ describe('Access', function () {
     });
 
     it('read access from team', function () {
-      const org = TestStubs.Organization({access: []});
+      const org = Organization({access: []});
       const nextRouterContext = TestStubs.routerContext([{organization: org}]);
 
       const team1 = TestStubs.Team({access: []});
@@ -78,7 +80,7 @@ describe('Access', function () {
     });
 
     it('read access from project', function () {
-      const org = TestStubs.Organization({access: []});
+      const org = Organization({access: []});
       const nextRouterContext = TestStubs.routerContext([{organization: org}]);
 
       const proj1 = TestStubs.Project({access: []});

+ 4 - 2
static/app/components/acl/feature.spec.tsx

@@ -1,3 +1,5 @@
+import {Organization} from 'sentry-fixture/organization';
+
 import {render, screen} from 'sentry-test/reactTestingLibrary';
 
 import Feature from 'sentry/components/acl/feature';
@@ -5,7 +7,7 @@ import ConfigStore from 'sentry/stores/configStore';
 import HookStore from 'sentry/stores/hookStore';
 
 describe('Feature', function () {
-  const organization = TestStubs.Organization({
+  const organization = Organization({
     features: ['org-foo', 'org-bar', 'bar'],
   });
   const project = TestStubs.Project({
@@ -93,7 +95,7 @@ describe('Feature', function () {
     });
 
     it('can specify org from props', function () {
-      const customOrg = TestStubs.Organization({features: ['org-bazar']});
+      const customOrg = Organization({features: ['org-bazar']});
       render(
         <Feature organization={customOrg} features={['org-bazar']}>
           {childrenMock}

+ 3 - 2
static/app/components/acl/role.spec.tsx

@@ -1,4 +1,5 @@
 import Cookies from 'js-cookie';
+import {Organization} from 'sentry-fixture/organization';
 
 import {render, screen} from 'sentry-test/reactTestingLibrary';
 
@@ -6,7 +7,7 @@ import {Role} from 'sentry/components/acl/role';
 import ConfigStore from 'sentry/stores/configStore';
 
 describe('Role', function () {
-  const organization = TestStubs.Organization({
+  const organization = Organization({
     orgRole: 'admin',
     orgRoleList: [
       {
@@ -123,7 +124,7 @@ describe('Role', function () {
 
     it('handles no organization.orgRoleList', function () {
       render(
-        <Role role="member" organization={{...organization, orgRoleList: undefined}}>
+        <Role role="member" organization={{...organization, orgRoleList: []}}>
           {childrenMock}
         </Role>,
         {context: routerContext}

Некоторые файлы не были показаны из-за большого количества измененных файлов