All files / src routes.js

58.33% Statements 14/24
100% Branches 8/8
37.5% Functions 6/16
58.33% Lines 14/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108            280x 7x 16x 3x 3x     13x 12x 3x   9x       13x 2x 1x         7x       35x                                                                                                                                                      
import { ROLES } from './constants/roles';
import { authErrorGuard } from './guards/authGuard';
import { authorizationGuard } from './guards/authorizationGuard';
import { environmentsGuard } from './guards/environmentsGuard';
 
function composeGuards(...guards) {
  return (to, from, next) => {
    const runGuard = (index) => {
      if (index >= guards.length) {
        next();
        return;
      }
 
      const guardResult = guards[index](to, from, (result) => {
        if (result !== undefined && result !== true) {
          next(result);
        } else {
          runGuard(index + 1);
        }
      });
 
      if (guardResult instanceof Promise) {
        guardResult.catch(() => {
          next('/error?type=guard_error');
        });
      }
    };
 
    runGuard(0);
  };
}
 
export default () => [
  {
    path: '/',
    redirect: '/environments',
  },
  {
    name: 'error',
    path: '/error',
    component: () => import('./features/auth/pages/ErrorPage'),
  },
  {
    name: 'environments',
    path: '/environments',
    component: () => import('./features/environments/pages/SelectEnvironmentPage'),
    beforeEnter: authErrorGuard,
  },
  {
    name: 'experiments',
    path: '/experiments',
    component: () => import('./features/experiments/pages/ExperimentsPage'),
    beforeEnter: composeGuards(authErrorGuard, environmentsGuard),
  },
  {
    name: 'targets',
    path: '/targets',
    component: () => import('./features/targets/pages/TargetsPage'),
    beforeEnter: composeGuards(authErrorGuard, environmentsGuard),
  },
  {
    name: 'templates',
    path: '/templates',
    component: () => import('./features/templates/pages/TemplatesPage'),
    beforeEnter: composeGuards(
      authErrorGuard,
      environmentsGuard,
      authorizationGuard,
    ),
    meta: { roles: [ROLES.ADMIN] },
  },
  {
    name: 'splits',
    path: '/splits',
    component: () => import('./features/splits/pages/SplitsPage'),
    beforeEnter: composeGuards(
      authErrorGuard,
      environmentsGuard,
      authorizationGuard,
    ),
    meta: { roles: [ROLES.ADMIN, ROLES.PRODUCT_MANAGER, ROLES.DASHBOARD_USER] },
  },
  {
    name: 'domains',
    path: '/domains',
    component: () => import('./features/domains/pages/DomainsPage'),
    beforeEnter: composeGuards(authErrorGuard, environmentsGuard),
  },
  {
    name: 'meGroups',
    path: '/me-groups',
    component: () => import('./features/me-groups/pages/MeGroupsPage'),
    beforeEnter: composeGuards(authErrorGuard, environmentsGuard),
  },
  {
    name: 'emailTemplates',
    path: '/email-templates',
    component: () => import('./features/email-templates/pages/EmailTemplatesPage'),
    beforeEnter: composeGuards(authErrorGuard, environmentsGuard),
  },
  {
    name: 'audit',
    path: '/audit',
    component: () => import('./features/audit/pages/AuditPage'),
    beforeEnter: composeGuards(authErrorGuard, environmentsGuard),
  },
];