5
5
var proxyquire = require ( 'proxyquireify' ) ( require ) ;
6
6
7
7
var TraceKit = require ( '../vendor/TraceKit/tracekit' ) ;
8
+
8
9
var _Raven = proxyquire ( '../src/raven' , {
9
10
'./utils' : {
10
11
// patched to return a predictable result
@@ -1013,7 +1014,7 @@ describe('globals', function() {
1013
1014
maxMessageLength : 100 ,
1014
1015
release : 'abc123' ,
1015
1016
} ;
1016
- Raven . _globalServer = 'http://localhost/store/' ;
1017
+ Raven . _globalEndpoint = 'http://localhost/store/' ;
1017
1018
Raven . _globalOptions = globalOptions ;
1018
1019
1019
1020
Raven . _send ( { message : 'bar' } ) ;
@@ -1226,7 +1227,7 @@ describe('globals', function() {
1226
1227
1227
1228
it ( 'should populate crossOrigin based on options' , function ( ) {
1228
1229
Raven . _makeImageRequest ( {
1229
- url : Raven . _globalServer ,
1230
+ url : Raven . _globalEndpoint ,
1230
1231
auth : { lol : '1' } ,
1231
1232
data : { foo : 'bar' } ,
1232
1233
options : {
@@ -1239,7 +1240,7 @@ describe('globals', function() {
1239
1240
1240
1241
it ( 'should populate crossOrigin if empty string' , function ( ) {
1241
1242
Raven . _makeImageRequest ( {
1242
- url : Raven . _globalServer ,
1243
+ url : Raven . _globalEndpoint ,
1243
1244
auth : { lol : '1' } ,
1244
1245
data : { foo : 'bar' } ,
1245
1246
options : {
@@ -1252,7 +1253,7 @@ describe('globals', function() {
1252
1253
1253
1254
it ( 'should not populate crossOrigin if falsey' , function ( ) {
1254
1255
Raven . _makeImageRequest ( {
1255
- url : Raven . _globalServer ,
1256
+ url : Raven . _globalEndpoint ,
1256
1257
auth : { lol : '1' } ,
1257
1258
data : { foo : 'bar' } ,
1258
1259
options : {
@@ -1487,7 +1488,7 @@ describe('Raven (public API)', function() {
1487
1488
Raven . afterLoad ( ) ;
1488
1489
1489
1490
assert . equal ( Raven . _globalKey , 'random' ) ;
1490
- assert . equal ( Raven . _globalServer , 'http://some.other.server:80/api/2/store/' ) ;
1491
+ assert . equal ( Raven . _globalEndpoint , 'http://some.other.server:80/api/2/store/' ) ;
1491
1492
1492
1493
assert . equal ( Raven . _globalOptions . some , 'config' ) ;
1493
1494
assert . equal ( Raven . _globalProject , '2' ) ;
@@ -1504,7 +1505,7 @@ describe('Raven (public API)', function() {
1504
1505
assert . equal ( Raven , Raven . config ( SENTRY_DSN , { foo : 'bar' } ) , 'it should return Raven' ) ;
1505
1506
1506
1507
assert . equal ( Raven . _globalKey , 'abc' ) ;
1507
- assert . equal ( Raven . _globalServer , 'http://example.com:80/api/2/store/' ) ;
1508
+ assert . equal ( Raven . _globalEndpoint , 'http://example.com:80/api/2/store/' ) ;
1508
1509
assert . equal ( Raven . _globalOptions . foo , 'bar' ) ;
1509
1510
assert . equal ( Raven . _globalProject , '2' ) ;
1510
1511
assert . isTrue ( Raven . isSetup ( ) ) ;
@@ -1514,15 +1515,15 @@ describe('Raven (public API)', function() {
1514
1515
Raven . config ( '//[email protected] /2' ) ;
1515
1516
1516
1517
assert . equal ( Raven . _globalKey , 'abc' ) ;
1517
- assert . equal ( Raven . _globalServer , '//example.com/api/2/store/' ) ;
1518
+ assert . equal ( Raven . _globalEndpoint , '//example.com/api/2/store/' ) ;
1518
1519
assert . equal ( Raven . _globalProject , '2' ) ;
1519
1520
assert . isTrue ( Raven . isSetup ( ) ) ;
1520
1521
} ) ;
1521
1522
1522
1523
it ( 'should work should work at a non root path' , function ( ) {
1523
1524
Raven . config ( '//[email protected] /sentry/2' ) ;
1524
1525
assert . equal ( Raven . _globalKey , 'abc' ) ;
1525
- assert . equal ( Raven . _globalServer , '//example.com/sentry/api/2/store/' ) ;
1526
+ assert . equal ( Raven . _globalEndpoint , '//example.com/sentry/api/2/store/' ) ;
1526
1527
assert . equal ( Raven . _globalProject , '2' ) ;
1527
1528
assert . isTrue ( Raven . isSetup ( ) ) ;
1528
1529
} ) ;
@@ -2028,4 +2029,80 @@ describe('Raven (public API)', function() {
2028
2029
assert . isFalse ( Raven . isSetup ( ) ) ;
2029
2030
} ) ;
2030
2031
} ) ;
2032
+
2033
+ describe ( '.showReportDialog' , function ( ) {
2034
+ it ( 'should throw a RavenConfigError if no eventId' , function ( ) {
2035
+ assert . throws ( function ( ) {
2036
+ Raven . showReportDialog ( {
2037
+ dsn : SENTRY_DSN // dsn specified via options
2038
+ } ) ;
2039
+ } , 'Missing eventId' ) ;
2040
+
2041
+ Raven . config ( SENTRY_DSN ) ;
2042
+ assert . throws ( function ( ) {
2043
+ Raven . showReportDialog ( ) ; // dsn specified via Raven.config
2044
+ } , 'Missing eventId' ) ;
2045
+ } ) ;
2046
+
2047
+ it ( 'should throw a RavenConfigError if no dsn' , function ( ) {
2048
+ assert . throws ( function ( ) {
2049
+ Raven . showReportDialog ( {
2050
+ eventId : 'abc123'
2051
+ } ) ;
2052
+ } , 'Missing DSN' ) ;
2053
+ } ) ;
2054
+
2055
+ describe ( 'script tag insertion' , function ( ) {
2056
+ beforeEach ( function ( ) {
2057
+ this . appendChildStub = this . sinon . stub ( document . head , 'appendChild' ) ;
2058
+ } ) ;
2059
+
2060
+ it ( 'should specify embed API endpoint and basic query string (DSN, eventId)' , function ( ) {
2061
+ Raven . showReportDialog ( {
2062
+ eventId : 'abc123' ,
2063
+ dsn : SENTRY_DSN
2064
+ } ) ;
2065
+
2066
+ var script = this . appendChildStub . getCall ( 0 ) . args [ 0 ] ;
2067
+ assert . equal ( script . src , 'http://example.com/api/embed/error-page/?eventId=abc123&dsn=http%3A%2F%2Fabc%40example.com%3A80%2F2' ) ;
2068
+
2069
+ this . appendChildStub . reset ( ) ;
2070
+
2071
+ Raven
2072
+ . config ( SENTRY_DSN )
2073
+ . captureException ( new Error ( 'foo' ) ) // generates lastEventId
2074
+ . showReportDialog ( ) ;
2075
+
2076
+ this . appendChildStub . getCall ( 0 ) . args [ 0 ] ;
2077
+ assert . equal ( script . src , 'http://example.com/api/embed/error-page/?eventId=abc123&dsn=http%3A%2F%2Fabc%40example.com%3A80%2F2' ) ;
2078
+ } ) ;
2079
+
2080
+ it ( 'should specify embed API endpoint and full query string (DSN, eventId, user)' , function ( ) {
2081
+ Raven . showReportDialog ( {
2082
+ eventId : 'abc123' ,
2083
+ dsn : SENTRY_DSN ,
2084
+ user : {
2085
+ name : 'Average Normalperson' ,
2086
+
2087
+ }
2088
+ } ) ;
2089
+
2090
+ var script = this . appendChildStub . getCall ( 0 ) . args [ 0 ] ;
2091
+ assert . equal ( script . src , 'http://example.com/api/embed/error-page/?eventId=abc123&dsn=http%3A%2F%2Fabc%40example.com%3A80%2F2&name=Average%20Normalperson&email=an%40example.com' ) ;
2092
+
2093
+ this . appendChildStub . reset ( ) ;
2094
+ Raven
2095
+ . config ( SENTRY_DSN )
2096
+ . captureException ( new Error ( 'foo' ) ) // generates lastEventId
2097
+ . setUserContext ( {
2098
+ name : 'Average Normalperson 2' ,
2099
+
2100
+ } )
2101
+ . showReportDialog ( ) ;
2102
+
2103
+ var script = this . appendChildStub . getCall ( 0 ) . args [ 0 ] ;
2104
+ assert . equal ( script . src , 'http://example.com/api/embed/error-page/?eventId=abc123&dsn=http%3A%2F%2Fabc%40example.com%3A80%2F2&name=Average%20Normalperson%202&email=an2%40example.com' ) ;
2105
+ } ) ;
2106
+ } ) ;
2107
+ } ) ;
2031
2108
} ) ;
0 commit comments