initializeOrg.jsx 1014 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. });
  23. const router = TestStubs.router({
  24. ...additionalRouter,
  25. params: {
  26. orgId: organization.slug,
  27. ...additionalRouter?.params,
  28. },
  29. });
  30. const routerContext = TestStubs.routerContext([
  31. {
  32. organization,
  33. project,
  34. router,
  35. location: router.location,
  36. },
  37. ]);
  38. return {
  39. org: organization,
  40. organization,
  41. project,
  42. projects,
  43. router,
  44. routerContext,
  45. };
  46. }