Skip to content

Commit

Permalink
Merge branch 'release/4.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
matus-tomlein committed Sep 1, 2022
2 parents dc5ecb6 + 596b07d commit 949afe0
Show file tree
Hide file tree
Showing 59 changed files with 1,061 additions and 166 deletions.
16 changes: 7 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
fail-fast: false
matrix:
version:
- {ios: 14.4, iphone: iPhone 11, watchos: 7.2, watch: Apple Watch Series 5 - 44mm, macos: '10.15', xcode: 12.4}
- {ios: 12.4, iphone: iPhone 5s, watchos: 5.3, watch: Apple Watch Series 2 - 38mm, macos: 10.15, xcode: 10.3}
- {ios: 15.5, iphone: iPhone 12 Pro, watchos: 8.5, watch: Apple Watch Series 5 - 44mm, macos: '12', xcode: 13.4}
- {ios: 14.4, iphone: iPhone 8, watchos: 7.2, watch: Apple Watch Series 4 - 40mm, macos: '11', xcode: 12.4}

steps:
- name: Checkout
Expand All @@ -41,8 +41,8 @@ jobs:
fail-fast: false
matrix:
version:
- {ios: '14.4', iphone: iPhone 11, watchos: '7.2', watch: Apple Watch Series 5 - 44mm, macos: '10.15', xcode: 12.4}
- {ios: 12.4, iphone: iPhone 5s, watchos: 5.3, watch: Apple Watch Series 2 - 38mm, macos: 10.15, xcode: 10.3}
- {ios: 15.5, iphone: iPhone 12 Pro, watchos: 8.5, watch: Apple Watch Series 5 - 44mm, macos: '12', xcode: 13.4}
- {ios: 14.4, iphone: iPhone 8, watchos: 7.2, watch: Apple Watch Series 4 - 40mm, macos: '11', xcode: 12.4}

steps:
- name: Checkout
Expand Down Expand Up @@ -83,8 +83,7 @@ jobs:
fail-fast: false
matrix:
version:
- {ios: '14.4', iphone: iPhone 11, watchos: '7.2', watch: Apple Watch Series 5 - 44mm, macos: '10.15', xcode: 12.4}
#- {ios: 12.4, iphone: iPhone 5s, watchos: 5.3, watch: Apple Watch Series 2 - 38mm, macos: 10.15, xcode: 10.3}
- {ios: '14.4', iphone: iPhone 11, watchos: '7.2', watch: Apple Watch Series 5 - 44mm, macos: '11', xcode: 12.4}

steps:
- name: Checkout
Expand Down Expand Up @@ -132,8 +131,7 @@ jobs:
fail-fast: false
matrix:
version:
- {ios: '14.4', iphone: iPhone 12 Pro, watchos: '7.2', watch: Apple Watch Series 5 - 44mm, macos: '10.15', xcode: 12.4}
#- {ios: 12.4, iphone: iPhone Xs Max, watchos: 5.3, watch: Apple Watch Series 2 - 38mm, macos: 10.15, xcode: 10.3}
- {ios: '14.4', iphone: iPhone 12 Pro, watchos: '7.2', watch: Apple Watch Series 5 - 44mm, macos: '11', xcode: 12.4}
podfile:
- {file: Podfile, type: "no directive"}
- {file: Podfile_frameworks, type: "use_frameworks! directive"}
Expand Down Expand Up @@ -178,7 +176,7 @@ jobs:
fail-fast: false
matrix:
version:
- {ios: '14.4', iphone: iPhone 11 Pro, watchos: '7.2', watch: Apple Watch Series 5 - 44mm, macos: '10.15', xcode: 12.4}
- {ios: '14.4', iphone: iPhone 11 Pro, watchos: '7.2', watch: Apple Watch Series 5 - 44mm, macos: '11', xcode: 12.4}

