mirror of
https://github.com/firebase/firebase-ios-sdk
synced 2026-11-10 22:45:59 +05:45
* Move display SDK source and resources into FIAM SDK * Change files prefixed with FID to be prefixed FIRIAM * Restructure example apps in firebase-ios-sdk directory * Fix directory structure for FIAM * Move proto files into base directory * Fix up proto files * Move unit test files to Firebase/InAppMessaging/Tests * Move FIRIAMSDKModeManagerTests and require app host in podspec * Move sample apps to tests folder * Add empty repo for FIAMDisplay that generates a warning * Fix up functional tests app * Fix up default UI test app * Re-generate protos * Add warning to remove display pod * Remove display podspec from .travis.yml * Remove trailing whitespace * Fix import in test app * Add changes to point to the default test app * Wrap iOS version conditionals * Add line in podspec about deprecation * Delete whitespace in podspec * Delete pods section in project file * Update changelog with consolidation info * Fix indentation in podspecs * Fix some import issues * Fix indent on FirebaseInAppMessaging.podspec * Delete FirebaseInAppMessagingDisplay, update podfile for external test app * Update podfiles, bump iOS min version to 9, remove iOS 9 checks in FIRIAMActionUrlFollowerTests * Add line in CHANGELOG referencing deletion of display sdk pod * Remove unused podfile * Update min version on Podfiles to iOS 9 * Add back FirebaseInAppMessagingDisplay.h * Add iOS support message to CHANGELOG.md * Wrap necessary deprecated iOS 9 call
235 lines
9.0 KiB
Objective-C
235 lines
9.0 KiB
Objective-C
/*
|
|
* Copyright 2018 Google
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#import <OCMock/OCMock.h>
|
|
#import <XCTest/XCTest.h>
|
|
|
|
#import "FIRIAMAnalyticsEventLoggerImpl.h"
|
|
#import "FIRIAMClearcutLogger.h"
|
|
|
|
#import <FirebaseAnalyticsInterop/FIRAnalyticsInterop.h>
|
|
#import <FirebaseAnalyticsInterop/FIRInteropEventNames.h>
|
|
#import <FirebaseAnalyticsInterop/FIRInteropParameterNames.h>
|
|
|
|
@interface FIRIAMAnalyticsEventLoggerImplTests : XCTestCase
|
|
@property(nonatomic) FIRIAMClearcutLogger *mockClearcutLogger;
|
|
@property(nonatomic) id<FIRIAMTimeFetcher> mockTimeFetcher;
|
|
@property(nonatomic) id mockFirebaseAnalytics;
|
|
@property(nonatomic) NSUserDefaults *mockUserDefaults;
|
|
|
|
@end
|
|
|
|
static NSString *campaignID = @"campaign id";
|
|
static NSString *campaignName = @"campaign name";
|
|
|
|
typedef void (^FIRAUserPropertiesCallback)(NSDictionary *userProperties);
|
|
|
|
typedef void (^FakeAnalyticsLogEventHandler)(NSString *origin,
|
|
NSString *name,
|
|
NSDictionary *parameters);
|
|
typedef void (^FakeAnalyticsUserPropertyHandler)(NSString *origin, NSString *name, id value);
|
|
typedef void (^LastNotificationCallback)(NSString *);
|
|
typedef void (^FakeAnalyticsLastNotificationHandler)(NSString *origin, LastNotificationCallback);
|
|
|
|
@interface FakeAnalytics : NSObject <FIRAnalyticsInterop>
|
|
|
|
@property FakeAnalyticsLogEventHandler eventHandler;
|
|
@property FakeAnalyticsLogEventHandler userPropertyHandler;
|
|
@property FakeAnalyticsLastNotificationHandler lastNotificationHandler;
|
|
|
|
- (instancetype)initWithEventHandler:(FakeAnalyticsLogEventHandler)eventHandler;
|
|
- (instancetype)initWithUserPropertyHandler:(FakeAnalyticsUserPropertyHandler)userPropertyHandler;
|
|
@end
|
|
|
|
@implementation FakeAnalytics
|
|
|
|
- (instancetype)initWithEventHandler:(FakeAnalyticsLogEventHandler)eventHandler {
|
|
self = [super init];
|
|
if (self) {
|
|
_eventHandler = eventHandler;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (instancetype)initWithUserPropertyHandler:(FakeAnalyticsUserPropertyHandler)userPropertyHandler {
|
|
self = [super init];
|
|
if (self) {
|
|
_userPropertyHandler = userPropertyHandler;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)logEventWithOrigin:(nonnull NSString *)origin
|
|
name:(nonnull NSString *)name
|
|
parameters:(nullable NSDictionary<NSString *, id> *)parameters {
|
|
if (_eventHandler) {
|
|
_eventHandler(origin, name, parameters);
|
|
}
|
|
}
|
|
|
|
- (void)setUserPropertyWithOrigin:(nonnull NSString *)origin
|
|
name:(nonnull NSString *)name
|
|
value:(nonnull id)value {
|
|
if (_userPropertyHandler) {
|
|
_userPropertyHandler(origin, name, value);
|
|
}
|
|
}
|
|
|
|
- (void)checkLastNotificationForOrigin:(nonnull NSString *)origin
|
|
queue:(nonnull dispatch_queue_t)queue
|
|
callback:(nonnull void (^)(NSString *_Nullable))
|
|
currentLastNotificationProperty {
|
|
if (_lastNotificationHandler) {
|
|
_lastNotificationHandler(origin, currentLastNotificationProperty);
|
|
}
|
|
}
|
|
|
|
// Stubs
|
|
- (void)clearConditionalUserProperty:(nonnull NSString *)userPropertyName
|
|
clearEventName:(nonnull NSString *)clearEventName
|
|
clearEventParameters:(nonnull NSDictionary *)clearEventParameters {
|
|
}
|
|
|
|
- (NSInteger)maxUserProperties:(nonnull NSString *)origin {
|
|
return -1;
|
|
}
|
|
|
|
- (void)registerAnalyticsListener:(nonnull id<FIRAnalyticsInteropListener>)listener
|
|
withOrigin:(nonnull NSString *)origin {
|
|
}
|
|
|
|
- (void)unregisterAnalyticsListenerWithOrigin:(nonnull NSString *)origin {
|
|
}
|
|
|
|
- (void)clearConditionalUserProperty:(nonnull NSString *)userPropertyName
|
|
forOrigin:(nonnull NSString *)origin
|
|
clearEventName:(nonnull NSString *)clearEventName
|
|
clearEventParameters:
|
|
(nonnull NSDictionary<NSString *, NSString *> *)clearEventParameters {
|
|
}
|
|
|
|
- (nonnull NSArray<NSDictionary<NSString *, NSString *> *> *)
|
|
conditionalUserProperties:(nonnull NSString *)origin
|
|
propertyNamePrefix:(nonnull NSString *)propertyNamePrefix {
|
|
return nil;
|
|
}
|
|
|
|
- (void)setConditionalUserProperty:(nonnull NSDictionary<NSString *, id> *)conditionalUserProperty {
|
|
}
|
|
|
|
- (void)getUserPropertiesWithCallback:(nonnull FIRAInteropUserPropertiesCallback)callback {
|
|
}
|
|
@end
|
|
|
|
@implementation FIRIAMAnalyticsEventLoggerImplTests
|
|
|
|
- (void)setUp {
|
|
[super setUp];
|
|
self.mockClearcutLogger = OCMClassMock(FIRIAMClearcutLogger.class);
|
|
self.mockTimeFetcher = OCMProtocolMock(@protocol(FIRIAMTimeFetcher));
|
|
self.mockUserDefaults = OCMClassMock(NSUserDefaults.class);
|
|
}
|
|
|
|
- (void)tearDown {
|
|
[super tearDown];
|
|
}
|
|
|
|
- (void)testLogImpressionEvent {
|
|
XCTestExpectation *expectation1 = [self expectationWithDescription:@"Log to Analytics"];
|
|
FakeAnalytics *analytics = [[FakeAnalytics alloc]
|
|
initWithEventHandler:^(NSString *origin, NSString *name, NSDictionary *parameters) {
|
|
XCTAssertEqualObjects(origin, @"fiam");
|
|
XCTAssertEqualObjects(name, @"firebase_in_app_message_impression");
|
|
XCTAssertEqual([parameters count], 3);
|
|
XCTAssertNotNil(parameters);
|
|
XCTAssertEqual(parameters[@"_nmid"], campaignID);
|
|
XCTAssertEqual(parameters[@"_nmn"], campaignName);
|
|
[expectation1 fulfill];
|
|
}];
|
|
FIRIAMAnalyticsEventLoggerImpl *logger =
|
|
[[FIRIAMAnalyticsEventLoggerImpl alloc] initWithClearcutLogger:self.mockClearcutLogger
|
|
usingTimeFetcher:self.mockTimeFetcher
|
|
usingUserDefaults:nil
|
|
analytics:analytics];
|
|
|
|
NSTimeInterval currentMoment = 10000;
|
|
OCMStub([self.mockTimeFetcher currentTimestampInSeconds]).andReturn(currentMoment);
|
|
|
|
OCMExpect([self.mockClearcutLogger
|
|
logAnalyticsEventForType:FIRIAMAnalyticsEventMessageImpression
|
|
forCampaignID:[OCMArg isEqual:campaignID]
|
|
withCampaignName:[OCMArg isEqual:campaignName]
|
|
eventTimeInMs:[OCMArg isNil]
|
|
completion:([OCMArg invokeBlockWithArgs:@YES, nil])]);
|
|
|
|
XCTestExpectation *expectation2 =
|
|
[self expectationWithDescription:@"Completion Callback Triggered"];
|
|
[logger logAnalyticsEventForType:FIRIAMAnalyticsEventMessageImpression
|
|
forCampaignID:campaignID
|
|
withCampaignName:campaignName
|
|
eventTimeInMs:nil
|
|
completion:^(BOOL success) {
|
|
[expectation2 fulfill];
|
|
}];
|
|
[self waitForExpectationsWithTimeout:1.0 handler:nil];
|
|
}
|
|
|
|
- (void)testLogActionEvent {
|
|
XCTestExpectation *expectation1 = [self expectationWithDescription:@"Log to Analytics"];
|
|
FakeAnalytics *analytics = [[FakeAnalytics alloc]
|
|
initWithEventHandler:^(NSString *origin, NSString *name, NSDictionary *parameters) {
|
|
XCTAssertEqualObjects(origin, @"fiam");
|
|
XCTAssertEqualObjects(name, @"firebase_in_app_message_action");
|
|
XCTAssertEqual([parameters count], 3);
|
|
XCTAssertNotNil(parameters);
|
|
XCTAssertEqual(parameters[@"_nmid"], campaignID);
|
|
XCTAssertEqual(parameters[@"_nmn"], campaignName);
|
|
[expectation1 fulfill];
|
|
}];
|
|
|
|
FIRIAMAnalyticsEventLoggerImpl *logger =
|
|
[[FIRIAMAnalyticsEventLoggerImpl alloc] initWithClearcutLogger:self.mockClearcutLogger
|
|
usingTimeFetcher:self.mockTimeFetcher
|
|
usingUserDefaults:self.mockUserDefaults
|
|
analytics:analytics];
|
|
|
|
NSTimeInterval currentMoment = 10000;
|
|
OCMStub([self.mockTimeFetcher currentTimestampInSeconds]).andReturn(currentMoment);
|
|
|
|
OCMExpect([self.mockClearcutLogger
|
|
logAnalyticsEventForType:FIRIAMAnalyticsEventActionURLFollow
|
|
forCampaignID:[OCMArg isEqual:campaignID]
|
|
withCampaignName:[OCMArg isEqual:campaignName]
|
|
eventTimeInMs:[OCMArg isNil]
|
|
completion:([OCMArg invokeBlockWithArgs:@YES, nil])]);
|
|
|
|
XCTestExpectation *expectation2 =
|
|
[self expectationWithDescription:@"Completion Callback Triggered"];
|
|
|
|
[logger logAnalyticsEventForType:FIRIAMAnalyticsEventActionURLFollow
|
|
forCampaignID:campaignID
|
|
withCampaignName:campaignName
|
|
eventTimeInMs:nil
|
|
completion:^(BOOL success) {
|
|
[expectation2 fulfill];
|
|
}];
|
|
|
|
[self waitForExpectationsWithTimeout:2.0 handler:nil];
|
|
OCMVerifyAll((id)self.mockClearcutLogger);
|
|
}
|
|
|
|
@end
|