Skip to content

Commit

Permalink
test: add nil check and fix/update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bgiori committed Apr 4, 2024
1 parent eca6cc2 commit 2fc7f3e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 4 additions & 1 deletion Sources/Amplitude/Amplitude.m
Original file line number Diff line number Diff line change
Expand Up @@ -1669,7 +1669,10 @@ - (NSString *)getAdSupportID {
}

- (NSString *)getDeviceId {
return [self initializeDeviceId];
if (self.deviceId == nil) {
return [self initializeDeviceId];
}
return self.deviceId;
}

- (long long)getSessionId {
Expand Down
8 changes: 8 additions & 0 deletions Tests/AmplitudeTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -1705,4 +1705,12 @@ - (void)testOpenURLFiresDeepLinkEvent {
XCTAssertEqualObjects([[event objectForKey:@"event_properties"] objectForKey:kAMPEventPropLinkUrl], @"https://test-app.com");
}

- (void)testGetDeviceIdAfterInit {
NSString *instanceName = @"testGetDeviceIdAfterInit";
Amplitude *client = [Amplitude instanceWithName:instanceName];
[client initializeApiKey:@"test"];
NSString *deviceId = [client getDeviceId];
XCTAssertNotEqual(deviceId, @"");
}

@end
3 changes: 0 additions & 3 deletions Tests/SetupTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,12 @@ - (void)testUserPropertiesSet {

- (void)testSetDeviceId {
AMPDatabaseHelper *dbHelper = [AMPDatabaseHelper getDatabaseHelper];
NSString *initialDeviceId = [self.amplitude getDeviceId];
XCTAssertNil(initialDeviceId); // device id not initialized yet

[self.amplitude initializeApiKey:apiKey];
[self.amplitude flushQueueWithQueue:self.amplitude.initializerQueue];
[self.amplitude flushQueue];
NSString *generatedDeviceId = [self.amplitude getDeviceId];
XCTAssertNotNil(generatedDeviceId);
XCTAssertNotEqualObjects(initialDeviceId, generatedDeviceId);
#if !TARGET_OS_OSX
XCTAssertEqual(generatedDeviceId.length, 36);
#else
Expand Down

0 comments on commit 2fc7f3e

Please sign in to comment.