All files / src/app/core/guards feature-toggle.guard.ts

100% Statements 12/12
100% Branches 1/1
100% Functions 1/1
100% Lines 12/12

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 26195x 195x   195x 195x         195x 15x 15x 15x   15x 1x 1x             14x    
import { inject } from '@angular/core';
import { ActivatedRouteSnapshot, Router } from '@angular/router';
 
import { FeatureToggleService } from 'ish-core/feature-toggle.module';
import { HttpStatusCodeService } from 'ish-core/utils/http-status-code/http-status-code.service';
 
/**
 * Routes only to the page if the configured feature toggle at the route is switched on
 */
export function featureToggleGuard(route: ActivatedRouteSnapshot) {
  const featureToggleService = inject(FeatureToggleService);
  const router = inject(Router);
  const httpStatusCodeService = inject(HttpStatusCodeService);
 
  if (!featureToggleService.enabled(route.data.feature)) {
    httpStatusCodeService.setStatus(404, false);
    return router.createUrlTree(['/error'], {
      queryParams: {
        error: 'feature-deactivated',
        value: route.data.feature,
      },
    });
  }
  return true;
}