Skip to content

Commit

Permalink
clean and fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
ABTastyAdel committed Dec 6, 2023
1 parent 9f2a1e3 commit 7c20006
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 35 deletions.
6 changes: 3 additions & 3 deletions FlagShip/FlagShipTests/FSTrackingManagerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class FSTrackingManagerTest: XCTestCase {
testEvent.envId = "envId"
}

func testSendHitWithSucess() {
func testSendHitWithSuccess() {
MockURLProtocol.requestHandler = { _ in
let response = HTTPURLResponse(url: URL(string: "---")!, statusCode: 200, httpVersion: nil, headerFields: nil)!
return (response, nil)
Expand Down Expand Up @@ -88,11 +88,11 @@ final class FSTrackingManagerTest: XCTestCase {
XCTAssert(perdiodicTrackingManager?.batchManager.isQueueEmpty() == false)
}

func testOnSucessToSendHits() {
func testOnSuccessToSendHits() {
let batchTest = FSBatch([testEvent, testEvent, testEvent])

perdiodicTrackingManager?.batchManager.reInjectElements(listToReInject: [testEvent, testEvent, testEvent])
perdiodicTrackingManager?.onSucessToSendHits(batchTest)
perdiodicTrackingManager?.onSuccessToSendHits(batchTest)
XCTAssertTrue(fsTestCacheManager.isCacheHitsCalled == true)
}

Expand Down
4 changes: 2 additions & 2 deletions FlagShip/FlagShipTests/FlagshipBucketingTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class FlagshipBucketingTest: XCTestCase {
}
}

func testBucketingWithSucess() {
let expectationSync = XCTestExpectation(description: "testBucketingWithSucess")
func testBucketingWithSuccess() {
let expectationSync = XCTestExpectation(description: "testBucketingWithSuccess")

fsConfig = FSConfigBuilder().Bucketing().withBucketingPollingIntervals(5).withStatusListener { newStatus in
if newStatus == .READY {
Expand Down
10 changes: 5 additions & 5 deletions FlagShip/Source/Tracking/FSTrackingManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class FSTrackingManager: ITrackingManager, FSBatchingManagerDelegate {
service.activate(currentActivate.bodyTrack) { error in

if error == nil {
FlagshipLogManager.Log(level: .ALL, tag: .ACTIVATE, messageToDisplay: FSLogMessage.MESSAGE("Exposure sent with sucess"))
FlagshipLogManager.Log(level: .ALL, tag: .ACTIVATE, messageToDisplay: FSLogMessage.MESSAGE("Exposure sent with success"))
FlagshipLogManager.Log(level: .ALL, tag: .ACTIVATE, messageToDisplay: FSLogMessage.MESSAGE(currentActivate.description()))

} else {
Expand Down Expand Up @@ -106,7 +106,7 @@ class FSTrackingManager: ITrackingManager, FSBatchingManagerDelegate {

if error == nil {
FlagshipLogManager.Log(level: .INFO, tag: .TRACKING, messageToDisplay: FSLogMessage.SUCCESS_SEND_HIT)
self.onSucessToSendHits(batchToSend)
self.onSuccessToSendHits(batchToSend)
} else {
self.onFailedToSendHits(batchToSend)
FlagshipLogManager.Log(level: .INFO, tag: .TRACKING, messageToDisplay: FSLogMessage.SEND_EVENT_FAILED)
Expand Down Expand Up @@ -167,14 +167,14 @@ class FSTrackingManager: ITrackingManager, FSBatchingManagerDelegate {
if error != nil {
self.onFailedToSendActivate(batchForCachedActivate)
} else {
self.onSucessToSendActivate(batchForCachedActivate)
self.onSuccessToSendActivate(batchForCachedActivate)
}
}
}
}

// ********** HITS ************//
func onSucessToSendHits(_ batchToSend: FSBatch) {
func onSuccessToSendHits(_ batchToSend: FSBatch) {
// Create a list of hits id to remove for database
cacheManager?.hitCacheDelegate?.flushHits(hitIds: batchToSend.items.map { elem in
elem.id
Expand All @@ -186,7 +186,7 @@ class FSTrackingManager: ITrackingManager, FSBatchingManagerDelegate {
}

// ********** ACTIVATES ************//
func onSucessToSendActivate(_ activateBatch: ActivateBatch) {
func onSuccessToSendActivate(_ activateBatch: ActivateBatch) {
cacheManager?.flushHits(activateBatch.listActivate.map { elem in
elem.id
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class ContinuousTrackingManager: FSTrackingManager {
service.activate(activateBatch.bodyTrack) { error in
if error == nil {
FlagshipLogManager.Log(level: .ALL, tag: .ACTIVATE, messageToDisplay: FSLogMessage.ACTIVATE_SUCCESS(activateBatch.bodyTrack.description))
self.onSucessToSendActivate(activateBatch)
self.onSuccessToSendActivate(activateBatch)
} else {
FlagshipLogManager.Log(level: .ALL, tag: .ACTIVATE, messageToDisplay: FSLogMessage.MESSAGE("Failed to send Activate"))
self.onFailedToSendActivate(activateBatch)
Expand All @@ -110,7 +110,7 @@ class ContinuousTrackingManager: FSTrackingManager {

// ********** HITS ************//
override
internal func onSucessToSendHits(_ batchToSend: FSBatch) {
internal func onSuccessToSendHits(_ batchToSend: FSBatch) {
// Create a list of hits id to remove for database
self.cacheManager?.hitCacheDelegate?.flushHits(hitIds: batchToSend.items.map { elem in
elem.id
Expand All @@ -125,7 +125,7 @@ class ContinuousTrackingManager: FSTrackingManager {

// ********** ACTIVATE ********//
override
internal func onSucessToSendActivate(_ activateBatch: ActivateBatch) {
internal func onSuccessToSendActivate(_ activateBatch: ActivateBatch) {
// Create array of ids and use it by the flush database
self.cacheManager?.flushHits(activateBatch.listActivate.map { elem in
elem.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class PeriodicTrackingManager: ContinuousTrackingManager {
}
}

override internal func onSucessToSendHits(_ batchToSend: FSBatch) {
override internal func onSuccessToSendHits(_ batchToSend: FSBatch) {

// Clear all hits in database
cacheManager?.flushAllHits()
Expand Down Expand Up @@ -58,7 +58,7 @@ class PeriodicTrackingManager: ContinuousTrackingManager {
}
}

override internal func onSucessToSendActivate(_ activateBatch: ActivateBatch) {
override internal func onSuccessToSendActivate(_ activateBatch: ActivateBatch) {
}

// Remove hits for visitorId and keep the consent hits
Expand Down
25 changes: 14 additions & 11 deletions FlagShip/Source/Troubleshooting/FSDataUsageTracking+Criticals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
let DataUsageLabel = "SDK_CONFIG"

extension FSDataUsageTracking {
// Troubleshooting Error Catched
// Troubleshooting on error catched
func processTSCatchedError(v: FSVisitor?, error: FlagshipError) {
var criticalJson: [String: String] = ["visitor.sessionId": _visitorSessionId,
"visitor.visitorId": v?.visitorId ?? "",
Expand All @@ -22,12 +22,12 @@ extension FSDataUsageTracking {
criticalJson.merge(_createTRContext(aV)) { _, new in new }
}

// Send TS on Flag warninig
// Send TS on error catched
sendTroubleshootingReport(_trHit:
TroubleshootingHit(pVisitorId: _visitorId, pLabel: CriticalPoints.ERROR_CATCHED.rawValue, pSpeceficCustomFields: criticalJson))
}

// Troubleshooting Flag
// Troubleshooting for Flag
func proceesTSFlag(crticalPointLabel: CriticalPoints, f: FSFlag, v: FSVisitor?) {
var criticalJson: [String: String] = ["visitor.sessionId": _visitorSessionId,
"visitor.visitorId": v?.visitorId ?? "",
Expand All @@ -44,7 +44,7 @@ extension FSDataUsageTracking {
TroubleshootingHit(pVisitorId: _visitorId, pLabel: crticalPointLabel.rawValue, pSpeceficCustomFields: criticalJson))
}

// Troubleshooting on request
// Troubleshooting on any request error
func processTSHttpError(requestType: FSRequestType, _ response: HTTPURLResponse?, _ request: URLRequest, _ data: Data? = nil) {
var criticalJson: [String: String] = ["visitor.sessionId": _visitorSessionId,
"visitor.visitorId": _visitorId]
Expand All @@ -69,11 +69,12 @@ extension FSDataUsageTracking {
return
}

// Send TS report on http error
// Send Troubleshooting report on http error
sendTroubleshootingReport(_trHit:
TroubleshootingHit(pVisitorId: _visitorId, pLabel: criticalLabel, pSpeceficCustomFields: criticalJson))
}


// Process http on bucketing error
func processTSHttp(crticalPointLabel: CriticalPoints, _ response: HTTPURLResponse?, _ request: URLRequest, _ data: Data? = nil) {
var criticalJson: [String: String] = ["visitor.sessionId": _visitorSessionId,
"visitor.visitorId": _visitorId]
Expand All @@ -90,7 +91,8 @@ extension FSDataUsageTracking {
sendTroubleshootingReport(_trHit:
TroubleshootingHit(pVisitorId: _visitorId, pLabel: crticalPointLabel.rawValue, pSpeceficCustomFields: criticalJson))
}


// Process on download bucketing file
func processTSBucketingFile(_ response: HTTPURLResponse?, _ request: URLRequest, _ data: Data) {
var criticalJson: [String: String] = ["visitor.sessionId": _visitorSessionId,
"visitor.visitorId": _visitorId]
Expand All @@ -108,7 +110,7 @@ extension FSDataUsageTracking {
TroubleshootingHit(pVisitorId: _visitorId, pLabel: CriticalPoints.SDK_BUCKETING_FILE.rawValue, pSpeceficCustomFields: criticalJson))
}

// TS Send Hit
// Troubleshooting on send hits
func processTSHits(label: String, visitor: FSVisitor, hit: FSTrackingProtocol) {
var criticalJson: [String: String] = ["visitor.sessionId": _visitorSessionId,
"visitor.visitorId": visitor.visitorId,
Expand All @@ -122,7 +124,7 @@ extension FSDataUsageTracking {
TroubleshootingHit(pVisitorId: visitor.visitorId, pLabel: label, pSpeceficCustomFields: criticalJson))
}

// TS on Fetching
// Troubleshooting on Fetching
func processTSFetching(v: FSVisitor, campaigns: FSCampaigns?) {
var criticalJson: [String: String] = ["visitor.sessionId": _visitorSessionId,
"visitor.visitorId": v.visitorId,
Expand All @@ -145,11 +147,12 @@ extension FSDataUsageTracking {
sendTroubleshootingReport(_trHit: TroubleshootingHit(
pVisitorId: v.visitorId, pLabel: CriticalPoints.VISITOR_FETCH_CAMPAIGNS.rawValue, pSpeceficCustomFields: criticalJson))
}


// Process on authenticate
func processTSXPC(label: String, visitor: FSVisitor) {
var criticalJson: [String: String] = [:]

// Create trio ids
// Create ids
let visitorIds = ["visitor.sessionId": _visitorSessionId,
"visitor.visitorId": visitor.visitorId,
"visitor.anonymousId": visitor.anonymousId ?? "null"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ extension FSDataUsageTracking {

let hashAlloc = Int(MurmurHash3.hash32(key: combinedId) % 100)

FlagshipLogManager.Log(level: .DEBUG, tag: .VISITOR, messageToDisplay: FSLogMessage.MESSAGE("The hash allocation for TR bucket is \(hashAlloc) ------------"))

let traf: Int = (_troubleshooting?.traffic ?? 0)

FlagshipLogManager.Log(level: .DEBUG, tag: .VISITOR, messageToDisplay: FSLogMessage.MESSAGE("The range allocation for TR bucket is \(traf) ------------"))

return hashAlloc <= (_troubleshooting?.traffic ?? 0)
} else {
return false
Expand Down Expand Up @@ -95,7 +89,7 @@ extension FSDataUsageTracking {
if error != nil {
FlagshipLogManager.Log(level: .ERROR, tag: .TRACKING, messageToDisplay: FSLogMessage.MESSAGE("Failed to send troubleshoting report : \(error.debugDescription)"))
} else {
FlagshipLogManager.Log(level: .DEBUG, tag: .TRACKING, messageToDisplay: FSLogMessage.MESSAGE("Sucess to send troubleshoting report"))
FlagshipLogManager.Log(level: .DEBUG, tag: .TRACKING, messageToDisplay: FSLogMessage.MESSAGE("Success to send troubleshoting report"))
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions FlagShip/Source/Troubleshooting/FSDataUsageTracking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class FSDataUsageTracking {
_visitorSessionId = FSTools.generateUuidv4()
}

// Configure with params
func configure(visitorId: String, hasConsented: Bool, config: FlagshipConfig, troubleshooting: FSTroubleshooting) {
_visitorId = visitorId
_hasConsented = hasConsented
Expand All @@ -52,6 +53,7 @@ class FSDataUsageTracking {
evaluateDataUsageTrackingAllocated()
}

// Configure with visitor instance
func configureWithVisitor(pVisitor: FSVisitor) {
_visitorId = pVisitor.visitorId
_hasConsented = pVisitor.hasConsented
Expand All @@ -60,17 +62,18 @@ class FSDataUsageTracking {
evaluateDataUsageTrackingAllocated()
}

// Update TR settings
// Update Troubleshootings settings
func updateTroubleshooting(trblShooting: FSTroubleshooting?) {
_troubleshooting = trblShooting
// Re evaluate the conditions of datausagetracking
// Re evaluate the conditions of data usage tracking
evaluateTroubleShootingConditions()
}

func isVisitorHasConsented() -> Bool {
return _hasConsented
}

// Update the consent
func updateConsent(newValue: Bool) {
_hasConsented = newValue
evaluateTroubleShootingConditions()
Expand All @@ -83,6 +86,7 @@ class FSDataUsageTracking {
}
}

// Send the data usage tracking
func sendDataUsageReport(_duHit: FSDataUsageHit) {
if dataUsageTrackingReportAllowed {
sendDataReport(_duHit)
Expand Down

0 comments on commit 7c20006

Please sign in to comment.