Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename BugsnagUser properties #560

Merged
merged 1 commit into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Bugsnag Notifiers on other platforms.

## Enhancements

* Rename `BugsnagUser` properties
[#560](https://github.com/bugsnag/bugsnag-cocoa/pull/560)

* Make `BugsnagOnErrorBlock` return `BOOL` rather than `void`
[#555](https://github.com/bugsnag/bugsnag-cocoa/pull/555)

Expand Down
16 changes: 8 additions & 8 deletions Source/BugsnagConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ - (nonnull id)copyWithZone:(nullable NSZone *)zone {
[copy setReleaseStage:self.releaseStage];
[copy setSession:[self.session copy]];
[copy setSendThreads:self.sendThreads];
[copy setUser:self.user.userId
withEmail:self.user.emailAddress
[copy setUser:self.user.id
withEmail:self.user.email
andName:self.user.name];

return copy;
Expand Down Expand Up @@ -278,9 +278,9 @@ - (void)setUser:(NSString *_Nullable)userId
* @param user A BugsnagUser object containing data to be added to the configuration metadata.
*/
- (void)setUserMetadataFromUser:(BugsnagUser *)user {
[self.metadata addMetadata:user.userId withKey:BSGKeyId toSection:BSGKeyUser];
[self.metadata addMetadata:user.id withKey:BSGKeyId toSection:BSGKeyUser];
[self.metadata addMetadata:user.name withKey:BSGKeyName toSection:BSGKeyUser];
[self.metadata addMetadata:user.emailAddress withKey:BSGKeyEmail toSection:BSGKeyUser];
[self.metadata addMetadata:user.email withKey:BSGKeyEmail toSection:BSGKeyUser];
}

// =============================================================================
Expand Down Expand Up @@ -399,8 +399,8 @@ - (void)persistUserData {
@synchronized(self) {
if (_user) {
// Email
if (_user.emailAddress) {
[BSG_SSKeychain setPassword:_user.emailAddress
if (_user.email) {
[BSG_SSKeychain setPassword:_user.email
forService:kBugsnagUserEmailAddress
account:kBugsnagUserKeychainAccount];
}
Expand All @@ -421,8 +421,8 @@ - (void)persistUserData {
}

// UserId
if (_user.userId) {
[BSG_SSKeychain setPassword:_user.userId
if (_user.id) {
[BSG_SSKeychain setPassword:_user.id
forService:kBugsnagUserUserId
account:kBugsnagUserKeychainAccount];
}
Expand Down
4 changes: 2 additions & 2 deletions Source/BugsnagUser.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

@interface BugsnagUser : NSObject

@property(readonly) NSString *userId;
@property(readonly) NSString *id;
@property(readonly) NSString *name;
@property(readonly) NSString *emailAddress;
@property(readonly) NSString *email;

@end
12 changes: 6 additions & 6 deletions Source/BugsnagUser.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ @implementation BugsnagUser

- (instancetype)initWithDictionary:(NSDictionary *)dict {
if (self = [super init]) {
_userId = dict[@"id"];
_emailAddress = dict[@"email"];
_id = dict[@"id"];
_email = dict[@"email"];
_name = dict[@"name"];
}
return self;
Expand All @@ -23,9 +23,9 @@ - (instancetype)initWithDictionary:(NSDictionary *)dict {
- (instancetype)initWithUserId:(NSString *)userId name:(NSString *)name emailAddress:(NSString *)emailAddress {
self = [super init];
if (self) {
_userId = userId;
_id = userId;
_name = name;
_emailAddress = emailAddress;
_email = emailAddress;
}
return self;
}
Expand All @@ -36,8 +36,8 @@ + (instancetype)userWithUserId:(NSString *)userId name:(NSString *)name emailAdd

- (NSDictionary *)toJson {
NSMutableDictionary *dict = [NSMutableDictionary new];
BSGDictInsertIfNotNil(dict, self.userId, @"id");
BSGDictInsertIfNotNil(dict, self.emailAddress, @"email");
BSGDictInsertIfNotNil(dict, self.id, @"id");
BSGDictInsertIfNotNil(dict, self.email, @"email");
BSGDictInsertIfNotNil(dict, self.name, @"name");
return [NSDictionary dictionaryWithDictionary:dict];
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/BugsnagClientTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ - (void) testUserInfoStorageRetrieval {
XCTAssertEqualObjects([client.metadata getMetadataFromSection:BSGKeyUser withKey:BSGKeyName], @"Jiminy Cricket");
XCTAssertEqualObjects([client.metadata getMetadataFromSection:BSGKeyUser withKey:BSGKeyEmail], @"jiminy@bugsnag.com");

XCTAssertEqualObjects([client user].userId, @"Jiminy");
XCTAssertEqualObjects([client user].id, @"Jiminy");
XCTAssertEqualObjects([client user].name, @"Jiminy Cricket");
XCTAssertEqualObjects([client user].emailAddress, @"jiminy@bugsnag.com");
XCTAssertEqualObjects([client user].email, @"jiminy@bugsnag.com");

[client setUser:nil withEmail:nil andName:@"Jiminy Cricket"];

XCTAssertNil([client user].userId);
XCTAssertNil([client user].id);
XCTAssertEqualObjects([client user].name, @"Jiminy Cricket");
XCTAssertNil([client user].emailAddress);
XCTAssertNil([client user].email);
}

- (void)testMetadataMutability {
Expand Down
12 changes: 6 additions & 6 deletions Tests/BugsnagConfigurationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,9 @@ - (void)testUserNonPesistence {

BugsnagConfiguration *config2 = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1];
XCTAssertNotNil(config2.user);
XCTAssertNil(config2.user.userId);
XCTAssertNil(config2.user.id);
XCTAssertNil(config2.user.name);
XCTAssertNil(config2.user.emailAddress);
XCTAssertNil(config2.user.email);
}

/**
Expand Down Expand Up @@ -656,9 +656,9 @@ - (void)testUser {

[config setUser:@"123" withEmail:@"test@example.com" andName:@"foo"];

XCTAssertEqualObjects(@"123", config.user.userId);
XCTAssertEqualObjects(@"123", config.user.id);
XCTAssertEqualObjects(@"foo", config.user.name);
XCTAssertEqualObjects(@"test@example.com", config.user.emailAddress);
XCTAssertEqualObjects(@"test@example.com", config.user.email);
}

- (void)testDefaultRedactedKeys {
Expand Down Expand Up @@ -822,8 +822,8 @@ - (void)testNSCopying {

// Object
[clone setUser:@"Cthulu" withEmail:@"hp@lovecraft.com" andName:@"Howard"];
XCTAssertEqualObjects(config.user.userId, @"foo");
XCTAssertEqualObjects(clone.user.userId, @"Cthulu");
XCTAssertEqualObjects(config.user.id, @"foo");
XCTAssertEqualObjects(clone.user.id, @"Cthulu");

// String
[clone setApiKey:DUMMY_APIKEY_32CHAR_2];
Expand Down
4 changes: 2 additions & 2 deletions Tests/BugsnagSessionTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ - (void)testPayloadDeserialization {

// user
XCTAssertNotNil(session.user);
XCTAssertEqualObjects(@"123", session.user.userId);
XCTAssertEqualObjects(@"123", session.user.id);
XCTAssertEqualObjects(@"Joe Bloggs", session.user.name);
XCTAssertEqualObjects(@"joe@example.com", session.user.emailAddress);
XCTAssertEqualObjects(@"joe@example.com", session.user.email);

// app
BugsnagApp *app = session.app;
Expand Down
12 changes: 6 additions & 6 deletions Tests/BugsnagSessionTrackerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ - (void)testStartNewSessionWithUser {
XCTAssertNotNil(session.id);
XCTAssertTrue([[NSDate date] timeIntervalSinceDate:session.startedAt] < 1);
XCTAssertEqual(session.user.name, @"Bill");
XCTAssertEqual(session.user.userId, @"123");
XCTAssertNil(session.user.emailAddress);
XCTAssertEqual(session.user.id, @"123");
XCTAssertNil(session.user.email);
XCTAssertFalse(session.autoCaptured);
}

Expand All @@ -79,8 +79,8 @@ - (void)testStartNewAutoCapturedSession {
XCTAssertTrue([[NSDate date] timeIntervalSinceDate:session.startedAt] < 1);
XCTAssertTrue(session.autoCaptured);
XCTAssertNil(session.user.name);
XCTAssertNil(session.user.userId);
XCTAssertNil(session.user.emailAddress);
XCTAssertNil(session.user.id);
XCTAssertNil(session.user.email);
}

- (void)testStartNewAutoCapturedSessionWithUser {
Expand All @@ -93,8 +93,8 @@ - (void)testStartNewAutoCapturedSessionWithUser {
XCTAssertNotNil(session.id);
XCTAssertTrue([[NSDate date] timeIntervalSinceDate:session.startedAt] < 1);
XCTAssertEqual(session.user.name, @"Bill");
XCTAssertEqual(session.user.userId, @"123");
XCTAssertEqual(session.user.emailAddress, @"bill@example.com");
XCTAssertEqual(session.user.id, @"123");
XCTAssertEqual(session.user.email, @"bill@example.com");
XCTAssertTrue(session.autoCaptured);
}

Expand Down
9 changes: 4 additions & 5 deletions Tests/BugsnagUserTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ @interface BugsnagUser ()
- (instancetype)initWithDictionary:(NSDictionary *)dict;
- (instancetype)initWithUserId:(NSString *)userId name:(NSString *)name emailAddress:(NSString *)emailAddress;
- (NSDictionary *)toJson;
- (instancetype)initWithUserId:(NSString *)userId name:(NSString *)name emailAddress:(NSString *)emailAddress;
@end

@interface BugsnagEvent ()
Expand All @@ -41,8 +40,8 @@ - (void)testDictDeserialisation {
BugsnagUser *user = [[BugsnagUser alloc] initWithDictionary:dict];

XCTAssertNotNil(user);
XCTAssertEqualObjects(user.userId, @"test");
XCTAssertEqualObjects(user.emailAddress, @"fake@example.com");
XCTAssertEqualObjects(user.id, @"test");
XCTAssertEqualObjects(user.email, @"fake@example.com");
XCTAssertEqualObjects(user.name, @"Tom Bombadil");
}

Expand All @@ -67,9 +66,9 @@ - (void)testUserEvent {
@"email": @"jane@example.com",
}
}}];
XCTAssertEqualObjects(@"123", event.user.userId);
XCTAssertEqualObjects(@"123", event.user.id);
XCTAssertEqualObjects(@"Jane Smith", event.user.name);
XCTAssertEqualObjects(@"jane@example.com", event.user.emailAddress);
XCTAssertEqualObjects(@"jane@example.com", event.user.email);
}

@end
12 changes: 12 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,15 @@ of the removed `addAttribute`:
- user
- sessionId
```

### `BugsnagUser` class

#### Renames

```diff
- userId
+ id

- emailAddress
+ email
```