-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Freemium Local Package and Freemium State Implementation (#3118)
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
1 parent
2ea93ee
commit bb8dd79
Showing
5 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
43
LocalPackages/Freemium/Sources/Freemium/FreemiumPIRState.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
LocalPackages/Freemium/Tests/FreemiumTests/FreemiumPIRStateTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |