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

feat: New appRestorationVersion user default #127

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 17 additions & 5 deletions Sources/InfomaniakCore/Account/UserDefaults+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ public extension UserDefaults {
self.rawValue = rawValue
}

// TODO: Clean hotfix
static let legacyIsFirstLaunch = Keys(rawValue: "isFirstLaunch")
static let currentUserId = Keys(rawValue: "currentUserId")
static let appRestorationVersion = Keys(rawValue: "appRestorationVersion")
}

func key(_ key: Keys) -> String {
return key.rawValue
}
}

// MARK: - Public extension

public extension UserDefaults {
var currentUserId: Int {
get {
return integer(forKey: key(.currentUserId))
Expand All @@ -44,19 +48,27 @@ public extension UserDefaults {
}
}

// TODO: Clean hotfix
var legacyIsFirstLaunch: Bool {
get {
if object(forKey: key(.legacyIsFirstLaunch)) != nil {
return bool(forKey: key(.legacyIsFirstLaunch))
} else {
guard let isFirstLaunch = object(forKey: key(.legacyIsFirstLaunch)) as? Bool else {
return true
}

return isFirstLaunch
}
set {
set(newValue, forKey: key(.legacyIsFirstLaunch))
}
}

var appRestorationVersion: Int? {
get {
return object(forKey: key(.appRestorationVersion)) as? Int
}
set {
set(newValue, forKey: key(.appRestorationVersion))
}
}
}

// MARK: - Internal extension
Expand Down
58 changes: 58 additions & 0 deletions Tests/InfomaniakCoreTests/Account/UserDefaults.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
Infomaniak Core - iOS
Copyright (C) 2023 Infomaniak Network SA

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import InfomaniakCore
import XCTest

final class UTUserDefaults: XCTestCase {
func testCurrentUserId() {
// GIVEN
let userDefaults = UserDefaults()
userDefaults.currentUserId = 1337

// WHEN
let currentUserId = userDefaults.currentUserId

// THEN
XCTAssertEqual(currentUserId, 1337)
}

func testLegacyIsFirstLaunch() {
// GIVEN
let userDefaults = UserDefaults()
userDefaults.legacyIsFirstLaunch = true

// WHEN
let legacyIsFirstLaunch = userDefaults.legacyIsFirstLaunch

// THEN
XCTAssertEqual(legacyIsFirstLaunch, true)
}

func testAppRestorationVersion() {
// GIVEN
let userDefaults = UserDefaults()
userDefaults.appRestorationVersion = 1337

// WHEN
let appRestorationVersion = userDefaults.appRestorationVersion

// THEN
XCTAssertEqual(appRestorationVersion, 1337)
}
}
Loading