initializeOrg.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import type {Organization, Project} from 'sentry/types';
  2. /**
  3. * Creates stubs for:
  4. * - a project or projects
  5. * - organization owning above projects
  6. * - router
  7. * - context that contains org + projects + router
  8. */
  9. export function initializeOrg({
  10. organization: additionalOrg,
  11. project: additionalProject,
  12. projects: additionalProjects,
  13. router: additionalRouter,
  14. }: {
  15. organization?: Partial<Organization>;
  16. project?: Partial<Project>;
  17. projects?: Partial<Project>[];
  18. router?: any;
  19. } = {}) {
  20. const projects = (
  21. additionalProjects ||
  22. (additionalProject && [additionalProject]) || [{}]
  23. ).map(p => TestStubs.Project(p));
  24. const [project] = projects;
  25. const organization = TestStubs.Organization({
  26. projects,
  27. ...additionalOrg,
  28. orgRoleList: TestStubs.OrgRoleList(),
  29. teamRoleList: TestStubs.TeamRoleList(),
  30. });
  31. const router = TestStubs.router({
  32. ...additionalRouter,
  33. params: {
  34. orgId: organization.slug,
  35. ...additionalRouter?.params,
  36. },
  37. });
  38. const routerContext: any = TestStubs.routerContext([
  39. {
  40. organization,
  41. project,
  42. router,
  43. location: router.location,
  44. },
  45. ]);
  46. return {
  47. organization,
  48. project,
  49. projects,
  50. router,
  51. routerContext,
  52. // not sure what purpose this serves
  53. route: {},
  54. };
  55. }