-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref(ios): Move breadcrumbs conversion to pure obj-c to ensure compati…
…bility with the swift implementation (#3854)
- Loading branch information
1 parent
758e3b7
commit 0019f64
Showing
5 changed files
with
90 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryBreadcrumbTests.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#import <XCTest/XCTest.h> | ||
#import "RNSentryBreadcrumb.h" | ||
@import Sentry; | ||
|
||
@interface RNSentryBreadcrumbTests : XCTestCase | ||
|
||
@end | ||
|
||
@implementation RNSentryBreadcrumbTests | ||
|
||
- (void)testGeneratesSentryBreadcrumbFromNSDictionary | ||
{ | ||
SentryBreadcrumb* actualCrumb = [RNSentryBreadcrumb from:@{ | ||
@"level": @"error", | ||
@"category": @"testCategory", | ||
@"type": @"testType", | ||
@"message": @"testMessage", | ||
@"data": @{ | ||
@"test": @"data" | ||
} | ||
}]; | ||
|
||
XCTAssertEqual(actualCrumb.level, kSentryLevelError); | ||
XCTAssertEqual(actualCrumb.category, @"testCategory"); | ||
XCTAssertEqual(actualCrumb.type, @"testType"); | ||
XCTAssertEqual(actualCrumb.message, @"testMessage"); | ||
XCTAssertTrue([actualCrumb.data isKindOfClass:[NSDictionary class]]); | ||
XCTAssertEqual(actualCrumb.data[@"test"], @"data"); | ||
} | ||
|
||
- (void)testUsesInfoAsDefaultSentryLevel | ||
{ | ||
SentryBreadcrumb* actualCrumb = [RNSentryBreadcrumb from:@{ | ||
@"message": @"testMessage", | ||
}]; | ||
|
||
XCTAssertEqual(actualCrumb.level, kSentryLevelInfo); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
@class SentryBreadcrumb; | ||
|
||
@interface RNSentryBreadcrumb : NSObject | ||
|
||
+ (SentryBreadcrumb *)from: (NSDictionary *) dict; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#import "RNSentryBreadcrumb.h" | ||
@import Sentry; | ||
|
||
@implementation RNSentryBreadcrumb | ||
|
||
+(SentryBreadcrumb*) from: (NSDictionary *) dict | ||
{ | ||
SentryBreadcrumb* crumb = [[SentryBreadcrumb alloc] init]; | ||
|
||
NSString * levelString = dict[@"level"]; | ||
SentryLevel sentryLevel; | ||
if ([levelString isEqualToString:@"fatal"]) { | ||
sentryLevel = kSentryLevelFatal; | ||
} else if ([levelString isEqualToString:@"warning"]) { | ||
sentryLevel = kSentryLevelWarning; | ||
} else if ([levelString isEqualToString:@"error"]) { | ||
sentryLevel = kSentryLevelError; | ||
} else if ([levelString isEqualToString:@"debug"]) { | ||
sentryLevel = kSentryLevelDebug; | ||
} else { | ||
sentryLevel = kSentryLevelInfo; | ||
} | ||
|
||
[crumb setLevel:sentryLevel]; | ||
[crumb setCategory:dict[@"category"]]; | ||
[crumb setType:dict[@"type"]]; | ||
[crumb setMessage:dict[@"message"]]; | ||
[crumb setData:dict[@"data"]]; | ||
|
||
return crumb; | ||
} | ||
|
||
@end |