chore: feature status in context of item (#2359)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { FeatureIdentifier } from '@standardnotes/features'
|
||||
import { FeatureStatus, ItemManagerInterface } from '@standardnotes/services'
|
||||
import { GetFeatureStatusUseCase } from './GetFeatureStatus'
|
||||
import { ComponentInterface } from '@standardnotes/models'
|
||||
import { ComponentInterface, DecryptedItemInterface } from '@standardnotes/models'
|
||||
|
||||
jest.mock('@standardnotes/features', () => ({
|
||||
FeatureIdentifier: {
|
||||
@@ -71,6 +71,34 @@ describe('GetFeatureStatusUseCase', () => {
|
||||
})
|
||||
|
||||
describe('native features', () => {
|
||||
it('should return Entitled if the context item belongs to a shared vault and user does not have subscription', () => {
|
||||
;(FindNativeFeature as jest.Mock).mockReturnValue({ deprecated: false })
|
||||
|
||||
expect(
|
||||
usecase.execute({
|
||||
featureId: 'nativeFeature',
|
||||
firstPartyOnlineSubscription: undefined,
|
||||
firstPartyRoles: undefined,
|
||||
hasPaidAnyPartyOnlineOrOfflineSubscription: false,
|
||||
inContextOfItem: { shared_vault_uuid: 'sharedVaultUuid' } as jest.Mocked<DecryptedItemInterface>,
|
||||
}),
|
||||
).toEqual(FeatureStatus.Entitled)
|
||||
})
|
||||
|
||||
it('should return NoUserSubscription if the context item does not belong to a shared vault and user does not have subscription', () => {
|
||||
;(FindNativeFeature as jest.Mock).mockReturnValue({ deprecated: false })
|
||||
|
||||
expect(
|
||||
usecase.execute({
|
||||
featureId: 'nativeFeature',
|
||||
firstPartyOnlineSubscription: undefined,
|
||||
firstPartyRoles: undefined,
|
||||
hasPaidAnyPartyOnlineOrOfflineSubscription: false,
|
||||
inContextOfItem: { shared_vault_uuid: undefined } as jest.Mocked<DecryptedItemInterface>,
|
||||
}),
|
||||
).toEqual(FeatureStatus.NoUserSubscription)
|
||||
})
|
||||
|
||||
it('should return NoUserSubscription for native features without subscription and roles', () => {
|
||||
;(FindNativeFeature as jest.Mock).mockReturnValue({ deprecated: false })
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { AnyFeatureDescription, FeatureIdentifier, FindNativeFeature } from '@standardnotes/features'
|
||||
import { DecryptedItemInterface } from '@standardnotes/models'
|
||||
import { Subscription } from '@standardnotes/security'
|
||||
import { FeatureStatus, ItemManagerInterface } from '@standardnotes/services'
|
||||
import { convertTimestampToMilliseconds } from '@standardnotes/utils'
|
||||
@@ -11,6 +12,7 @@ export class GetFeatureStatusUseCase {
|
||||
firstPartyOnlineSubscription: Subscription | undefined
|
||||
firstPartyRoles: { online: string[] } | { offline: string[] } | undefined
|
||||
hasPaidAnyPartyOnlineOrOfflineSubscription: boolean
|
||||
inContextOfItem?: DecryptedItemInterface
|
||||
}): FeatureStatus {
|
||||
if (this.isFreeFeature(dto.featureId as FeatureIdentifier)) {
|
||||
return FeatureStatus.Entitled
|
||||
@@ -33,6 +35,7 @@ export class GetFeatureStatusUseCase {
|
||||
nativeFeature,
|
||||
firstPartyOnlineSubscription: dto.firstPartyOnlineSubscription,
|
||||
firstPartyRoles: dto.firstPartyRoles,
|
||||
inContextOfItem: dto.inContextOfItem,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -51,7 +54,15 @@ export class GetFeatureStatusUseCase {
|
||||
nativeFeature: AnyFeatureDescription
|
||||
firstPartyOnlineSubscription: Subscription | undefined
|
||||
firstPartyRoles: { online: string[] } | { offline: string[] } | undefined
|
||||
inContextOfItem?: DecryptedItemInterface
|
||||
}): FeatureStatus {
|
||||
if (dto.inContextOfItem) {
|
||||
const isSharedVaultItem = dto.inContextOfItem.shared_vault_uuid !== undefined
|
||||
if (isSharedVaultItem) {
|
||||
return FeatureStatus.Entitled
|
||||
}
|
||||
}
|
||||
|
||||
if (!dto.firstPartyOnlineSubscription && !dto.firstPartyRoles) {
|
||||
return FeatureStatus.NoUserSubscription
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user