summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/resolvers/flag
diff options
context:
space:
mode:
Diffstat (limited to 'vid-webpack-master/src/app/shared/resolvers/flag')
-rw-r--r--vid-webpack-master/src/app/shared/resolvers/flag/flag.resolver.spec.ts61
-rw-r--r--vid-webpack-master/src/app/shared/resolvers/flag/flag.resolver.ts14
2 files changed, 75 insertions, 0 deletions
diff --git a/vid-webpack-master/src/app/shared/resolvers/flag/flag.resolver.spec.ts b/vid-webpack-master/src/app/shared/resolvers/flag/flag.resolver.spec.ts
new file mode 100644
index 000000000..930562ce0
--- /dev/null
+++ b/vid-webpack-master/src/app/shared/resolvers/flag/flag.resolver.spec.ts
@@ -0,0 +1,61 @@
+import {TestBed, getTestBed} from '@angular/core/testing';
+import {
+ HttpClientTestingModule,
+ HttpTestingController
+} from '@angular/common/http/testing';
+import {NgRedux} from "@angular-redux/store";
+import {FeatureFlagsService} from "../../services/featureFlag/feature-flags.service";
+import {ActivatedRouteSnapshot, convertToParamMap} from "@angular/router";
+import {FlagsResolve} from "./flag.resolver";
+import {ConfigurationService} from "../../services/configuration.service";
+
+class MockAppStore<T> {
+ getState() {
+ return {
+ service: {
+ serviceInstance: {}
+ }
+ }
+ }
+}
+
+
+describe('Flag resolver', () => {
+ let injector;
+ let resolver: FlagsResolve;
+ let configurationService: ConfigurationService;
+ let httpMock: HttpTestingController;
+
+ let activatedRouteSnapshot: ActivatedRouteSnapshot;
+ beforeAll(done => (async () => {
+ TestBed.configureTestingModule({
+ imports: [HttpClientTestingModule],
+ providers: [
+ FlagsResolve,
+ ConfigurationService,
+ FeatureFlagsService,
+ {provide: NgRedux, useClass: MockAppStore},
+ {
+ provide: ActivatedRouteSnapshot, useValue: {
+ queryParamMap:
+ convertToParamMap({ })
+ }
+ },
+ ]
+ });
+ await TestBed.compileComponents();
+
+ injector = getTestBed();
+ resolver = injector.get(FlagsResolve);
+ httpMock = injector.get(HttpTestingController);
+ activatedRouteSnapshot = injector.get(ActivatedRouteSnapshot);
+ configurationService = injector.get(ConfigurationService);
+
+ })().then(done).catch(done.fail));
+
+ test('should update flags', () => {
+ spyOn(configurationService, 'getFlags');
+ resolver.resolve(activatedRouteSnapshot);
+ expect(configurationService.getFlags).toHaveBeenCalled();
+ });
+});
diff --git a/vid-webpack-master/src/app/shared/resolvers/flag/flag.resolver.ts b/vid-webpack-master/src/app/shared/resolvers/flag/flag.resolver.ts
new file mode 100644
index 000000000..7ebce8bde
--- /dev/null
+++ b/vid-webpack-master/src/app/shared/resolvers/flag/flag.resolver.ts
@@ -0,0 +1,14 @@
+import {ActivatedRouteSnapshot, Resolve} from "@angular/router";
+import {Injectable} from "@angular/core";
+import {Observable} from "rxjs";
+import {ConfigurationService} from "../../services/configuration.service";
+
+@Injectable()
+export class FlagsResolve implements Resolve<Observable< { [key: string]: boolean }>> {
+
+ constructor(private _configurationService: ConfigurationService) {}
+
+ resolve(route: ActivatedRouteSnapshot) {
+ return this._configurationService.getFlags();
+ }
+}