Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up RemoteConfigFeature+Helpers and RemoteConfigFeatureFlagToolsViewModel #1924

Merged
merged 5 commits into from
Feb 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 47 additions & 31 deletions Library/RemoteConfig/RemoteConfigFeature+HelpersTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,102 +3,118 @@ import Prelude
import XCTest

final class RemoteConfigFeatureHelpersTests: TestCase {
func assertFeatureIsFalse(_ featureFlag: Bool,
whenRemoteConfigFeatureIsFalse feature: RemoteConfigFeature) {
func assertFeatureIsFalse(
whenRemoteConfigFeatureIsFalse feature: RemoteConfigFeature,
checkFeatureFlag: () -> Bool
) {
let mockRemoteConfigClient = MockRemoteConfigClient()
|> \.features .~ [feature.rawValue: false]

withEnvironment(remoteConfigClient: mockRemoteConfigClient) {
XCTAssertFalse(featureFlag)
XCTAssertFalse(checkFeatureFlag())
}
}

func assertFeatureIsTrue(_ featureFlag: Bool, whenRemoteConfigFeatureIsTrue feature: RemoteConfigFeature) {
func assertFeatureIsTrue(
whenRemoteConfigFeatureIsTrue feature: RemoteConfigFeature,
checkFeatureFlag: () -> Bool
) {
let mockRemoteConfigClient = MockRemoteConfigClient()
|> \.features .~ [feature.rawValue: true]

withEnvironment(remoteConfigClient: mockRemoteConfigClient) {
XCTAssertFalse(featureFlag)
XCTAssertTrue(checkFeatureFlag())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅 Great catch @ifosli. Soon as I swapped this to XCTAssertTrue the tests started failing!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now!

}
}

func testBlockUsers_RemoteConfig_FeatureFlag_False() {
self.assertFeatureIsFalse(featureBlockUsersEnabled(), whenRemoteConfigFeatureIsFalse: .blockUsersEnabled)
self.assertFeatureIsFalse(whenRemoteConfigFeatureIsFalse: .blockUsersEnabled) {
featureBlockUsersEnabled()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I could be wrong about this, but I don't think you need to do { featureBlockUsersEnabled() } - just featureBlockUsersEnabled should do the trick (though I think you need to pass the function as a normal param instead of trailing closure syntax). I'm okay with this as-is, but I think it's a little clearer when we don't make new closures just to call a single function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you're correct. Will fix, that looks much nicer.

}

func testBlockUsers_RemoteConfig_FeatureFlag_True() {
self.assertFeatureIsTrue(featureBlockUsersEnabled(), whenRemoteConfigFeatureIsTrue: .blockUsersEnabled)
self.assertFeatureIsTrue(whenRemoteConfigFeatureIsTrue: .blockUsersEnabled) {
featureBlockUsersEnabled()
}
}

func testConsentManagementDialog_RemoteConfig_FeatureFlag_False() {
self
.assertFeatureIsFalse(
featureConsentManagementDialogEnabled(),
whenRemoteConfigFeatureIsFalse: .consentManagementDialogEnabled
)
) {
featureConsentManagementDialogEnabled()
}
}

func testConsentManagementDialog_RemoteConfig_FeatureFlag_True() {
self
.assertFeatureIsTrue(
featureConsentManagementDialogEnabled(),
whenRemoteConfigFeatureIsTrue: .consentManagementDialogEnabled
)
) {
featureConsentManagementDialogEnabled()
}
}

func testDarkMode_RemoteConfig_FeatureFlag_False() {
self.assertFeatureIsFalse(featureDarkModeEnabled(), whenRemoteConfigFeatureIsFalse: .darkModeEnabled)
self.assertFeatureIsFalse(whenRemoteConfigFeatureIsFalse: .darkModeEnabled) {
featureDarkModeEnabled()
}
}

func testDarkMode_RemoteConfig_FeatureFlag_True() {
self.assertFeatureIsTrue(featureDarkModeEnabled(), whenRemoteConfigFeatureIsTrue: .darkModeEnabled)
self.assertFeatureIsTrue(whenRemoteConfigFeatureIsTrue: .darkModeEnabled) {
featureDarkModeEnabled()
}
}

func testFacebookDeprecation_RemoteConfig_FeatureFlag_True() {
self
.assertFeatureIsTrue(
featureFacebookLoginInterstitialEnabled(),
whenRemoteConfigFeatureIsTrue: .facebookLoginInterstitialEnabled
)
.assertFeatureIsTrue(whenRemoteConfigFeatureIsTrue: .facebookLoginInterstitialEnabled
) {
featureFacebookLoginInterstitialEnabled()
}
}

func testFacebookDeprecation_RemoteConfig_FeatureFlag_False() {
self
.assertFeatureIsFalse(
featureFacebookLoginInterstitialEnabled(),
whenRemoteConfigFeatureIsFalse: .facebookLoginInterstitialEnabled
)
.assertFeatureIsFalse(whenRemoteConfigFeatureIsFalse: .facebookLoginInterstitialEnabled
) {
featureFacebookLoginInterstitialEnabled()
}
}

func testPostCampaignPledge_RemoteConfig_FeatureFlag_True() {
self
.assertFeatureIsTrue(
featurePostCampaignPledgeEnabled(),
whenRemoteConfigFeatureIsTrue: .postCampaignPledgeEnabled
)
.assertFeatureIsTrue(whenRemoteConfigFeatureIsTrue: .postCampaignPledgeEnabled
) {
featurePostCampaignPledgeEnabled()
}
}

func testPostCampaignPledge_RemoteConfig_FeatureFlag_False() {
self
.assertFeatureIsFalse(
featurePostCampaignPledgeEnabled(),
whenRemoteConfigFeatureIsFalse: .postCampaignPledgeEnabled
)
) {
featurePostCampaignPledgeEnabled()
}
}

func testReportThisProject_RemoteConfig_FeatureFlag_True() {
self
.assertFeatureIsTrue(
featureReportThisProjectEnabled(),
whenRemoteConfigFeatureIsTrue: .reportThisProjectEnabled
)
) { featureReportThisProjectEnabled() }
}

func testReportThisProject_RemoteConfig_FeatureFlag_False() {
self
.assertFeatureIsFalse(
featureReportThisProjectEnabled(),
whenRemoteConfigFeatureIsFalse: .reportThisProjectEnabled
)
) {
featureReportThisProjectEnabled()
}
}
}