initializeOrg.jsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. organization,
  42. project,
  43. projects,
  44. router,
  45. routerContext,
  46. };
  47. }