55var proxyquire = require ( 'proxyquireify' ) ( require ) ;
66
77var TraceKit = require ( '../vendor/TraceKit/tracekit' ) ;
8+
89var _Raven = proxyquire ( '../src/raven' , {
910 './utils' : {
1011 // patched to return a predictable result
@@ -1013,7 +1014,7 @@ describe('globals', function() {
10131014 maxMessageLength : 100 ,
10141015 release : 'abc123' ,
10151016 } ;
1016- Raven . _globalServer = 'http://localhost/store/' ;
1017+ Raven . _globalEndpoint = 'http://localhost/store/' ;
10171018 Raven . _globalOptions = globalOptions ;
10181019
10191020 Raven . _send ( { message : 'bar' } ) ;
@@ -1226,7 +1227,7 @@ describe('globals', function() {
12261227
12271228 it ( 'should populate crossOrigin based on options' , function ( ) {
12281229 Raven . _makeImageRequest ( {
1229- url : Raven . _globalServer ,
1230+ url : Raven . _globalEndpoint ,
12301231 auth : { lol : '1' } ,
12311232 data : { foo : 'bar' } ,
12321233 options : {
@@ -1239,7 +1240,7 @@ describe('globals', function() {
12391240
12401241 it ( 'should populate crossOrigin if empty string' , function ( ) {
12411242 Raven . _makeImageRequest ( {
1242- url : Raven . _globalServer ,
1243+ url : Raven . _globalEndpoint ,
12431244 auth : { lol : '1' } ,
12441245 data : { foo : 'bar' } ,
12451246 options : {
@@ -1252,7 +1253,7 @@ describe('globals', function() {
12521253
12531254 it ( 'should not populate crossOrigin if falsey' , function ( ) {
12541255 Raven . _makeImageRequest ( {
1255- url : Raven . _globalServer ,
1256+ url : Raven . _globalEndpoint ,
12561257 auth : { lol : '1' } ,
12571258 data : { foo : 'bar' } ,
12581259 options : {
@@ -1487,7 +1488,7 @@ describe('Raven (public API)', function() {
14871488 Raven . afterLoad ( ) ;
14881489
14891490 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/' ) ;
14911492
14921493 assert . equal ( Raven . _globalOptions . some , 'config' ) ;
14931494 assert . equal ( Raven . _globalProject , '2' ) ;
@@ -1504,7 +1505,7 @@ describe('Raven (public API)', function() {
15041505 assert . equal ( Raven , Raven . config ( SENTRY_DSN , { foo : 'bar' } ) , 'it should return Raven' ) ;
15051506
15061507 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/' ) ;
15081509 assert . equal ( Raven . _globalOptions . foo , 'bar' ) ;
15091510 assert . equal ( Raven . _globalProject , '2' ) ;
15101511 assert . isTrue ( Raven . isSetup ( ) ) ;
@@ -1514,15 +1515,15 @@ describe('Raven (public API)', function() {
15141515 Raven . config ( '//abc@example.com/2' ) ;
15151516
15161517 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/' ) ;
15181519 assert . equal ( Raven . _globalProject , '2' ) ;
15191520 assert . isTrue ( Raven . isSetup ( ) ) ;
15201521 } ) ;
15211522
15221523 it ( 'should work should work at a non root path' , function ( ) {
15231524 Raven . config ( '//abc@example.com/sentry/2' ) ;
15241525 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/' ) ;
15261527 assert . equal ( Raven . _globalProject , '2' ) ;
15271528 assert . isTrue ( Raven . isSetup ( ) ) ;
15281529 } ) ;
@@ -2028,4 +2029,80 @@ describe('Raven (public API)', function() {
20282029 assert . isFalse ( Raven . isSetup ( ) ) ;
20292030 } ) ;
20302031 } ) ;
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+ email : 'an@example.com'
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+ email : 'an2@example.com'
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+ } ) ;
20312108} ) ;
0 commit comments