|
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 |
@@ -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 | + 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 | + }); |
2031 | 2108 | }); |
0 commit comments