Skip to content

Commit

Permalink
Freemium Local Package and Freemium State Implementation (#3118)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/0/1208051900053062/f
Tech Design URL:
https://app.asana.com/0/1206488453854252/1208051900053059/f

**Description**: This PR implements the proposal captured in the related
[Tech
Design](https://app.asana.com/0/1206488453854252/1208051900053059/f).
Specifically:

* A new `Freemium` local package
* A `FreemiumPIRState` type and associated unit tests

Note: This PR intends to just set up the foundation for this package. As
we develop the Freemium PIR feature, we may decide to add more to it.
However, we don’t intend to alter the core attributes i.e a local
package used to manage simple Freemium PIR State.
  • Loading branch information
aataraxiaa authored Aug 23, 2024
1 parent 2ea93ee commit bb8dd79
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 0 deletions.
30 changes: 30 additions & 0 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2585,6 +2585,10 @@
C17CA7AE2B9B52E6008EC3C1 /* NavigationBarPopoversTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C17CA7AC2B9B52E6008EC3C1 /* NavigationBarPopoversTests.swift */; };
C17CA7B22B9B5317008EC3C1 /* MockAutofillPopoverPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C17CA7B12B9B5317008EC3C1 /* MockAutofillPopoverPresenter.swift */; };
C17CA7B32B9B5317008EC3C1 /* MockAutofillPopoverPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C17CA7B12B9B5317008EC3C1 /* MockAutofillPopoverPresenter.swift */; };
C18BF9CC2C73678500ED6B8A /* Freemium in Frameworks */ = {isa = PBXBuildFile; productRef = C18BF9CB2C73678500ED6B8A /* Freemium */; };
C18BF9CE2C73678C00ED6B8A /* Freemium in Frameworks */ = {isa = PBXBuildFile; productRef = C18BF9CD2C73678C00ED6B8A /* Freemium */; };
C18BF9D02C736C9100ED6B8A /* Freemium in Frameworks */ = {isa = PBXBuildFile; productRef = C18BF9CF2C736C9100ED6B8A /* Freemium */; };
C18BF9D22C736C9700ED6B8A /* Freemium in Frameworks */ = {isa = PBXBuildFile; productRef = C18BF9D12C736C9700ED6B8A /* Freemium */; };
C1B1CBE12BE1915100B6049C /* DataImportShortcutsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1B1CBE02BE1915100B6049C /* DataImportShortcutsViewModel.swift */; };
C1B1CBE22BE1915100B6049C /* DataImportShortcutsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1B1CBE02BE1915100B6049C /* DataImportShortcutsViewModel.swift */; };
C1D8BE452C1739E70057E426 /* DataBrokerProtectionMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1D8BE442C1739E70057E426 /* DataBrokerProtectionMocks.swift */; };
Expand Down Expand Up @@ -3699,6 +3703,7 @@
9D9AE91A2AAA3B450026E7DC /* DuckDuckGoDBPBackgroundAgent.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = DuckDuckGoDBPBackgroundAgent.entitlements; sourceTree = "<group>"; };
9D9DE5712C63A96400D20B15 /* AppKitExtensions */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = AppKitExtensions; sourceTree = "<group>"; };
9DB6E7222AA0DA7A00A17F3C /* LoginItems */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = LoginItems; sourceTree = "<group>"; };
9DF2DB592C73B52F0025F43C /* Freemium */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = Freemium; sourceTree = "<group>"; };
9F0660722BECC71200B8EEF1 /* SubscriptionAttributionPixelHandlerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionAttributionPixelHandlerTests.swift; sourceTree = "<group>"; };
9F0660762BECC81800B8EEF1 /* PixelCapturedParameters.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PixelCapturedParameters.swift; sourceTree = "<group>"; };
9F0A2CF72B96A58600C5B8C0 /* BaseBookmarkEntityTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseBookmarkEntityTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4340,6 +4345,7 @@
F1D43AF52B98E48900BAB743 /* BareBonesBrowserKit in Frameworks */,
378F44E629B4BDEE00899924 /* SwiftUIExtensions in Frameworks */,
3706FCA7293F65D500E42796 /* BrowserServicesKit in Frameworks */,
C18BF9CE2C73678C00ED6B8A /* Freemium in Frameworks */,
3129788A2B64131200B67619 /* DataBrokerProtection in Frameworks */,
F198C7202BD18D92000BF24D /* SwiftLintTool in Frameworks */,
4BCBE4582BA7E17800FC75A1 /* SubscriptionUI in Frameworks */,
Expand Down Expand Up @@ -4517,6 +4523,7 @@
files = (
9DEF97E12B06C4EE00764F03 /* Networking in Frameworks */,
F1D0428E2BFB9F9C00A31506 /* Subscription in Frameworks */,
C18BF9D02C736C9100ED6B8A /* Freemium in Frameworks */,
9D9AE8F92AAA3AD00026E7DC /* DataBrokerProtection in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -4527,6 +4534,7 @@
files = (
315A023F2B6421AE00BFA577 /* Networking in Frameworks */,
F1D042902BFB9FA300A31506 /* Subscription in Frameworks */,
C18BF9D22C736C9700ED6B8A /* Freemium in Frameworks */,
9D9AE8FB2AAA3AD90026E7DC /* DataBrokerProtection in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -4535,6 +4543,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
C18BF9CC2C73678500ED6B8A /* Freemium in Frameworks */,
F1DF95E32BD1807C0045E591 /* Crashes in Frameworks */,
85E2BBCE2B8F534000DBEC7A /* History in Frameworks */,
1EA7B8D32B7E078C000330A4 /* SubscriptionUI in Frameworks */,
Expand Down Expand Up @@ -5068,6 +5077,7 @@
7B9167A82C09E88800322310 /* AppLauncher */,
378E279D2970217400FCADA2 /* BuildToolPlugins */,
3192A2702A4C4E330084EA89 /* DataBrokerProtection */,
9DF2DB592C73B52F0025F43C /* Freemium */,
9DB6E7222AA0DA7A00A17F3C /* LoginItems */,
7B25FE322AD12C990012AFAB /* NetworkProtectionMac */,
378F44E229B4B7B600899924 /* SwiftUIExtensions */,
Expand Down Expand Up @@ -8673,6 +8683,7 @@
371209242C232E6C003ADF3D /* RemoteMessaging */,
D6BC8AC72C5A95B10025375B /* DuckPlayer */,
9D9DE5742C63AA0C00D20B15 /* AppKitExtensions */,
C18BF9CD2C73678C00ED6B8A /* Freemium */,
);
productName = DuckDuckGo;
productReference = 3706FD05293F65D500E42796 /* DuckDuckGo App Store.app */;
Expand Down Expand Up @@ -8999,6 +9010,7 @@
9D9AE8F82AAA3AD00026E7DC /* DataBrokerProtection */,
9DEF97E02B06C4EE00764F03 /* Networking */,
F1D0428D2BFB9F9C00A31506 /* Subscription */,
C18BF9CF2C736C9100ED6B8A /* Freemium */,
);
productName = DuckDuckGoAgent;
productReference = 9D9AE8D12AAA39A70026E7DC /* DuckDuckGo Personal Information Removal.app */;
Expand All @@ -9022,6 +9034,7 @@
9D9AE8FA2AAA3AD90026E7DC /* DataBrokerProtection */,
315A023E2B6421AE00BFA577 /* Networking */,
F1D0428F2BFB9FA300A31506 /* Subscription */,
C18BF9D12C736C9700ED6B8A /* Freemium */,
);
productName = DuckDuckGoAgent;
productReference = 9D9AE8F22AAA39D30026E7DC /* DuckDuckGo Personal Information Removal App Store.app */;
Expand Down Expand Up @@ -9085,6 +9098,7 @@
371209222C232E66003ADF3D /* RemoteMessaging */,
D6BC8AC52C5A95AA0025375B /* DuckPlayer */,
9D9DE5722C63AA0700D20B15 /* AppKitExtensions */,
C18BF9CB2C73678500ED6B8A /* Freemium */,
);
productName = DuckDuckGo;
productReference = AA585D7E248FD31100E9A3E2 /* DuckDuckGo.app */;
Expand Down Expand Up @@ -14064,6 +14078,22 @@
package = 9FF521422BAA8FF300B9819B /* XCRemoteSwiftPackageReference "lottie-spm" */;
productName = Lottie;
};
C18BF9CB2C73678500ED6B8A /* Freemium */ = {
isa = XCSwiftPackageProductDependency;
productName = Freemium;
};
C18BF9CD2C73678C00ED6B8A /* Freemium */ = {
isa = XCSwiftPackageProductDependency;
productName = Freemium;
};
C18BF9CF2C736C9100ED6B8A /* Freemium */ = {
isa = XCSwiftPackageProductDependency;
productName = Freemium;
};
C18BF9D12C736C9700ED6B8A /* Freemium */ = {
isa = XCSwiftPackageProductDependency;
productName = Freemium;
};
CBC83E3529B63D380008E19C /* Configuration */ = {
isa = XCSwiftPackageProductDependency;
package = 9807F643278CA16F00E1547B /* XCRemoteSwiftPackageReference "BrowserServicesKit" */;
Expand Down
8 changes: 8 additions & 0 deletions LocalPackages/Freemium/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
38 changes: 38 additions & 0 deletions LocalPackages/Freemium/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.
//
// Package.swift
//
// Copyright © 2024 DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import PackageDescription

let package = Package(
name: "Freemium",
platforms: [ .macOS("11.4") ],
products: [
.library(
name: "Freemium",
targets: ["Freemium"]),
],
targets: [
.target(
name: "Freemium"),
.testTarget(
name: "FreemiumTests",
dependencies: ["Freemium"]),
]
)
43 changes: 43 additions & 0 deletions LocalPackages/Freemium/Sources/Freemium/FreemiumPIRState.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// FreemiumPIRState.swift
//
// Copyright © 2024 DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

/// `FreemiumPIRState` types provide access to Freemium PIR-related state
protocol FreemiumPIRState {
var didOnboard: Bool { get set }
}

/// Default implementation of `FreemiumPIRState`. `UserDefaults` is used as underlying storage.
public final class DefaultFreemiumPIRState: FreemiumPIRState {

private let userDefaults: UserDefaults
private let key = "macos.browser.freemium.pir"

public var didOnboard: Bool {
get {
userDefaults.bool(forKey: key)
} set {
userDefaults.set(newValue, forKey: key)
}
}

public init(userDefaults: UserDefaults) {
self.userDefaults = userDefaults
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// FreemiumPIRStateTests.swift
//
// Copyright © 2024 DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import XCTest
@testable import Freemium

final class FreemiumPIRStateTests: XCTestCase {

private static let testSuiteName = "test.defaults.freemium.state.tests"
private let pir = "macos.browser.freemium.pir"
private let testUserDefaults = UserDefaults(suiteName: FreemiumPIRStateTests.testSuiteName)!

override func setUpWithError() throws {
testUserDefaults.removePersistentDomain(forName: FreemiumPIRStateTests.testSuiteName)
}

func testSetsHasFreemiumPIR() throws {
// Given
let sut = DefaultFreemiumPIRState(userDefaults: testUserDefaults)
XCTAssertFalse(testUserDefaults.bool(forKey: pir))

// When
sut.didOnboard = true

// Then
XCTAssertTrue(testUserDefaults.bool(forKey: pir))
}

func testGetsHasFreemiumPIR() throws {
// Given
let sut = DefaultFreemiumPIRState(userDefaults: testUserDefaults)
XCTAssertFalse(sut.didOnboard)
testUserDefaults.setValue(true, forKey: pir)
XCTAssertTrue(testUserDefaults.bool(forKey: pir))

// When
let result = sut.didOnboard

// Then
XCTAssertTrue(result)
}
}

0 comments on commit bb8dd79

Please sign in to comment.