chore: remove calling payments server for subscriptions if using third party api hosts (#2398)

This commit is contained in:
Karol Sójko
2023-08-09 13:16:19 +02:00
committed by GitHub
parent e05d8c9e76
commit 90dcb33a44
24 changed files with 233 additions and 89 deletions

View File

@@ -7,14 +7,17 @@ import { SubscriptionApiServiceInterface } from '@standardnotes/api'
import { Invitation } from '@standardnotes/models'
import { InternalEventBusInterface } from '..'
import { SubscriptionManager } from './SubscriptionManager'
import { IsApplicationUsingThirdPartyHost } from '../UseCase/IsApplicationUsingThirdPartyHost'
import { Result } from '@standardnotes/domain-core'
describe('SubscriptionManager', () => {
let subscriptionApiService: SubscriptionApiServiceInterface
let internalEventBus: InternalEventBusInterface
let sessions: SessionsClientInterface
let storage: StorageServiceInterface
let isApplicationUsingThirdPartyHostUseCase: IsApplicationUsingThirdPartyHost
const createManager = () => new SubscriptionManager(subscriptionApiService, sessions, storage, internalEventBus)
const createManager = () => new SubscriptionManager(subscriptionApiService, sessions, storage, isApplicationUsingThirdPartyHostUseCase, internalEventBus)
beforeEach(() => {
subscriptionApiService = {} as jest.Mocked<SubscriptionApiServiceInterface>
@@ -31,6 +34,9 @@ describe('SubscriptionManager', () => {
internalEventBus = {} as jest.Mocked<InternalEventBusInterface>
internalEventBus.addEventHandler = jest.fn()
internalEventBus.publish = jest.fn()
isApplicationUsingThirdPartyHostUseCase = {} as jest.Mocked<IsApplicationUsingThirdPartyHost>
isApplicationUsingThirdPartyHostUseCase.execute = jest.fn().mockReturnValue(Result.ok(false))
})
describe('event handling', () => {

View File

@@ -22,6 +22,7 @@ import {
} from '@standardnotes/responses'
import { SubscriptionManagerEvent } from './SubscriptionManagerEvent'
import { ApplicationStageChangedEventPayload } from '../Event/ApplicationStageChangedEventPayload'
import { IsApplicationUsingThirdPartyHost } from '../UseCase/IsApplicationUsingThirdPartyHost'
export class SubscriptionManager
extends AbstractService<SubscriptionManagerEvent>
@@ -34,6 +35,7 @@ export class SubscriptionManager
private subscriptionApiService: SubscriptionApiServiceInterface,
private sessions: SessionsClientInterface,
private storage: StorageServiceInterface,
private isApplicationUsingThirdPartyHostUseCase: IsApplicationUsingThirdPartyHost,
protected override internalEventBus: InternalEventBusInterface,
) {
super(internalEventBus)
@@ -43,7 +45,15 @@ export class SubscriptionManager
switch (event.type) {
case ApplicationEvent.Launched: {
void this.fetchOnlineSubscription()
void this.fetchAvailableSubscriptions()
const isThirdPartyHostUsedOrError = this.isApplicationUsingThirdPartyHostUseCase.execute()
if (isThirdPartyHostUsedOrError.isFailed()) {
break
}
const isThirdPartyHostUsed = isThirdPartyHostUsedOrError.getValue()
if (!isThirdPartyHostUsed) {
void this.fetchAvailableSubscriptions()
}
break
}