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

Fixed LIB-1462 #855

Merged
merged 1 commit into from
Dec 6, 2019
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
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