chore: fix and add test for role change event
This commit is contained in:
@@ -259,6 +259,20 @@ describe('FeaturesService', () => {
|
||||
expect(triggeredEvents).not.toContain(FeaturesEvent.DidPurchaseSubscription)
|
||||
})
|
||||
|
||||
it('should not notify of subscription purchase if new roles are not paid', async () => {
|
||||
storageService.getValue = jest.fn().mockReturnValue(roles)
|
||||
|
||||
featureService.initializeFromDisk()
|
||||
|
||||
const spy = jest.spyOn(featureService, 'notifyEvent' as never)
|
||||
|
||||
const newRoles = [...roles, 'TRANSITION_USER']
|
||||
await featureService.updateOnlineRolesWithNewValues(newRoles)
|
||||
|
||||
const triggeredEvents = spy.mock.calls.map((call) => call[0])
|
||||
expect(triggeredEvents).not.toContain(FeaturesEvent.DidPurchaseSubscription)
|
||||
})
|
||||
|
||||
it('saves new roles to storage if a role has been added', async () => {
|
||||
storageService.getValue = jest.fn().mockReturnValue(roles)
|
||||
|
||||
|
||||
@@ -360,8 +360,10 @@ export class FeaturesService
|
||||
|
||||
const isInitialLoadRolesChange = previousRoles.length === 0
|
||||
if (!isInitialLoadRolesChange) {
|
||||
const newRolesIncludePaidSubscription = this.rolesIncludePaidSubscription(roles)
|
||||
if (newRolesIncludePaidSubscription) {
|
||||
const changedRoles = roles.filter((role) => !previousRoles.includes(role))
|
||||
const changedRolesIncludePaidSubscription = this.rolesIncludePaidSubscription(changedRoles)
|
||||
|
||||
if (changedRolesIncludePaidSubscription) {
|
||||
await this.notifyEvent(FeaturesEvent.DidPurchaseSubscription)
|
||||
}
|
||||
}
|
||||
@@ -397,11 +399,9 @@ export class FeaturesService
|
||||
}
|
||||
|
||||
private rolesIncludePaidSubscription(roles: string[]) {
|
||||
{
|
||||
const unpaidRoles = [RoleName.NAMES.CoreUser]
|
||||
const paidRoles = [RoleName.NAMES.PlusUser, RoleName.NAMES.ProUser]
|
||||
|
||||
return roles.some((role) => !unpaidRoles.includes(role))
|
||||
}
|
||||
return roles.some((role) => paidRoles.includes(role))
|
||||
}
|
||||
|
||||
onlineRolesIncludePaidSubscription(): boolean {
|
||||
|
||||
Reference in New Issue
Block a user