From 1ae87858c0029c9e973201638b3edfabda5b7167 Mon Sep 17 00:00:00 2001 From: Adriano Costa Date: Fri, 10 May 2024 12:24:20 +0200 Subject: [PATCH] HXCS-3659 remove duplications --- .../services/debug-features.service.spec.ts | 210 +++++------------- 1 file changed, 54 insertions(+), 156 deletions(-) diff --git a/lib/core/feature-flags/src/lib/services/debug-features.service.spec.ts b/lib/core/feature-flags/src/lib/services/debug-features.service.spec.ts index 51540450ef1..a46703fcc93 100644 --- a/lib/core/feature-flags/src/lib/services/debug-features.service.spec.ts +++ b/lib/core/feature-flags/src/lib/services/debug-features.service.spec.ts @@ -39,7 +39,7 @@ describe('DebugFeaturesService', () => { setItem: () => {} }; - const getServiceWithDebugMode = (debugMode: boolean) => { + beforeEach(() => { TestBed.configureTestingModule({ providers: [ DebugFeaturesService, @@ -48,179 +48,77 @@ describe('DebugFeaturesService', () => { { provide: OverridableFeaturesServiceToken, useClass: DummyFeaturesService } ] }); - const featureService = TestBed.inject(DebugFeaturesService); - featureService.enable(debugMode); - return featureService; - }; + service = TestBed.inject(DebugFeaturesService); + }); - describe('in debug mode', () => { - beforeEach(() => { - service = getServiceWithDebugMode(true); - }); + it('should return false for isOn$ when flag is enabled', (done) => { + const flagKey = 'feature1'; - it('should be in debug mode', (done) => { - service.isEnabled().subscribe((isEnabled) => { - expect(isEnabled).toBeTrue(); + service + .isOn$(flagKey) + .pipe(take(1)) + .subscribe((isEnabled) => { + expect(isEnabled).toBeFalse(); done(); }); - }); - - it('should return false for isOn$ when flag is enabled', (done) => { - const flagKey = 'feature1'; - - service - .isOn$(flagKey) - .pipe(take(1)) - .subscribe((isEnabled) => { - expect(isEnabled).toBeFalse(); - done(); - }); - }); - - it('should return false for isOn$ when flag is disabled', (done) => { - const flagKey = 'feature2'; - - service - .isOn$(flagKey) - .pipe(take(1)) - .subscribe((isEnabled) => { - expect(isEnabled).toBeFalse(); - done(); - }); - }); - - it('should return true for isOff$ when flag is enabled', (done) => { - const flagKey = 'feature3'; - - service - .isOff$(flagKey) - .pipe(take(1)) - .subscribe((isEnabled) => { - expect(isEnabled).toBeTrue(); - done(); - }); - }); - - it('should return true for isOff$ when flag is disabled', (done) => { - const flagKey = 'feature4'; - - service - .isOff$(flagKey) - .pipe(take(1)) - .subscribe((isEnabled) => { - expect(isEnabled).toBeTrue(); - done(); - }); - }); - - it('should always reset specified flags', () => { - const flagsToReset = { - feature1: true - }; - const writableFeaturesServiceToken = TestBed.inject(WritableFeaturesServiceToken); - const spy = spyOn(writableFeaturesServiceToken, 'resetFlags'); - service.resetFlags(flagsToReset); + }); - expect(spy).toHaveBeenCalled(); - }); + it('should return false for isOn$ when flag is disabled', (done) => { + const flagKey = 'feature2'; - it('should get the flags as an observable', (done) => { - service.getFlags$().subscribe((flags) => { - expect(flags).toEqual({}); + service + .isOn$(flagKey) + .pipe(take(1)) + .subscribe((isEnabled) => { + expect(isEnabled).toBeFalse(); done(); }); - }); - - it('should get the flags snapshot', () => { - const flags = service.getFlagsSnapshot(); - expect(flags).toEqual({}); - }); - - it('should return the storageFeaturesService key with -override postfix', () => { - expect(service.storageKey).toBe('feature-flags-override'); - }); }); - describe('not in debug mode', () => { - beforeEach(() => { - service = getServiceWithDebugMode(false); - }); - it('should not be in debug mode', (done) => { - service.isEnabled().subscribe((isEnabled) => { - expect(isEnabled).toBeFalse(); + it('should return true for isOff$ when flag is enabled', (done) => { + const flagKey = 'feature3'; + + service + .isOff$(flagKey) + .pipe(take(1)) + .subscribe((isEnabled) => { + expect(isEnabled).toBeTrue(); done(); }); - }); - - it('should return false for isOn$ when flag is enabled', (done) => { - const flagKey = 'feature1'; - - service - .isOn$(flagKey) - .pipe(take(1)) - .subscribe((isEnabled) => { - expect(isEnabled).toBeFalse(); - done(); - }); - }); - - it('should return false for isOn$ when flag is disabled', (done) => { - const flagKey = 'feature2'; - - service - .isOn$(flagKey) - .pipe(take(1)) - .subscribe((isEnabled) => { - expect(isEnabled).toBeFalse(); - done(); - }); - }); - - it('should return true for isOff$ when flag is enabled', (done) => { - const flagKey = 'feature3'; - - service - .isOff$(flagKey) - .pipe(take(1)) - .subscribe((isEnabled) => { - expect(isEnabled).toBeTrue(); - done(); - }); - }); - - it('should return true for isOff$ when flag is disabled', (done) => { - const flagKey = 'feature4'; - - service - .isOff$(flagKey) - .pipe(take(1)) - .subscribe((isEnabled) => { - expect(isEnabled).toBeTrue(); - done(); - }); - }); - - it('should always reset specified flags', () => { - const flagsToReset = { - feature1: true - }; - const writableFeaturesServiceToken = TestBed.inject(WritableFeaturesServiceToken); - const spy = spyOn(writableFeaturesServiceToken, 'resetFlags'); - service.resetFlags(flagsToReset); + }); - expect(spy).toHaveBeenCalled(); - }); + it('should return true for isOff$ when flag is disabled', (done) => { + const flagKey = 'feature4'; - it('should get the flags as an observable', (done) => { - service.getFlags$().subscribe((flags) => { - expect(flags).toEqual({}); + service + .isOff$(flagKey) + .pipe(take(1)) + .subscribe((isEnabled) => { + expect(isEnabled).toBeTrue(); done(); }); - }); + }); - it('should get the flags snapshot', () => { - const flags = service.getFlagsSnapshot(); + it('should always reset specified flags', () => { + const flagsToReset = { + feature1: true + }; + const writableFeaturesServiceToken = TestBed.inject(WritableFeaturesServiceToken); + const spy = spyOn(writableFeaturesServiceToken, 'resetFlags'); + service.resetFlags(flagsToReset); + + expect(spy).toHaveBeenCalled(); + }); + + it('should get the flags as an observable', (done) => { + service.getFlags$().subscribe((flags) => { expect(flags).toEqual({}); + done(); }); }); + + it('should get the flags snapshot', () => { + const flags = service.getFlagsSnapshot(); + expect(flags).toEqual({}); + }); });