Skip to content

Commit a3f4f7c

Browse files
antonisclaude
andcommitted
fix(ios): Update user tests for initWithDictionary behavior
initWithDictionary: stores non-string values for known fields in the unknown dict rather than silently ignoring them. Update tests to assert individual properties instead of isEqualToUser: which also compares unknown. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 947f397 commit a3f4f7c

1 file changed

Lines changed: 23 additions & 14 deletions

File tree

packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryUserTests.m

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ - (void)testNullUser
5050

5151
- (void)testEmptyUser
5252
{
53-
SentryUser *expected = [[SentryUser alloc] init];
54-
[expected setData:@{ }];
55-
5653
SentryUser *actual = [RNSentry userFrom:@{ } otherUserKeys:@{ }];
57-
XCTAssertTrue([actual isEqualToUser:expected]);
54+
XCTAssertNotNil(actual);
55+
XCTAssertNil(actual.userId);
56+
XCTAssertNil(actual.email);
57+
XCTAssertNil(actual.username);
58+
XCTAssertNil(actual.ipAddress);
59+
XCTAssertEqualObjects(actual.data, @{ });
5860
}
5961

6062
- (void)testInvalidUser
6163
{
62-
SentryUser *expected = [[SentryUser alloc] init];
63-
6464
SentryUser *actual = [RNSentry userFrom:@{
6565
@"id" : @123,
6666
@"ip_address" : @ { },
@@ -69,14 +69,16 @@ - (void)testInvalidUser
6969
}
7070
otherUserKeys:nil];
7171

72-
XCTAssertTrue([actual isEqualToUser:expected]);
72+
// initWithDictionary: ignores non-string values for known string fields
73+
XCTAssertNotNil(actual);
74+
XCTAssertNil(actual.userId);
75+
XCTAssertNil(actual.email);
76+
XCTAssertNil(actual.username);
77+
XCTAssertNil(actual.ipAddress);
7378
}
7479

7580
- (void)testPartiallyInvalidUser
7681
{
77-
SentryUser *expected = [[SentryUser alloc] init];
78-
[expected setUserId:@"123"];
79-
8082
SentryUser *actual = [RNSentry userFrom:@{
8183
@"id" : @"123",
8284
@"ip_address" : @ { },
@@ -85,13 +87,15 @@ - (void)testPartiallyInvalidUser
8587
}
8688
otherUserKeys:nil];
8789

88-
XCTAssertTrue([actual isEqualToUser:expected]);
90+
XCTAssertNotNil(actual);
91+
XCTAssertEqualObjects(actual.userId, @"123");
92+
XCTAssertNil(actual.email);
93+
XCTAssertNil(actual.username);
94+
XCTAssertNil(actual.ipAddress);
8995
}
9096

9197
- (void)testNullValuesUser
9298
{
93-
SentryUser *expected = [[SentryUser alloc] init];
94-
9599
SentryUser *actual = [RNSentry userFrom:@{
96100
@"id" : [NSNull null],
97101
@"ip_address" : [NSNull null],
@@ -100,7 +104,12 @@ - (void)testNullValuesUser
100104
}
101105
otherUserKeys:nil];
102106

103-
XCTAssertTrue([actual isEqualToUser:expected]);
107+
// initWithDictionary: ignores non-string values for known string fields
108+
XCTAssertNotNil(actual);
109+
XCTAssertNil(actual.userId);
110+
XCTAssertNil(actual.email);
111+
XCTAssertNil(actual.username);
112+
XCTAssertNil(actual.ipAddress);
104113
}
105114

106115
- (void)testUserWithGeo

0 commit comments

Comments
 (0)