Skip to content

Commit

Permalink
Merge pull request #5026 from wikimedia/yir-year-id
Browse files Browse the repository at this point in the history
[YiR] Add yearID to feature config
  • Loading branch information
l-olson1214 authored Oct 21, 2024
2 parents 3f7595c + 9eaf7d9 commit 1e0b8c2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ public class WMFYearInReviewDataController {

private let coreDataStore: WMFCoreDataStore
private let developerSettingsDataController: WMFDeveloperSettingsDataControlling

public let targetConfigYearID = "2024.1"

public init(coreDataStore: WMFCoreDataStore? = WMFDataEnvironment.current.coreDataStore, developerSettingsDataController: WMFDeveloperSettingsDataControlling = WMFDeveloperSettingsDataController.shared) throws {
guard let coreDataStore else {
Expand All @@ -20,7 +22,8 @@ public class WMFYearInReviewDataController {
return false
}

guard let iosFeatureConfig = developerSettingsDataController.loadFeatureConfig()?.ios.first else {
guard let iosFeatureConfig = developerSettingsDataController.loadFeatureConfig()?.ios.first,
let yirConfig = iosFeatureConfig.yir(yearID: targetConfigYearID) else {
return false
}

Expand All @@ -29,12 +32,12 @@ public class WMFYearInReviewDataController {
return false
}

let uppercaseConfigCountryCodes = iosFeatureConfig.yir.countryCodes.map { $0.uppercased() }
let uppercaseConfigCountryCodes = yirConfig.countryCodes.map { $0.uppercased() }
guard uppercaseConfigCountryCodes.contains(countryCode.uppercased()) else {
return false
}

let uppercaseConfigPrimaryAppLanguageCodes = iosFeatureConfig.yir.primaryAppLanguageCodes.map { $0.uppercased() }
let uppercaseConfigPrimaryAppLanguageCodes = yirConfig.primaryAppLanguageCodes.map { $0.uppercased() }
guard let languageCode = primaryAppLanguageProject.languageCode,
uppercaseConfigPrimaryAppLanguageCodes.contains(languageCode.uppercased()) else {
return false
Expand Down Expand Up @@ -246,24 +249,25 @@ public class WMFYearInReviewDataController {
return false
}

guard let iosFeatureConfig = developerSettingsDataController.loadFeatureConfig()?.ios.first else {
guard let iosFeatureConfig = developerSettingsDataController.loadFeatureConfig()?.ios.first,
let yirConfig = iosFeatureConfig.yir(yearID: targetConfigYearID) else {
return false
}

// Check remote feature disable switch
guard iosFeatureConfig.yir.isEnabled else {
guard yirConfig.isEnabled else {
return false
}


// Check remote valid country codes
let uppercaseConfigCountryCodes = iosFeatureConfig.yir.countryCodes.map { $0.uppercased() }
let uppercaseConfigCountryCodes = yirConfig.countryCodes.map { $0.uppercased() }
guard uppercaseConfigCountryCodes.contains(countryCode.uppercased()) else {
return false
}

// Check remote valid primary app language wikis
let uppercaseConfigPrimaryAppLanguageCodes = iosFeatureConfig.yir.primaryAppLanguageCodes.map { $0.uppercased() }
let uppercaseConfigPrimaryAppLanguageCodes = yirConfig.primaryAppLanguageCodes.map { $0.uppercased() }
guard let languageCode = primaryAppLanguageProject.languageCode,
uppercaseConfigPrimaryAppLanguageCodes.contains(languageCode.uppercased()) else {
return false
Expand All @@ -273,14 +277,14 @@ public class WMFYearInReviewDataController {

// TODO: Check persisted slide item here https://phabricator.wikimedia.org/T376041
// if {read_count persisted slide item}.display == yes {
if iosFeatureConfig.yir.personalizedSlides.readCount.isEnabled {
if yirConfig.personalizedSlides.readCount.isEnabled {
personalizedSlideCount += 1
}
// }

// TODO: Check persisted slide item here https://phabricator.wikimedia.org/T376041
// if {edit_count persisted slide item}.display == yes {
if iosFeatureConfig.yir.personalizedSlides.editCount.isEnabled {
if yirConfig.personalizedSlides.editCount.isEnabled {
personalizedSlideCount += 1
}
// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public struct WMFFeatureConfigResponse: Codable {
public let isEnabled: Bool
}

public let yearID: String
public let isEnabled: Bool
public let countryCodes: [String]
public let primaryAppLanguageCodes: [String]
Expand All @@ -24,7 +25,11 @@ public struct WMFFeatureConfigResponse: Codable {

let version: Int

public let yir: YearInReview
public let yir: [YearInReview]

public func yir(yearID: String) -> YearInReview? {
return yir.first { $0.yearID == yearID }
}
}

public let ios: [IOS]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"ios": [
{
"version": 1,
"yir": {
"yir": [{
"yearID": "2024.1",
"isEnabled": true,
"countryCodes": [
"FR",
Expand All @@ -23,7 +24,7 @@
"isEnabled": true
}
}
}
}]
}
],
"android": {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,21 @@ final class WMFDeveloperSettingsDataControllerTests: XCTestCase {
return
}

guard let config = controller.loadFeatureConfig() else {
guard let config = controller.loadFeatureConfig(),
let iosConfig = config.ios.first,
let yirConfig = config.ios.first?.yir(yearID: "2024.1") else {
XCTFail("Failure loading feature config")
return
}

XCTAssertEqual(config.ios.first?.version, 1, "Unexpected feature config version")
XCTAssertEqual(config.ios.first?.yir.isEnabled, true, "Unexpected feature config yir isEnabled")
XCTAssertEqual(config.ios.first?.yir.countryCodes.count, 2, "Unexpected feature config yir countryCodes count")
XCTAssertEqual(config.ios.first?.yir.primaryAppLanguageCodes.count, 2, "Unexpected feature config yir primaryAppLanguageCodes count")
XCTAssertEqual(config.ios.first?.yir.dataPopulationStartDateString, "2024-01-01T00:00:00Z", "Unexpected feature config yir dataPopulationStartDateString")
XCTAssertEqual(config.ios.first?.yir.dataPopulationEndDateString, "2024-11-01T00:00:00Z", "Unexpected feature config yir dataPopulationEndDateString")
XCTAssertEqual(config.ios.first?.yir.personalizedSlides.readCount.isEnabled, true, "Unexpected feature config yir personalizedSlides readCount isEnabled flag")
XCTAssertEqual(config.ios.first?.yir.personalizedSlides.editCount.isEnabled, true, "Unexpected feature config yir personalizedSlides editCount isEnabled flag")
XCTAssertEqual(iosConfig.version, 1, "Unexpected feature config version")
XCTAssertEqual(yirConfig.isEnabled, true, "Unexpected feature config yir isEnabled")
XCTAssertEqual(yirConfig.countryCodes.count, 2, "Unexpected feature config yir countryCodes count")
XCTAssertEqual(yirConfig.primaryAppLanguageCodes.count, 2, "Unexpected feature config yir primaryAppLanguageCodes count")
XCTAssertEqual(yirConfig.dataPopulationStartDateString, "2024-01-01T00:00:00Z", "Unexpected feature config yir dataPopulationStartDateString")
XCTAssertEqual(yirConfig.dataPopulationEndDateString, "2024-11-01T00:00:00Z", "Unexpected feature config yir dataPopulationEndDateString")
XCTAssertEqual(yirConfig.personalizedSlides.readCount.isEnabled, true, "Unexpected feature config yir personalizedSlides readCount isEnabled flag")
XCTAssertEqual(yirConfig.personalizedSlides.editCount.isEnabled, true, "Unexpected feature config yir personalizedSlides editCount isEnabled flag")

expectation.fulfill()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ final class YearInReviewDataControllerTests: XCTestCase {
let readCountSlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)
let editCountSlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)
let personalizedSlides = WMFFeatureConfigResponse.IOS.YearInReview.PersonalizedSlides(readCount: readCountSlideSettings, editCount: editCountSlideSettings)
let yearInReview = WMFFeatureConfigResponse.IOS.YearInReview(isEnabled: false, countryCodes: ["FR", "IT"], primaryAppLanguageCodes: ["fr", "it"], dataPopulationStartDateString: "2024-01-01T00:00:00Z", dataPopulationEndDateString: "2024-11-01T00:00:00Z", personalizedSlides: personalizedSlides)
let ios = WMFFeatureConfigResponse.IOS(version: 1, yir: yearInReview)
let yearInReview = WMFFeatureConfigResponse.IOS.YearInReview(yearID: "2024.1", isEnabled: false, countryCodes: ["FR", "IT"], primaryAppLanguageCodes: ["fr", "it"], dataPopulationStartDateString: "2024-01-01T00:00:00Z", dataPopulationEndDateString: "2024-11-01T00:00:00Z", personalizedSlides: personalizedSlides)
let ios = WMFFeatureConfigResponse.IOS(version: 1, yir: [yearInReview])
let config = WMFFeatureConfigResponse(ios: [ios])

// Create mock developer settings data controller
Expand All @@ -159,8 +159,8 @@ final class YearInReviewDataControllerTests: XCTestCase {
let readCountSlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)
let editCountSlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)
let personalizedSlides = WMFFeatureConfigResponse.IOS.YearInReview.PersonalizedSlides(readCount: readCountSlideSettings, editCount: editCountSlideSettings)
let yearInReview = WMFFeatureConfigResponse.IOS.YearInReview(isEnabled: true, countryCodes: ["FR", "IT"], primaryAppLanguageCodes: ["fr", "it"], dataPopulationStartDateString: "2024-01-01T00:00:00Z", dataPopulationEndDateString: "2024-11-01T00:00:00Z", personalizedSlides: personalizedSlides)
let ios = WMFFeatureConfigResponse.IOS(version: 1, yir: yearInReview)
let yearInReview = WMFFeatureConfigResponse.IOS.YearInReview(yearID: "2024.1", isEnabled: true, countryCodes: ["FR", "IT"], primaryAppLanguageCodes: ["fr", "it"], dataPopulationStartDateString: "2024-01-01T00:00:00Z", dataPopulationEndDateString: "2024-11-01T00:00:00Z", personalizedSlides: personalizedSlides)
let ios = WMFFeatureConfigResponse.IOS(version: 1, yir: [yearInReview])
let config = WMFFeatureConfigResponse(ios: [ios])

// Create mock developer settings data controller
Expand Down Expand Up @@ -189,8 +189,8 @@ final class YearInReviewDataControllerTests: XCTestCase {
let readCountSlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)
let editCountSlideSettings = WMFFeatureConfigResponse.IOS.YearInReview.SlideSettings(isEnabled: true)
let personalizedSlides = WMFFeatureConfigResponse.IOS.YearInReview.PersonalizedSlides(readCount: readCountSlideSettings, editCount: editCountSlideSettings)
let yearInReview = WMFFeatureConfigResponse.IOS.YearInReview(isEnabled: true, countryCodes: ["FR", "IT"], primaryAppLanguageCodes: ["fr", "it"], dataPopulationStartDateString: "2024-01-01T00:00:00Z", dataPopulationEndDateString: "2024-11-01T00:00:00Z", personalizedSlides: personalizedSlides)
let ios = WMFFeatureConfigResponse.IOS(version: 1, yir: yearInReview)
let yearInReview = WMFFeatureConfigResponse.IOS.YearInReview(yearID: "2024.1", isEnabled: true, countryCodes: ["FR", "IT"], primaryAppLanguageCodes: ["fr", "it"], dataPopulationStartDateString: "2024-01-01T00:00:00Z", dataPopulationEndDateString: "2024-11-01T00:00:00Z", personalizedSlides: personalizedSlides)
let ios = WMFFeatureConfigResponse.IOS(version: 1, yir: [yearInReview])
let config = WMFFeatureConfigResponse(ios: [ios])

// Create mock developer settings data controller
Expand Down

0 comments on commit 1e0b8c2

Please sign in to comment.