|
9 | 9 | // https://github.com/Specta/Specta |
10 | 10 |
|
11 | 11 | #import "SEGPayloadBuilder.h" |
| 12 | +#import <MixpanelGroup.h> |
12 | 13 |
|
13 | 14 | SpecBegin(InitialSpecs) |
14 | 15 |
|
15 | 16 | describe(@"Mixpanel Integration", ^{ |
16 | 17 | __block SEGMixpanelIntegration *integration; |
17 | 18 | __block Mixpanel *mixpanel; |
18 | 19 | __block MixpanelPeople *mixpanelPeople; |
| 20 | + __block MixpanelGroup *mixpanelGroup; |
19 | 21 |
|
20 | 22 | beforeEach(^{ |
21 | 23 | mixpanel = mock([Mixpanel class]); |
22 | 24 | mixpanelPeople = mock([MixpanelPeople class]); |
23 | 25 | [given([mixpanel people]) willReturn:mixpanelPeople]; |
24 | | - |
| 26 | + |
| 27 | + mixpanelGroup = mock([MixpanelGroup class]); |
| 28 | + |
25 | 29 | integration = [[SEGMixpanelIntegration alloc] initWithSettings:@{ |
26 | 30 | @"trackAllPages" : @1, |
27 | | - @"setAllTraitsByDefault" : @1 |
| 31 | + @"setAllTraitsByDefault" : @1, |
| 32 | + @"groupIdentifierTraits" : @[@"group_id", @"group_name", @"group_idtest2"] |
28 | 33 | } andMixpanel:mixpanel]; |
29 | 34 | }); |
30 | 35 |
|
|
118 | 123 | @"age" : @24 |
119 | 124 | }]; |
120 | 125 | }); |
| 126 | + |
| 127 | + |
| 128 | + it(@"simple group", ^{ |
| 129 | + NSDictionary *groupTraits = @{ |
| 130 | + @"groupCity" : @"Cairo", |
| 131 | + @"group_name" : @"mixPanelTest1Group" |
| 132 | + }; |
| 133 | + [integration group:[SEGPayloadBuilder group:@"groupTest1" withTraits:groupTraits]]; |
| 134 | + |
| 135 | + NSDictionary *groupIdentifierTraits = integration.settings[@"groupIdentifierTraits"]; |
| 136 | + |
| 137 | + for (NSString *identifierTrait in groupIdentifierTraits) { |
| 138 | + NSString *groupIdentifierVal = groupTraits[identifierTrait]; |
| 139 | + if (groupIdentifierVal) { |
| 140 | + [verify(mixpanel) getGroup:groupIdentifierVal groupID:@"groupTest1"]; |
| 141 | + } |
| 142 | + |
| 143 | + } |
| 144 | + |
| 145 | + }); |
| 146 | + |
| 147 | + it(@"complex group", ^{ |
| 148 | + NSDictionary *groupTraits = @{ |
| 149 | + @"groupCity" : @"Alexandria", |
| 150 | + @"name" : @"mixPanelTest1Group", |
| 151 | + @"address": @{@"city": @"Alexandria", @"postalCode": @"22314", @"state":@"Virginia", @"street": @"105 N Union St" }, |
| 152 | + @"description": @"Art Center", |
| 153 | + @"avatar" : @"https://gravatar.com/avatar/f8b72def445675a558fe68b1cb651da1?s=400&d=robohash&r=x" |
| 154 | + }; |
| 155 | + [integration group:[SEGPayloadBuilder group:@"groupTest1" withTraits:groupTraits]]; |
| 156 | + |
| 157 | + NSDictionary *groupIdentifierTraits = integration.settings[@"groupIdentifierTraits"]; |
| 158 | + |
| 159 | + for (NSString *identifierTrait in groupIdentifierTraits) { |
| 160 | + NSString *groupIdentifierVal = groupTraits[identifierTrait]; |
| 161 | + if (groupIdentifierVal) { |
| 162 | + [verify(mixpanel) getGroup:groupIdentifierVal groupID:@"groupTest1"]; |
| 163 | + } |
| 164 | + |
| 165 | + } |
| 166 | + |
| 167 | + }); |
121 | 168 |
|
| 169 | + it(@"simple group without name", ^{ |
| 170 | + NSDictionary *groupTraits = @{ |
| 171 | + @"groupCity" : @"Cairo" |
| 172 | + }; |
| 173 | + [integration group:[SEGPayloadBuilder group:@"groupTest2" withTraits:groupTraits]]; |
| 174 | + |
| 175 | + NSDictionary *groupIdentifierTraits = integration.settings[@"groupIdentifierTraits"]; |
| 176 | + |
| 177 | + for (NSString *identifierTrait in groupIdentifierTraits) { |
| 178 | + NSString *groupIdentifierVal = groupTraits[identifierTrait]; |
| 179 | + [given([mixpanel getGroup:groupIdentifierVal groupID:@"groupTest2"]) willReturn:nil]; |
| 180 | + |
| 181 | + } |
| 182 | + }); |
| 183 | + |
| 184 | + it(@"simple group setOnce traits", ^{ |
| 185 | + [given([mixpanel getGroup:@"test1" groupID:@"groupTest2"]) willReturn:mixpanelGroup]; |
| 186 | + NSDictionary *groupTraits = @{ |
| 187 | + @"groupCity" : @"Cairo", |
| 188 | + @"groupCount" : @"20", |
| 189 | + @"group_id" : @"test1" |
| 190 | + }; |
| 191 | + [integration group:[SEGPayloadBuilder group:@"groupTest2" withTraits:groupTraits]]; |
| 192 | + |
| 193 | + [verify(mixpanelGroup) setOnce:groupTraits]; |
| 194 | + [verify(mixpanel) getGroup:@"test1" groupID:@"groupTest2"]; |
| 195 | + }); |
| 196 | + |
122 | 197 | it(@"alias", ^{ |
123 | 198 | [given([mixpanel distinctId]) willReturn:@"123456"]; |
124 | 199 | [integration alias:[SEGPayloadBuilder alias:@"prateek"]]; |
|
0 commit comments