steps:
- name: Checkout
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
Version 4.0.0 (2022-09-01)
--------------------------
Do not resume remote configuration from cache in case it has different endpoint (#688)
Fix too many events tracked by screen view autotracking (#689)
Ignore trailing slashes in the network configuration endpoint (#695)
Add interface to subscribe for events tracked in Web views (#691)
Add anonymous tracking features (#702)
Return tracked event ID from the track method (#710)
Extend the onSuccess callback when setting up remote configuration to pass configuration state (#694)
Add support for tracking events in a Share Extension (#700) (thanks to @onato)
Fix default session timeout values to 30 minutes everywhere (#708)
Upgrade deprecated macOS and XCode versions in Github actions (#696)

Version 3.2.0 (2022-06-28)
--------------------------
Add eventIndex and firstEventTimestamp properties to client sessions (#682)
Expand Down
11 changes: 11 additions & 0 deletions Snowplow iOSTests/Configurations/TestEmitterConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,16 @@ - (void)testPauseEmitter {
XCTAssertEqual(0, [[tracker emitter] dbCount]);
}

- (void)testActivatesServerAnonymisationInEmitter {
SPEmitterConfiguration *emitterConfig = [[SPEmitterConfiguration alloc] init];
emitterConfig.serverAnonymisation = YES;

SPNetworkConfiguration *networkConfig = [[SPNetworkConfiguration alloc] initWithEndpoint:@"" method:SPHttpMethodPost];

id<SPTrackerController> tracker = [SPSnowplow createTrackerWithNamespace:@"namespace" network:networkConfig configurations:@[emitterConfig]];

XCTAssertTrue(tracker.emitter.serverAnonymisation);
}


@end
87 changes: 66 additions & 21 deletions Snowplow iOSTests/Configurations/TestRemoteConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ - (void)testDownloadConfiguration {
XCTestExpectation *expectation = [XCTestExpectation new];

SPRemoteConfiguration *remoteConfig = [[SPRemoteConfiguration alloc] initWithEndpoint:endpoint method:SPHttpMethodGet];
[[SPConfigurationFetcher alloc] initWithRemoteSource:remoteConfig onFetchCallback:^(SPFetchedConfigurationBundle * _Nonnull fetchedConfigurationBundle) {
[[SPConfigurationFetcher alloc] initWithRemoteSource:remoteConfig onFetchCallback:^(SPFetchedConfigurationBundle * _Nonnull fetchedConfigurationBundle, SPConfigurationState configurationState) {
XCTAssertNotNil(fetchedConfigurationBundle);
XCTAssertEqualObjects(@"http://iglucentral.com/schemas/com.snowplowanalytics.mobile/remote_config/jsonschema/1-0-0", fetchedConfigurationBundle.schema);
XCTAssertEqual(SPConfigurationStateFetched, configurationState);
[expectation fulfill];
}];

Expand All @@ -103,13 +104,15 @@ - (void)testConfigurationCache {
expected.configurationVersion = 12;
expected.configurationBundle = @[bundle];

SPConfigurationCache *cache = [SPConfigurationCache new];
SPRemoteConfiguration *remoteConfig = [[SPRemoteConfiguration alloc] initWithEndpoint:@"http://example.com" method:SPHttpMethodGet];

SPConfigurationCache *cache = [[SPConfigurationCache alloc] initWithRemoteConfiguration:remoteConfig];
[cache clearCache];
[cache writeCache:expected];

[NSThread sleepForTimeInterval:5]; // wait the config is written on cache.

cache = [SPConfigurationCache new];
cache = [[SPConfigurationCache alloc] initWithRemoteConfiguration:remoteConfig];
SPFetchedConfigurationBundle *config = [cache readCache];

XCTAssertEqual(expected.configurationVersion, config.configurationVersion);
Expand All @@ -124,17 +127,17 @@ - (void)testConfigurationCache {
- (void)testConfigurationProvider_notDownloading_fails {
// prepare test
NSString *endpoint = @"https://fake-snowplowanalytics.com/config.json";
SPConfigurationCache *cache = [SPConfigurationCache new];
SPRemoteConfiguration *remoteConfig = [[SPRemoteConfiguration alloc] initWithEndpoint:endpoint method:SPHttpMethodGet];
SPConfigurationCache *cache = [[SPConfigurationCache alloc] initWithRemoteConfiguration:remoteConfig];
[cache clearCache];
[[LSNocilla sharedInstance] start];
stubRequest(@"GET", endpoint)
.andReturn(404);

// test
XCTestExpectation *expectation = [XCTestExpectation new];
SPRemoteConfiguration *remoteConfig = [[SPRemoteConfiguration alloc] initWithEndpoint:endpoint method:SPHttpMethodGet];
SPConfigurationProvider *provider = [[SPConfigurationProvider alloc] initWithRemoteConfiguration:remoteConfig];
[provider retrieveConfigurationOnlyRemote:NO onFetchCallback:^(SPFetchedConfigurationBundle * _Nonnull fetchedConfigurationBundle) {
[provider retrieveConfigurationOnlyRemote:NO onFetchCallback:^(SPFetchedConfigurationBundle * _Nonnull fetchedConfigurationBundle, SPConfigurationState configurationState) {
XCTFail();
}];
XCTWaiterResult result = [XCTWaiter waitForExpectations:@[expectation] timeout:5];
Expand All @@ -147,7 +150,8 @@ - (void)testConfigurationProvider_notDownloading_fails {
- (void)testConfigurationProvider_downloadOfWrongSchema_fails {
// prepare test
NSString *endpoint = @"https://fake-snowplowanalytics.com/config.json";
SPConfigurationCache *cache = [SPConfigurationCache new];
SPRemoteConfiguration *remoteConfig = [[SPRemoteConfiguration alloc] initWithEndpoint:endpoint method:SPHttpMethodGet];
SPConfigurationCache *cache = [[SPConfigurationCache alloc] initWithRemoteConfiguration:remoteConfig];
[cache clearCache];
[[LSNocilla sharedInstance] start];
stubRequest(@"GET", endpoint)
Expand All @@ -157,9 +161,8 @@ - (void)testConfigurationProvider_downloadOfWrongSchema_fails {

// test
XCTestExpectation *expectation = [XCTestExpectation new];
SPRemoteConfiguration *remoteConfig = [[SPRemoteConfiguration alloc] initWithEndpoint:endpoint method:SPHttpMethodGet];
SPConfigurationProvider *provider = [[SPConfigurationProvider alloc] initWithRemoteConfiguration:remoteConfig];
[provider retrieveConfigurationOnlyRemote:NO onFetchCallback:^(SPFetchedConfigurationBundle * _Nonnull fetchedConfigurationBundle) {
[provider retrieveConfigurationOnlyRemote:NO onFetchCallback:^(SPFetchedConfigurationBundle * _Nonnull fetchedConfigurationBundle, SPConfigurationState configurationState) {
XCTFail();
}];
XCTWaiterResult result = [XCTWaiter waitForExpectations:@[expectation] timeout:5];
Expand All @@ -172,8 +175,9 @@ - (void)testConfigurationProvider_downloadOfWrongSchema_fails {
- (void)testConfigurationProvider_downloadSameConfigVersionThanCached_dontUpdate {
// prepare test
NSString *endpoint = @"https://fake-snowplowanalytics.com/config.json";
SPRemoteConfiguration *remoteConfig = [[SPRemoteConfiguration alloc] initWithEndpoint:endpoint method:SPHttpMethodGet];

SPConfigurationCache *cache = [SPConfigurationCache new];
SPConfigurationCache *cache = [[SPConfigurationCache alloc] initWithRemoteConfiguration:remoteConfig];
[cache clearCache];
SPConfigurationBundle *bundle = [[SPConfigurationBundle alloc] initWithNamespace:@"namespace" networkConfiguration:[[SPNetworkConfiguration alloc] initWithEndpoint:@"endpoint"]];
SPFetchedConfigurationBundle *cached = [[SPFetchedConfigurationBundle alloc] init];
Expand All @@ -191,10 +195,10 @@ - (void)testConfigurationProvider_downloadSameConfigVersionThanCached_dontUpdate

// test
XCTestExpectation *expectation = [XCTestExpectation new];
SPRemoteConfiguration *remoteConfig = [[SPRemoteConfiguration alloc] initWithEndpoint:endpoint method:SPHttpMethodGet];
SPConfigurationProvider *provider = [[SPConfigurationProvider alloc] initWithRemoteConfiguration:remoteConfig];
__block int i = 0;
[provider retrieveConfigurationOnlyRemote:NO onFetchCallback:^(SPFetchedConfigurationBundle * _Nonnull fetchedConfigurationBundle) {
[provider retrieveConfigurationOnlyRemote:NO onFetchCallback:^(SPFetchedConfigurationBundle * _Nonnull fetchedConfigurationBundle, SPConfigurationState configurationState) {
XCTAssertEqual(SPConfigurationStateCached, configurationState);
if (i == 1 || [fetchedConfigurationBundle.schema isEqualToString:@"http://iglucentral.com/schemas/com.snowplowanalytics.mobile/remote_config/jsonschema/1-1-0"]) {
XCTFail();
}
Expand All @@ -213,8 +217,9 @@ - (void)testConfigurationProvider_downloadSameConfigVersionThanCached_dontUpdate
- (void)testConfigurationProvider_downloadHigherConfigVersionThanCached_doUpdate {
// prepare test
NSString *endpoint = @"https://fake-snowplowanalytics.com/config.json";
SPRemoteConfiguration *remoteConfig = [[SPRemoteConfiguration alloc] initWithEndpoint:endpoint method:SPHttpMethodGet];

SPConfigurationCache *cache = [SPConfigurationCache new];
SPConfigurationCache *cache = [[SPConfigurationCache alloc] initWithRemoteConfiguration:remoteConfig];
[cache clearCache];
SPConfigurationBundle *bundle = [[SPConfigurationBundle alloc] initWithNamespace:@"namespace" networkConfiguration:[[SPNetworkConfiguration alloc] initWithEndpoint:@"endpoint"]];
SPFetchedConfigurationBundle *cached = [[SPFetchedConfigurationBundle alloc] init];
Expand All @@ -232,10 +237,11 @@ - (void)testConfigurationProvider_downloadHigherConfigVersionThanCached_doUpdate

// test
XCTestExpectation *expectation = [XCTestExpectation new];
SPRemoteConfiguration *remoteConfig = [[SPRemoteConfiguration alloc] initWithEndpoint:endpoint method:SPHttpMethodGet];
SPConfigurationProvider *provider = [[SPConfigurationProvider alloc] initWithRemoteConfiguration:remoteConfig];
__block int i = 0;
[provider retrieveConfigurationOnlyRemote:NO onFetchCallback:^(SPFetchedConfigurationBundle * _Nonnull fetchedConfigurationBundle) {
[provider retrieveConfigurationOnlyRemote:NO onFetchCallback:^(SPFetchedConfigurationBundle * _Nonnull fetchedConfigurationBundle, SPConfigurationState configurationState) {
XCTAssertEqual(i == 0 ? SPConfigurationStateCached : SPConfigurationStateFetched,
configurationState);
if (i == 1 && [fetchedConfigurationBundle.schema isEqualToString:@"http://iglucentral.com/schemas/com.snowplowanalytics.mobile/remote_config/jsonschema/1-1-0"]) {
i++;
}
Expand All @@ -254,8 +260,9 @@ - (void)testConfigurationProvider_downloadHigherConfigVersionThanCached_doUpdate
- (void)testConfigurationProvider_justRefresh_downloadSameConfigVersionThanCached_dontUpdate {
// prepare test
NSString *endpoint = @"https://fake-snowplowanalytics.com/config.json";
SPRemoteConfiguration *remoteConfig = [[SPRemoteConfiguration alloc] initWithEndpoint:endpoint method:SPHttpMethodGet];

SPConfigurationCache *cache = [SPConfigurationCache new];
SPConfigurationCache *cache = [[SPConfigurationCache alloc] initWithRemoteConfiguration:remoteConfig];
[cache clearCache];
SPConfigurationBundle *bundle = [[SPConfigurationBundle alloc] initWithNamespace:@"namespace" networkConfiguration:[[SPNetworkConfiguration alloc] initWithEndpoint:@"endpoint"]];
SPFetchedConfigurationBundle *cached = [[SPFetchedConfigurationBundle alloc] init];
Expand All @@ -265,10 +272,10 @@ - (void)testConfigurationProvider_justRefresh_downloadSameConfigVersionThanCache
[cache writeCache:cached];
[NSThread sleepForTimeInterval:5]; // wait to write on cache

SPRemoteConfiguration *remoteConfig = [[SPRemoteConfiguration alloc] initWithEndpoint:endpoint method:SPHttpMethodGet];
SPConfigurationProvider *provider = [[SPConfigurationProvider alloc] initWithRemoteConfiguration:remoteConfig];
XCTestExpectation *expectation = [XCTestExpectation new];
[provider retrieveConfigurationOnlyRemote:NO onFetchCallback:^(SPFetchedConfigurationBundle * _Nonnull fetchedConfigurationBundle) {
[provider retrieveConfigurationOnlyRemote:NO onFetchCallback:^(SPFetchedConfigurationBundle * _Nonnull fetchedConfigurationBundle, SPConfigurationState configurationState) {
XCTAssertEqual(SPConfigurationStateCached, configurationState);
[expectation fulfill];
}];
[self waitForExpectations:@[expectation] timeout:5];
Expand All @@ -281,7 +288,7 @@ - (void)testConfigurationProvider_justRefresh_downloadSameConfigVersionThanCache

// test
expectation = [XCTestExpectation new];
[provider retrieveConfigurationOnlyRemote:YES onFetchCallback:^(SPFetchedConfigurationBundle * _Nonnull fetchedConfigurationBundle) {
[provider retrieveConfigurationOnlyRemote:YES onFetchCallback:^(SPFetchedConfigurationBundle * _Nonnull fetchedConfigurationBundle, SPConfigurationState configurationState) {
XCTFail();
}];
XCTWaiterResult result = [XCTWaiter waitForExpectations:@[expectation] timeout:5];
Expand All @@ -291,13 +298,52 @@ - (void)testConfigurationProvider_justRefresh_downloadSameConfigVersionThanCache
[[LSNocilla sharedInstance] stop];
}

- (void)testDoesntUseCachedConfigurationIfDifferentRemoteEndpoint {
// prepare test
NSString *endpoint = @"https://fake-snowplowanalytics.com/config.json";
SPRemoteConfiguration *cachedRemoteConfig = [[SPRemoteConfiguration alloc] initWithEndpoint:@"https://cached-snowplowanalytics.com/config.json" method:SPHttpMethodGet];
SPRemoteConfiguration *remoteConfig = [[SPRemoteConfiguration alloc] initWithEndpoint:endpoint method:SPHttpMethodGet];

// write configuration (version 2) to cache
SPConfigurationCache *cache = [[SPConfigurationCache alloc] initWithRemoteConfiguration:cachedRemoteConfig];
[cache clearCache];
SPConfigurationBundle *bundle = [[SPConfigurationBundle alloc] initWithNamespace:@"namespace" networkConfiguration:[[SPNetworkConfiguration alloc] initWithEndpoint:@"endpoint"]];
SPFetchedConfigurationBundle *cached = [[SPFetchedConfigurationBundle alloc] init];
cached.schema = @"http://iglucentral.com/schemas/com.snowplowanalytics.mobile/remote_config/jsonschema/1-0-0";
cached.configurationVersion = 2;
cached.configurationBundle = @[bundle];
[cache writeCache:cached];
[NSThread sleepForTimeInterval:5]; // wait to write on cache

// stub request for configuration (return version 1)
[[LSNocilla sharedInstance] start];
stubRequest(@"GET", endpoint)
.andReturn(200)
.withHeaders(@{@"Content-Type": @"application/json"})
.withBody(@"{\"$schema\":\"http://iglucentral.com/schemas/com.snowplowanalytics.mobile/remote_config/jsonschema/1-1-0\",\"configurationVersion\":1,\"configurationBundle\":[]}");

// initialize tracker with remote config
XCTestExpectation *expectation = [XCTestExpectation new];
[[SPConfigurationFetcher alloc] initWithRemoteSource:remoteConfig onFetchCallback:^(SPFetchedConfigurationBundle * _Nonnull fetchedConfigurationBundle, SPConfigurationState configurationState) {
XCTAssertNotNil(fetchedConfigurationBundle);
// should be the non-cache configuration (version 1)
XCTAssertEqualObjects(@"http://iglucentral.com/schemas/com.snowplowanalytics.mobile/remote_config/jsonschema/1-1-0", fetchedConfigurationBundle.schema);
XCTAssertEqual(1, fetchedConfigurationBundle.configurationVersion);
[expectation fulfill];
}];

[self waitForExpectations:@[expectation] timeout:10];
[[LSNocilla sharedInstance] stop];
}

// TODO: Replace LSNocilla as it's unreliable and unsupported. It causes this test failure.
/*
- (void)testConfigurationProvider_justRefresh_downloadHigherConfigVersionThanCached_doUpdate {
// prepare test
NSString *endpoint = @"https://fake-snowplowanalytics.com/config.json";
SPRemoteConfiguration *remoteConfig = [[SPRemoteConfiguration alloc] initWithEndpoint:endpoint method:SPHttpMethodGet];
SPConfigurationCache *cache = [SPConfigurationCache new];
SPConfigurationCache *cache = [[SPConfigurationCache alloc] initWithRemoteConfiguration:remoteConfig];
[cache clearCache];
SPConfigurationBundle *bundle = [[SPConfigurationBundle alloc] init];
bundle.networkConfiguration = [[SPNetworkConfiguration alloc] initWithEndpoint:@"endpoint"];
Expand All @@ -308,7 +354,6 @@ - (void)testConfigurationProvider_justRefresh_downloadHigherConfigVersionThanCac
[cache writeCache:cached];
[NSThread sleepForTimeInterval:5]; // wait to write on cache
SPRemoteConfiguration *remoteConfig = [[SPRemoteConfiguration alloc] initWithEndpoint:endpoint method:SPHttpMethodGet];
SPConfigurationProvider *provider = [[SPConfigurationProvider alloc] initWithRemoteConfiguration:remoteConfig];
XCTestExpectation *expectation = [XCTestExpectation new];
[provider retrieveConfigurationOnlyRemote:NO onFetchCallback:^(SPFetchedConfigurationBundle * _Nonnull fetchedConfigurationBundle) {
Expand Down
Loading

0 comments on commit 949afe0

Please sign in to comment.