|
| 1 | +const { getTime } = require('../functional/uncat-internal-help.cjs') |
| 2 | +const { getErrorsFromResponse } = require('../functional/err/assertion-helpers') |
| 3 | + |
| 4 | +describe('newrelic api', () => { |
| 5 | + let testHandle |
| 6 | + const init = { |
| 7 | + ajax: { deny_list: [], harvestTimeSeconds: 2 }, |
| 8 | + jserrors: { harvestTimeSeconds: 2 }, |
| 9 | + metrics: { harvestTimeSeconds: 2 }, |
| 10 | + page_action: { harvestTimeSeconds: 2 }, |
| 11 | + page_view_timing: { harvestTimeSeconds: 2 }, |
| 12 | + session_trace: { harvestTimeSeconds: 2 }, |
| 13 | + spa: { harvestTimeSeconds: 2 } |
| 14 | + } |
| 15 | + |
| 16 | + beforeEach(async () => { |
| 17 | + testHandle = await browser.getTestHandle() |
| 18 | + }) |
| 19 | + |
| 20 | + afterEach(async () => { |
| 21 | + await testHandle.destroy() |
| 22 | + }) |
| 23 | + |
| 24 | + it('should load when sessionStorage is not available', async () => { |
| 25 | + const url = await testHandle.assetURL('api/session-storage-disallowed.html', { |
| 26 | + loader: 'spa', |
| 27 | + init |
| 28 | + }) |
| 29 | + |
| 30 | + await Promise.all([ |
| 31 | + testHandle.expectRum(), |
| 32 | + browser.url(url) |
| 33 | + ]) |
| 34 | + const result = await browser.execute(() => { |
| 35 | + return typeof window.newrelic.addToTrace === 'function' |
| 36 | + }) |
| 37 | + |
| 38 | + expect(result).toEqual(true) |
| 39 | + }) |
| 40 | + |
| 41 | + describe('setPageViewName api', () => { |
| 42 | + it('customTransactionName 1 arg', async () => { |
| 43 | + const url = await testHandle.assetURL('api.html', { |
| 44 | + loader: 'spa', |
| 45 | + init |
| 46 | + }) |
| 47 | + |
| 48 | + const rumPromise = testHandle.expectRum() |
| 49 | + const eventsPromise = testHandle.expectEvents() |
| 50 | + const timeSlicePromise = testHandle.expectAjaxTimeSlices() |
| 51 | + const resourcesPromise = testHandle.expectResources() |
| 52 | + |
| 53 | + await Promise.all([ |
| 54 | + browser.url(url), |
| 55 | + rumPromise, |
| 56 | + eventsPromise, |
| 57 | + timeSlicePromise, |
| 58 | + resourcesPromise |
| 59 | + ]) |
| 60 | + |
| 61 | + expect((await rumPromise).request.query.ct).toEqual('http://custom.transaction/foo') |
| 62 | + expect((await eventsPromise).request.query.ct).toEqual('http://custom.transaction/foo') |
| 63 | + expect((await timeSlicePromise).request.query.ct).toEqual('http://custom.transaction/foo') |
| 64 | + expect((await resourcesPromise).request.query.ct).toEqual('http://custom.transaction/foo') |
| 65 | + }) |
| 66 | + |
| 67 | + it('customTransactionName 1 arg unload', async () => { |
| 68 | + const url = await testHandle.assetURL('api.html', { |
| 69 | + loader: 'spa', |
| 70 | + init |
| 71 | + }) |
| 72 | + const unloadUrl = await testHandle.assetURL('/', { |
| 73 | + loader: 'spa', |
| 74 | + init |
| 75 | + }) |
| 76 | + |
| 77 | + await browser.url(url) |
| 78 | + const metricsPromise = testHandle.expectCustomMetrics() |
| 79 | + await browser.url(unloadUrl) |
| 80 | + const { request: { body, query } } = await metricsPromise |
| 81 | + const time = getTime(body ? JSON.parse(body)?.cm : JSON.parse(query.cm)) |
| 82 | + |
| 83 | + expect(query.ct).toEqual('http://custom.transaction/foo') |
| 84 | + expect(typeof time).toEqual('number') |
| 85 | + expect(time).toBeGreaterThan(0) |
| 86 | + }) |
| 87 | + |
| 88 | + it('customTransactionName 2 arg', async () => { |
| 89 | + const url = await testHandle.assetURL('api2.html', { |
| 90 | + loader: 'spa', |
| 91 | + init |
| 92 | + }) |
| 93 | + const unloadUrl = await testHandle.assetURL('/', { |
| 94 | + loader: 'spa', |
| 95 | + init |
| 96 | + }) |
| 97 | + |
| 98 | + await browser.url(url) |
| 99 | + const metricsPromise = testHandle.expectCustomMetrics() |
| 100 | + await browser.url(unloadUrl) |
| 101 | + const { request: { body, query } } = await metricsPromise |
| 102 | + const time = getTime(body ? JSON.parse(body)?.cm : JSON.parse(query.cm)) |
| 103 | + |
| 104 | + expect(query.ct).toEqual('http://bar.baz/foo') |
| 105 | + expect(typeof time).toEqual('number') |
| 106 | + expect(time).toBeGreaterThan(0) |
| 107 | + }) |
| 108 | + }) |
| 109 | + |
| 110 | + describe('noticeError api', () => { |
| 111 | + it('takes an error object', async () => { |
| 112 | + const url = await testHandle.assetURL('api.html', { |
| 113 | + loader: 'spa', |
| 114 | + init |
| 115 | + }) |
| 116 | + |
| 117 | + const errorsPromise = testHandle.expectErrors() |
| 118 | + await browser.url(url) |
| 119 | + const { request } = await errorsPromise |
| 120 | + const errorData = getErrorsFromResponse(request) |
| 121 | + const params = errorData[0] && errorData[0]['params'] |
| 122 | + |
| 123 | + expect(params.exceptionClass).toEqual('Error') |
| 124 | + expect(params.message).toEqual('no free taco coupons') |
| 125 | + }) |
| 126 | + |
| 127 | + it('takes a string', async () => { |
| 128 | + const url = await testHandle.assetURL('api/noticeError.html', { |
| 129 | + loader: 'spa', |
| 130 | + init |
| 131 | + }) |
| 132 | + |
| 133 | + const errorsPromise = testHandle.expectErrors() |
| 134 | + await browser.url(url) |
| 135 | + const { request } = await errorsPromise |
| 136 | + const errorData = getErrorsFromResponse(request) |
| 137 | + const params = errorData[0] && errorData[0]['params'] |
| 138 | + |
| 139 | + expect(params.exceptionClass).toEqual('Error') |
| 140 | + expect(params.message).toEqual('too many free taco coupons') |
| 141 | + }) |
| 142 | + }) |
| 143 | +}) |
0 commit comments