initializeOrg.jsx 1.1 KB

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