Skip to content

Commit

Permalink
[MBL-722] Full MockOptimizely Removal (#1823)
Browse files Browse the repository at this point in the history
* reference commit

* clean up commented out code

* remove optimizley files

* update TestCase and TestCase AppEnvironment

* cleanup Library tests

* update snapshot tests

* remove optimizely keys from KeyStore and update tests

* removes duplicate tests

* update CommentsViewControllerTests snapshots

---------

Co-authored-by: Mubarak Sadoon <msadoon@gmail.com>
  • Loading branch information
scottkicks and msadoon committed May 24, 2023
1 parent c50512a commit e7fdb3b
Show file tree
Hide file tree
Showing 242 changed files with 144 additions and 1,916 deletions.
10 changes: 0 additions & 10 deletions Kickstarter-iOS/AppDelegate.swift
Expand Up @@ -254,16 +254,6 @@ internal final class AppDelegate: UIResponder, UIApplicationDelegate {
AppEnvironment.current.ksrAnalytics.configureSegmentClient(Analytics.shared())
}

self.viewModel.outputs.configureFeatureFlagClient
.observeValues { [weak self] featureFlagClient in
guard let strongSelf = self else { return }

// TODO: Will remove this method and input/output with the full removal of Optimizely code
AppEnvironment.updateOptimizelyClient(featureFlagClient)

strongSelf.viewModel.inputs.didUpdateRemoteConfigClient()
}

self.viewModel.outputs.segmentIsEnabled
.observeValues { enabled in
enabled ? Analytics.shared().enable() : Analytics.shared().disable()
Expand Down
26 changes: 0 additions & 26 deletions Kickstarter-iOS/AppDelegateViewModel.swift
Expand Up @@ -102,9 +102,6 @@ public protocol AppDelegateViewModelOutputs {
/// Emits an app secret that should be used to configure AppCenter.
var configureAppCenterWithData: Signal<AppCenterConfigData, Never> { get }

/// Emits when the application has configured feature flag client.
var configureFeatureFlagClient: Signal<OptimizelyClientType, Never> { get }

/// Emits when the application should configure Firebase
var configureFirebase: Signal<(), Never> { get }

Expand Down Expand Up @@ -802,11 +799,6 @@ public final class AppDelegateViewModel: AppDelegateViewModelType, AppDelegateVi

AppEnvironment.updateAdvertisingIdentifer(advertisingIdentifier)
}

self.configureFeatureFlagClient = self.applicationLaunchOptionsProperty.signal
.map { _ in AppEnvironment.current }
.map(configureOptimizely(for:))
.skipNil()
}

public var inputs: AppDelegateViewModelInputs { return self }
Expand Down Expand Up @@ -937,7 +929,6 @@ public final class AppDelegateViewModel: AppDelegateViewModelType, AppDelegateVi
return self.applicationDidFinishLaunchingReturnValueProperty.value
}

// FIXME: Currently not used with `MockOptimizelyClient`, but could be when we implement the next real feature flagging client.
fileprivate let remoteConfigClientConfigurationFailedProperty = MutableProperty(())
public func remoteConfigClientConfigurationFailed() {
self.remoteConfigClientConfigurationFailedProperty.value = ()
Expand All @@ -951,7 +942,6 @@ public final class AppDelegateViewModel: AppDelegateViewModelType, AppDelegateVi
public let applicationIconBadgeNumber: Signal<Int, Never>
public let configureAppCenterWithData: Signal<AppCenterConfigData, Never>
public let configureFirebase: Signal<(), Never>
public let configureFeatureFlagClient: Signal<OptimizelyClientType, Never>
public let configurePerimeterX: Signal<(), Never>
public let configureSegmentWithBraze: Signal<String, Never>
public let continueUserActivityReturnValue = MutableProperty(false)
Expand Down Expand Up @@ -1253,22 +1243,6 @@ extension ShortcutItem {
}
}

private func configureOptimizely(for _: Environment) -> OptimizelyClientType? {
// FIXME: This is until we add a new feature flagging client
let mockOptimizelyClient = MockOptimizelyClient()
|> \.features .~
[
OptimizelyFeature.commentFlaggingEnabled.rawValue: false,
OptimizelyFeature.consentManagementDialogEnabled.rawValue: false,
OptimizelyFeature.facebookLoginDeprecationEnabled.rawValue: false,
OptimizelyFeature.settingsPaymentSheetEnabled.rawValue: true,
OptimizelyFeature.paymentSheetEnabled.rawValue: true,
OptimizelyFeature.projectPageStoryTabEnabled.rawValue: true
]

return mockOptimizelyClient
}

