Skip to content

Commit

Permalink
Fixed LIB-1462 (#855)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsneed authored Dec 6, 2019
1 parent 2c8971c commit 24abc1f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions Analytics/Classes/Integrations/SEGIntegrationsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extern NSString *_Nonnull SEGAnalyticsIntegrationDidStart;
@interface SEGIntegrationsManager : NSObject

// Exposed for testing.
+ (BOOL)isIntegration:(NSString *_Nonnull)key enabledInOptions:(NSDictionary *_Nonnull)options;
+ (BOOL)isTrackEvent:(NSString *_Nonnull)event enabledForIntegration:(NSString *_Nonnull)key inPlan:(NSDictionary *_Nonnull)plan;

// @Deprecated - Exposing for backward API compat reasons only
Expand Down
14 changes: 13 additions & 1 deletion Analytics/Classes/Integrations/SEGIntegrationsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,19 @@ + (BOOL)isIntegration:(NSString *)key enabledInOptions:(NSDictionary *)options
return YES;
}
if (options[key]) {
return [options[key] boolValue];
id value = options[key];

// it's been observed that customers sometimes override this with
// value's that aren't bool types.
if ([value isKindOfClass:[NSNumber class]]) {
NSNumber *numberValue = (NSNumber *)value;
return [numberValue boolValue];
} else {
NSString *msg = [NSString stringWithFormat: @"Value for `%@` in integration options is supposed to be a boolean and it is not!"
"This is likely due to a user-added value in `integrations` that overwrites a value received from the server", key];
SEGLog(msg);
NSAssert(NO, msg);
}
} else if (options[@"All"]) {
return [options[@"All"] boolValue];
} else if (options[@"all"]) {
Expand Down
35 changes: 35 additions & 0 deletions AnalyticsTests/IntegrationsManagerTest.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,48 @@
import Analytics
import Quick
import Nimble
import SwiftTryCatch

class IntegrationsManagerTest: QuickSpec {

override func spec() {
describe("IntegrationsManager") {
context("is track event enabled for integration in plan") {

it("asserts when invalid value types are used integration enablement flags") {
var exception: NSException? = nil
SwiftTryCatch.tryRun({
SEGIntegrationsManager.isIntegration("comScore", enabledInOptions: ["comScore": "blah"])
}, catchRun: { e in
exception = e
}, finallyRun: nil)

expect(exception).toNot(beNil())
}

it("asserts when invalid value types are used integration enablement flags") {
var exception: NSException? = nil
SwiftTryCatch.tryRun({
SEGIntegrationsManager.isIntegration("comScore", enabledInOptions: ["comScore": ["key": 1]])
}, catchRun: { e in
exception = e
}, finallyRun: nil)

expect(exception).toNot(beNil())
}

it("pulls valid integration data when supplied") {
let enabled = SEGIntegrationsManager.isIntegration("comScore", enabledInOptions: ["comScore": true])
expect(enabled).to(beTrue())
}

it("falls back correctly when values aren't explicitly specified") {
let enabled = SEGIntegrationsManager.isIntegration("comScore", enabledInOptions: ["all": true])
expect(enabled).to(beTrue())
let allEnabled = SEGIntegrationsManager.isIntegration("comScore", enabledInOptions: ["All": true])
expect(allEnabled).to(beTrue())
}

it("returns true when there is no plan") {
let enabled = SEGIntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Amplitude", inPlan:[:])
expect(enabled).to(beTrue())
Expand Down

0 comments on commit 24abc1f

Please sign in to comment.