This commit is contained in:
Mo
2022-11-13 09:28:16 -06:00
committed by GitHub
parent e56a960bbf
commit d519aca685
49 changed files with 512 additions and 151 deletions

View File

@@ -10,6 +10,7 @@ import { PureCryptoInterface } from '@standardnotes/sncrypto-common'
import { convertTimestampToMilliseconds } from '@standardnotes/utils'
import {
AlertService,
FeaturesEvent,
FeatureStatus,
InternalEventBusInterface,
StorageKey,
@@ -203,6 +204,47 @@ describe('featuresService', () => {
})
describe('updateRoles()', () => {
it('setRoles should notify event if roles changed', async () => {
storageService.getValue = jest.fn().mockReturnValue(roles)
const featuresService = createService()
featuresService.initializeFromDisk()
const mock = (featuresService['notifyEvent'] = jest.fn())
const newRoles = [...roles, RoleName.PlusUser]
await featuresService.setRoles(newRoles)
expect(mock.mock.calls[0][0]).toEqual(FeaturesEvent.UserRolesChanged)
})
it('should notify of subscription purchase', async () => {
storageService.getValue = jest.fn().mockReturnValue(roles)
const featuresService = createService()
featuresService.initializeFromDisk()
const spy = jest.spyOn(featuresService, 'notifyEvent' as never)
const newRoles = [...roles, RoleName.ProUser]
await featuresService.updateRolesAndFetchFeatures('123', newRoles)
expect(spy.mock.calls[2][0]).toEqual(FeaturesEvent.DidPurchaseSubscription)
})
it('should not notify of subscription purchase on initial roles load after sign in', async () => {
storageService.getValue = jest.fn().mockReturnValue(roles)
const featuresService = createService()
featuresService.initializeFromDisk()
featuresService['roles'] = []
const spy = jest.spyOn(featuresService, 'notifyEvent' as never)
const newRoles = [...roles, RoleName.ProUser]
await featuresService.updateRolesAndFetchFeatures('123', newRoles)
const triggeredEvents = spy.mock.calls.map((call) => call[0])
expect(triggeredEvents).not.toContain(FeaturesEvent.DidPurchaseSubscription)
})
it('saves new roles to storage and fetches features if a role has been added', async () => {
const newRoles = [...roles, RoleName.PlusUser]
@@ -631,7 +673,7 @@ describe('featuresService', () => {
await featuresService.updateRolesAndFetchFeatures('123', [RoleName.CoreUser, RoleName.PlusUser])
sessionManager.isSignedIntoFirstPartyServer = jest.fn().mockReturnValue(false)
featuresService.hasOnlineSubscription = jest.fn().mockReturnValue(false)
featuresService.rolesIncludePaidSubscription = jest.fn().mockReturnValue(false)
featuresService['completedSuccessfulFeaturesRetrieval'] = true
expect(featuresService.getFeatureStatus(FeatureIdentifier.MidnightTheme)).toBe(FeatureStatus.NoUserSubscription)