private func visitorCookies() -> [HTTPCookie] {
let uuidString = (AppEnvironment.current.device.identifierForVendor ?? UUID()).uuidString

Expand Down
170 changes: 0 additions & 170 deletions Kickstarter-iOS/AppDelegateViewModelTests.swift
Expand Up @@ -13,7 +13,6 @@ final class AppDelegateViewModelTests: TestCase {

private let applicationIconBadgeNumber = TestObserver<Int, Never>()
private let configureAppCenterWithData = TestObserver<AppCenterConfigData, Never>()
private let configureFeatureFlagClient = TestObserver<OptimizelyClientType, Never>()
private let configureFirebase = TestObserver<(), Never>()
private let configurePerimeterX = TestObserver<(), Never>()
private let configureSegmentWithBraze = TestObserver<String, Never>()
Expand Down Expand Up @@ -56,16 +55,6 @@ final class AppDelegateViewModelTests: TestCase {
]
}

private let featureFlagsWithDefaultValues =
[
OptimizelyFeature.commentFlaggingEnabled.rawValue: false,
OptimizelyFeature.consentManagementDialogEnabled.rawValue: false,
OptimizelyFeature.facebookLoginDeprecationEnabled.rawValue: false,
OptimizelyFeature.settingsPaymentSheetEnabled.rawValue: true,
OptimizelyFeature.paymentSheetEnabled.rawValue: true,
OptimizelyFeature.projectPageStoryTabEnabled.rawValue: true
]

override func setUp() {
super.setUp()

Expand All @@ -74,7 +63,6 @@ final class AppDelegateViewModelTests: TestCase {
self.vm.outputs.applicationIconBadgeNumber.observe(self.applicationIconBadgeNumber.observer)
self.vm.outputs.configureAppCenterWithData.observe(self.configureAppCenterWithData.observer)
self.vm.outputs.configureFirebase.observe(self.configureFirebase.observer)
self.vm.outputs.configureFeatureFlagClient.observe(self.configureFeatureFlagClient.observer)
self.vm.outputs.configurePerimeterX.observe(self.configurePerimeterX.observer)
self.vm.outputs.configureSegmentWithBraze.observe(self.configureSegmentWithBraze.observer)
self.vm.outputs.emailVerificationCompleted.map(first)
Expand Down Expand Up @@ -168,164 +156,6 @@ final class AppDelegateViewModelTests: TestCase {
self.configurePerimeterX.assertValueCount(1)
}

// MARK: - Feature Flag Client

func testConfigureFeatureFlagClient_Production() {
let mockService = MockService(serverConfig: ServerConfig.production)

withEnvironment(apiService: mockService) {
self.configureFeatureFlagClient.assertDidNotEmitValue()

self.vm.inputs.applicationDidFinishLaunching(application: UIApplication.shared, launchOptions: nil)

self.configureFeatureFlagClient.assertValueCount(1)

guard let mockOptimizelyClient = self.configureFeatureFlagClient.lastValue as? MockOptimizelyClient
else {
XCTFail()

return
}

XCTAssertEqual(mockOptimizelyClient.features, featureFlagsWithDefaultValues)
}
}

func testConfigureFeatureFlagClient_Staging() {
let mockService = MockService(serverConfig: ServerConfig.staging)

withEnvironment(apiService: mockService) {
self.configureFeatureFlagClient.assertDidNotEmitValue()

self.vm.inputs.applicationDidFinishLaunching(application: UIApplication.shared, launchOptions: nil)

self.configureFeatureFlagClient.assertValueCount(1)

guard let mockOptimizelyClient = self.configureFeatureFlagClient.lastValue as? MockOptimizelyClient
else {
XCTFail()

return
}

XCTAssertEqual(mockOptimizelyClient.features, featureFlagsWithDefaultValues)
}
}

func testConfigureFeatureFlag_Release() {
let mockBundle = MockBundle(
bundleIdentifier: KickstarterBundleIdentifier.release.rawValue,
lang: Language.en.rawValue
)

withEnvironment(mainBundle: mockBundle) {
self.configureFeatureFlagClient.assertDidNotEmitValue()

self.vm.inputs.applicationDidFinishLaunching(application: UIApplication.shared, launchOptions: nil)

self.configureFeatureFlagClient.assertValueCount(1)

guard let mockOptimizelyClient = self.configureFeatureFlagClient.lastValue as? MockOptimizelyClient
else {
XCTFail()

return
}

XCTAssertEqual(mockOptimizelyClient.features, featureFlagsWithDefaultValues)
}
}

func testConfigureFeatureFlagClient_Alpha() {
let mockBundle = MockBundle(
bundleIdentifier: KickstarterBundleIdentifier.alpha.rawValue,
lang: Language.en.rawValue
)

withEnvironment(mainBundle: mockBundle) {
self.configureFeatureFlagClient.assertDidNotEmitValue()

self.vm.inputs.applicationDidFinishLaunching(application: UIApplication.shared, launchOptions: nil)

self.configureFeatureFlagClient.assertValueCount(1)

guard let mockOptimizelyClient = self.configureFeatureFlagClient.lastValue as? MockOptimizelyClient
else {
XCTFail()

return
}

XCTAssertEqual(mockOptimizelyClient.features, featureFlagsWithDefaultValues)
}
}

func testConfigureFeatureFlagClient_Beta() {
let mockBundle = MockBundle(
bundleIdentifier: KickstarterBundleIdentifier.beta.rawValue,
lang: Language.en.rawValue
)

withEnvironment(mainBundle: mockBundle) {
self.configureFeatureFlagClient.assertDidNotEmitValue()

self.vm.inputs.applicationDidFinishLaunching(application: UIApplication.shared, launchOptions: nil)

self.configureFeatureFlagClient.assertValueCount(1)

guard let mockOptimizelyClient = self.configureFeatureFlagClient.lastValue as? MockOptimizelyClient
else {
XCTFail()

return
}

XCTAssertEqual(mockOptimizelyClient.features, featureFlagsWithDefaultValues)
}
}

func testConfigureFeatureFlag_Debug() {
let mockBundle = MockBundle(
bundleIdentifier: KickstarterBundleIdentifier.debug.rawValue,
lang: Language.en.rawValue
)

withEnvironment(mainBundle: mockBundle) {
self.configureFeatureFlagClient.assertDidNotEmitValue()

self.vm.inputs.applicationDidFinishLaunching(application: UIApplication.shared, launchOptions: nil)

self.configureFeatureFlagClient.assertValueCount(1)

guard let mockOptimizelyClient = self.configureFeatureFlagClient.lastValue as? MockOptimizelyClient
else {
XCTFail()

return
}

XCTAssertEqual(mockOptimizelyClient.features, featureFlagsWithDefaultValues)
}
}

func testFeatureFlagClientConfiguration_IsSuccess() {
let mockService = MockService(serverConfig: ServerConfig.staging)

withEnvironment(apiService: mockService) {
self.configureFeatureFlagClient.assertDidNotEmitValue()

self.vm.inputs.applicationDidFinishLaunching(application: UIApplication.shared, launchOptions: nil)

self.configureFeatureFlagClient.assertValueCount(1)

self.vm.inputs.didUpdateRemoteConfigClient()

self.postNotificationName.assertValues([.ksr_remoteConfigClientConfigured])
}
}

// FIXME: When a real feature flagging client is setup, test the error case.

// MARK: - AppCenter

func testConfigureAppCenter_AlphaApp_LoggedOut() {
Expand Down
Expand Up @@ -174,43 +174,7 @@ internal final class CommentsViewControllerTests: TestCase {
}
}

func testView_CurrentUser_LoggedIn_IsBacking_CommentFlaggingEnabledFeatureFlag_True() {
let mockOptimizelyClient = MockOptimizelyClient()
|> \.features .~ [OptimizelyFeature.commentFlaggingEnabled.rawValue: true]

let mockService =
MockService(fetchProjectCommentsEnvelopeResult: .success(CommentsEnvelope.multipleCommentTemplate))

let project = Project.template
|> \.personalization.isBacking .~ true

combos(Language.allLanguages, [Device.phone4_7inch, Device.pad]).forEach {
language, device in
withEnvironment(
apiService: mockService,
currentUser: .template,
language: language,
optimizelyClient: mockOptimizelyClient
) {
let controller = CommentsViewController.configuredWith(project: project)
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller)
parent.view.frame.size.height = 1_100

self.scheduler.run()

assertSnapshot(
matching: parent.view,
as: .image,
named: "Comments - lang_\(language)_device_\(device)"
)
}
}
}

func testView_CurrentUser_LoggedIn_IsBacking_CommentFlaggingEnabledFeatureFlag_False() {
let mockOptimizelyClient = MockOptimizelyClient()
|> \.features .~ [OptimizelyFeature.commentFlaggingEnabled.rawValue: false]

func testView_CurrentUser_LoggedIn_IsBacking() {
let mockService =
MockService(fetchProjectCommentsEnvelopeResult: .success(CommentsEnvelope.multipleCommentTemplate))

Expand All @@ -222,8 +186,7 @@ internal final class CommentsViewControllerTests: TestCase {
withEnvironment(
apiService: mockService,
currentUser: .template,
language: language,
optimizelyClient: mockOptimizelyClient
language: language
) {
let controller = CommentsViewController.configuredWith(project: project)
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller)
Expand Down Expand Up @@ -294,11 +257,10 @@ internal final class CommentsViewControllerTests: TestCase {
}

func testCommentsViewControllerCreation_Success() {
let mockOptimizelyClient = MockOptimizelyClient()
let mockService = MockService(fetchProjectResult: .success(.template))

withEnvironment(
apiService: mockService, optimizelyClient: mockOptimizelyClient
apiService: mockService
) {
XCTAssert(commentsViewController(for: .template).isKind(of: CommentsViewController.self))
}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Expand Up @@ -35,10 +35,8 @@ public final class PaymentMethodsFooterView: UIView, NibLoading {
}

@IBAction func addNewCardButtonTapped(_: Any) {
if featureSettingsPaymentSheetEnabled() {
self.loadingIndicator.startAnimating()
self.addCardButton.isHidden = true
}
self.loadingIndicator.startAnimating()
self.addCardButton.isHidden = true

self.addCardButton.isUserInteractionEnabled = false
self.delegate?.paymentMethodsFooterViewDidTapAddNewCardButton(self)
Expand Down
Expand Up @@ -29,8 +29,6 @@ final class PledgePaymentMethodsViewControllerTests: TestCase {
func testView_PledgeContext_AddNewCardNonLoadingState_Success() {
let response = UserEnvelope<GraphUser>(me: self.userWithCards)
let envelope = ClientSecretEnvelope(clientSecret: "test")
let mockOptimizelyClient = MockOptimizelyClient()
|> \.features .~ [OptimizelyFeature.paymentSheetEnabled.rawValue: true]
let mockService = MockService(
createStripeSetupIntentResult: .success(envelope),
fetchGraphUserResult: .success(response)
Expand All @@ -42,8 +40,7 @@ final class PledgePaymentMethodsViewControllerTests: TestCase {
withEnvironment(
apiService: mockService,
currentUser: User.template,
language: language,
optimizelyClient: mockOptimizelyClient
language: language
) {
let controller = PledgePaymentMethodsViewController.instantiate()

Expand All @@ -70,8 +67,6 @@ final class PledgePaymentMethodsViewControllerTests: TestCase {

func testView_PledgeContext_AddNewCardLoadingState_Success() {
let response = UserEnvelope<GraphUser>(me: self.userWithCards)
let mockOptimizelyClient = MockOptimizelyClient()
|> \.features .~ [OptimizelyFeature.paymentSheetEnabled.rawValue: true]
/// Using .failure case to prevent real Stripe sheet from being shown.
let mockService = MockService(
createStripeSetupIntentResult: .failure(.couldNotParseJSON),
Expand All @@ -84,8 +79,7 @@ final class PledgePaymentMethodsViewControllerTests: TestCase {
withEnvironment(
apiService: mockService,
currentUser: User.template,
language: language,
optimizelyClient: mockOptimizelyClient
language: language
) {
let controller = PledgePaymentMethodsViewController.instantiate()

Expand Down

0 comments on commit e7fdb3b

Please sign in to comment.