2 // CKKSLaunchSequenceTests.m
5 #import <XCTest/XCTest.h>
6 #import <OCMock/OCMock.h>
7 #import "keychain/analytics/CKKSLaunchSequence.h"
8 #import <utilities/SecCoreAnalytics.h>
11 @interface CKKSLaunchSequenceTests : XCTestCase
12 @property (strong) XCTestExpectation *launchExpection;
15 @implementation CKKSLaunchSequenceTests
17 - (void)mockSendEvent:(NSDictionary *)name event:(NSDictionary *)event {
18 NSLog(@"CAEvent: %@", event);
19 [self.launchExpection fulfill];
24 id credentialStoreMock = OCMClassMock([SecCoreAnalytics class]);
25 OCMStub([credentialStoreMock sendEvent:[OCMArg any] event:[OCMArg any]]).andCall(self, @selector(mockSendEvent:event:));
27 CKKSLaunchSequence *launch = [[CKKSLaunchSequence alloc] initWithRocketName:@"rocket"];
28 [launch addEvent:@"keyword1"];
30 [launch addEvent:@"keyword2"];
31 [launch addAttribute:@"attribute" value:@"value"];
33 self.launchExpection = [self expectationWithDescription:@"launch"];
37 [self waitForExpectations:@[self.launchExpection] timeout:0.2];
39 self.launchExpection = [self expectationWithDescription:@"launch"];
40 self.launchExpection.inverted = true;
44 [self waitForExpectations:@[self.launchExpection] timeout:0.2];
45 self.launchExpection = nil;
47 NSArray *res = [launch eventsByTime];
48 XCTAssert(res.count > 0, "should have event");
50 for (NSString *event in res) {
51 found |= [event hasPrefix:@"attr:"];
53 XCTAssert(found, "should have an attribute");