Skip to content

Commit

Permalink
Run swiftlint --fix
Browse files Browse the repository at this point in the history
Motivation: fix all lint issues
  • Loading branch information
Rodrigo Gomez Palacio committed Oct 23, 2024
1 parent 4f7a9dd commit 663edc1
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
THE SOFTWARE.
*/

@objc public class OSIamFetchReadyCondition: NSObject, OSCondition {
@objc public class OSIamFetchReadyCondition: NSObject, OSCondition {
// the id used to index the token map (e.g. onesignalId)
private let id: String
private var hasSubscriptionUpdatePending: Bool = false
Expand All @@ -48,11 +48,11 @@

// Expose the constant to Objective-C
@objc public static let CONDITIONID: String = "OSIamFetchReadyCondition"

public var conditionId: String {
return OSIamFetchReadyCondition.CONDITIONID
}

public func setSubscriptionUpdatePending(value: Bool) {
hasSubscriptionUpdatePending = value
}
Expand All @@ -63,12 +63,12 @@
let userCreateTokenSet = tokenMap[NSNumber(value: OSIamFetchOffsetKey.userCreate.rawValue)] != nil
let userUpdateTokenSet = tokenMap[NSNumber(value: OSIamFetchOffsetKey.userUpdate.rawValue)] != nil
let subscriptionTokenSet = tokenMap[NSNumber(value: OSIamFetchOffsetKey.subscriptionUpdate.rawValue)] != nil
if (userCreateTokenSet) {
return true;

if userCreateTokenSet {
return true
}

if (hasSubscriptionUpdatePending) {
if hasSubscriptionUpdatePending {
return userUpdateTokenSet && subscriptionTokenSet
}
return userUpdateTokenSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import OneSignalCore

// Private initializer to prevent multiple instances
private override init() {}

// Used for testing
public func reset() {
indexedTokens = [:]
Expand Down Expand Up @@ -72,13 +72,13 @@ import OneSignalCore
return condition.getNewestToken(indexedTokens: self.indexedTokens)
}
}

// Method to resolve conditions by condition ID (e.g. OSIamFetchReadyCondition.ID)
@objc public func resolveConditionsWithID(id: String) {
guard let conditionList = indexedConditions[id] else { return }
var completedConditions: [(OSCondition, DispatchSemaphore)] = []
for (condition, semaphore) in conditionList {
if (condition.conditionId == id) {
if condition.conditionId == id {
semaphore.signal()
completedConditions.append((condition, semaphore))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,3 @@ public class OSReadYourWriteData: NSObject {
return hasher.finalize()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public class OSOperationRepo: NSObject {

// Persist the deltas (including new delta) to storage
OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_OPERATION_REPO_DELTA_QUEUE_KEY, withValue: self.deltaQueue)

if flush {
self.flushDeltaQueue()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ public class MockNewRecordsState: OSNewRecordsState {
super.add(key, overwrite)
}

override public func canAccess(_ key: String) -> Bool {
return super.canAccess(key)
}

public func get(_ key: String?) -> [MockNewRecord] {
return records.filter { $0.key == key }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class OSConsistencyManagerTests: XCTestCase {
XCTAssertTrue(true) // Simulate some async action completing without hanging
}
}

func testSetRywTokenWithoutAnyCondition() {
// Given
let id = "test_id"
Expand All @@ -138,7 +138,7 @@ class OSConsistencyManagerTests: XCTestCase {
// There is no condition registered, so we just check that no errors occur
XCTAssertTrue(true) // If no errors occur, this test will pass
}

func testMultipleConditionsWithDifferentKeys() {
let expectation1 = self.expectation(description: "UserUpdate condition met")
let expectation2 = self.expectation(description: "SubscriptionUpdate condition met")
Expand Down Expand Up @@ -215,7 +215,7 @@ class OSConsistencyManagerTests: XCTestCase {

return result
}

func testConditionMetImmediatelyAfterTokenAlreadySet() {
let expectation = self.expectation(description: "Condition met immediately")

Expand Down Expand Up @@ -247,7 +247,7 @@ class OSConsistencyManagerTests: XCTestCase {

waitForExpectations(timeout: 2.0, handler: nil)
}

func testConcurrentUpdatesToTokens() {
let expectation = self.expectation(description: "Concurrent updates handled correctly")

Expand Down Expand Up @@ -294,16 +294,15 @@ class OSConsistencyManagerTests: XCTestCase {
}
}


// Mock implementation of OSCondition that simulates a condition that isn't met
class TestUnmetCondition: NSObject, OSCondition {
// class-level constant for the ID
public static let CONDITIONID = "TestUnmetCondition"

public var conditionId: String {
return TestUnmetCondition.CONDITIONID
}

func isMet(indexedTokens: [String: [NSNumber: OSReadYourWriteData]]) -> Bool {
return false // Always returns false to simulate an unmet condition
}
Expand All @@ -316,49 +315,49 @@ class TestUnmetCondition: NSObject, OSCondition {
// Mock implementation of OSCondition for cases where the condition is met
class TestMetCondition: NSObject, OSCondition {
private let expectedTokens: [String: [NSNumber: OSReadYourWriteData]]

// class-level constant for the ID
public static let CONDITIONID = "TestMetCondition"

public var conditionId: String {
return TestMetCondition.CONDITIONID
}

init(expectedTokens: [String: [NSNumber: OSReadYourWriteData]]) {
self.expectedTokens = expectedTokens
}

func isMet(indexedTokens: [String: [NSNumber: OSReadYourWriteData]]) -> Bool {
print("Expected tokens: \(expectedTokens)")
print("Actual tokens: \(indexedTokens)")

// Check if all the expected tokens are present in the actual tokens
for (id, expectedTokenMap) in expectedTokens {
guard let actualTokenMap = indexedTokens[id] else {
print("No tokens found for id: \(id)")
return false
}

// Check if all expected keys (e.g., userUpdate, subscriptionUpdate) are present with the correct value
for (expectedKey, expectedValue) in expectedTokenMap {
guard let actualValue = actualTokenMap[expectedKey] else {
print("Key \(expectedKey) not found in actual tokens")
return false
}

if actualValue != expectedValue {
print("Mismatch for key \(expectedKey): expected \(expectedValue.rywToken), found \(actualValue.rywToken)")
return false
}
}
}

print("Condition met for id")
return true
}

func getNewestToken(indexedTokens: [String: [NSNumber: OSReadYourWriteData]]) -> OSReadYourWriteData? {
var dataBasedOnNewestRywToken: OSReadYourWriteData? = nil
var dataBasedOnNewestRywToken: OSReadYourWriteData?

// Loop through the token maps and compare the values
for tokenMap in indexedTokens.values {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class OSPropertyOperationExecutor: OSOperationExecutor {
if let rywToken = response?["ryw_token"] as? String
{
let rywDelay = response?["ryw_delay"] as? NSNumber

OSConsistencyManager.shared.setRywTokenAndDelay(
id: onesignalId,
key: OSIamFetchOffsetKey.userUpdate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor {
}
return
}

if let onesignalId = request.identityModel.onesignalId {
if let rywToken = response["ryw_token"] as? String
{
Expand All @@ -312,7 +312,7 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor {
OSConsistencyManager.shared.resolveConditionsWithID(id: OSIamFetchReadyCondition.CONDITIONID)
}
}

request.subscriptionModel.hydrate(response)
if inBackground {
OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier)
Expand Down Expand Up @@ -419,7 +419,7 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor {
OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier)
}
}

if let onesignalId = OneSignalUserManagerImpl.sharedInstance.onesignalId {
if let rywToken = response?["ryw_token"] as? String
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ extension OSUserExecutor {
} else {
self.executePendingRequests()
}

if let onesignalId = request.identityModel.onesignalId {
if let rywToken = response["ryw_token"] as? String
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class OSSubscriptionModelStoreListener: OSModelStoreListener {
let condition = OSIamFetchReadyCondition.sharedInstance(withId: onesignalId)
condition.setSubscriptionUpdatePending(value: true)
}

return OSDelta(
name: OS_UPDATE_SUBSCRIPTION_DELTA,
identityModelId: OneSignalUserManagerImpl.sharedInstance.user.identityModel.modelId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager {
guard let externalId = user.identityModel.externalId, let jwtExpiredHandler = self.jwtExpiredHandler else {
return
}
jwtExpiredHandler(externalId) { [self] (newToken) -> Void in
jwtExpiredHandler(externalId) { [self] (newToken) in
guard user.identityModel.externalId == externalId else {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ final class OneSignalUserTests: XCTestCase {
/* When */

OneSignalUserManagerImpl.sharedInstance.sendSessionTime(100)

OneSignalUserManagerImpl.sharedInstance.updatePropertiesDeltas(property: .session_count, value: 1, flush: false)

OneSignalUserManagerImpl.sharedInstance.setLanguage("lang_1")
Expand All @@ -106,7 +106,6 @@ final class OneSignalUserTests: XCTestCase {

OneSignalUserManagerImpl.sharedInstance.addTags(["a": "a", "b": "b", "c": "c"])


let purchases = [
["sku": "sku1", "amount": "1.25", "iso": "USD"],
["sku": "sku2", "amount": "3.99", "iso": "USD"]
Expand All @@ -115,7 +114,7 @@ final class OneSignalUserTests: XCTestCase {
OneSignalUserManagerImpl.sharedInstance.sendPurchases(purchases as [[String: AnyObject]])

OneSignalUserManagerImpl.sharedInstance.setLocation(latitude: 111.111, longitude: 222.222)

// This adds a `session_count` property with value of 1
// It also sets `refresh_device_metadata` to `true`
OneSignalUserManagerImpl.sharedInstance.startNewSession()
Expand Down

0 comments on commit 663edc1

Please sign in to comment.