-
-
Notifications
You must be signed in to change notification settings - Fork 722
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: last seen environment remove duplicate entries (#4663)
- Loading branch information
Showing
2 changed files
with
75 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import createStores from '../../../test/fixtures/store'; | ||
import EventEmitter from 'events'; | ||
import getLogger from '../../../test/fixtures/no-logger'; | ||
import { IUnleashConfig } from '../../types'; | ||
import { LastSeenService } from './last-seen-service'; | ||
|
||
function initLastSeenService(flagEnabled = true) { | ||
const stores = createStores(); | ||
|
||
const eventBus = new EventEmitter(); | ||
eventBus.emit = jest.fn(); | ||
|
||
const config = { | ||
eventBus, | ||
getLogger, | ||
flagResolver: { | ||
isEnabled: () => { | ||
return flagEnabled; | ||
}, | ||
}, | ||
} as unknown as IUnleashConfig; | ||
|
||
const lastSeenService = new LastSeenService(stores, config); | ||
|
||
return { lastSeenService, featureToggleStore: stores.featureToggleStore }; | ||
} | ||
|
||
test('should not add duplicates per feature/environment', async () => { | ||
const { lastSeenService, featureToggleStore } = initLastSeenService(); | ||
|
||
lastSeenService.updateLastSeen([ | ||
{ | ||
featureName: 'myFeature', | ||
environment: 'development', | ||
yes: 1, | ||
no: 0, | ||
appName: 'test', | ||
timestamp: new Date(), | ||
}, | ||
]); | ||
|
||
lastSeenService.updateLastSeen([ | ||
{ | ||
featureName: 'myFeature', | ||
environment: 'development', | ||
yes: 1, | ||
no: 0, | ||
appName: 'test', | ||
timestamp: new Date(), | ||
}, | ||
]); | ||
featureToggleStore.setLastSeen = jest.fn(); | ||
await lastSeenService.store(); | ||
|
||
expect(featureToggleStore.setLastSeen).toHaveBeenCalledWith([ | ||
{ | ||
environment: 'development', | ||
featureName: 'myFeature', | ||
}, | ||
]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters