Skip to content

Commit

Permalink
test: add analytics tests
Browse files Browse the repository at this point in the history
  • Loading branch information
erezrokah committed Feb 9, 2022
1 parent 51f37de commit 9ee00c7
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions tests/integration/240.telemetry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,40 @@ test.serial('should track --telemetry-enable', async (t) => {
test('should send netlify-cli/<version> user-agent', async (t) => {
await withMockApi(routes, async ({ apiUrl, requests }) => {
await callCli(['api', 'listSites'], getCLIOptions(apiUrl))
t.true(requests.length !== 0)
const request = requests.find(({ path }) => path === '/api/v1/track')
t.truthy(request)
// example: netlify-cli/6.14.25 darwin-x64 node-v16.13.0
const userAgent = requests[0].headers['user-agent']
const userAgent = request.headers['user-agent']
t.assert(userAgent.startsWith(`${name}/${version}`))
})
})

test('should send correct command on success', async (t) => {
await withMockApi(routes, async ({ apiUrl, requests }) => {
await callCli(['api', 'listSites'], getCLIOptions(apiUrl))
const request = requests.find(({ path }) => path === '/api/v1/track')
t.truthy(request)

t.true(typeof request.body.anonymousId === 'string')
t.true(typeof request.body.userId === 'string')
t.true(Number.isInteger(request.body.duration))
t.is(request.body.event, 'cli:command')
t.is(request.body.status, 'success')
t.deepEqual(request.body.properties, { command: 'api' })
})
})

test('should send correct command on failure', async (t) => {
await withMockApi(routes, async ({ apiUrl, requests }) => {
await t.throwsAsync(() => callCli(['dev:exec', 'exit 1'], getCLIOptions(apiUrl)))
const request = requests.find(({ path }) => path === '/api/v1/track')
t.truthy(request)

t.true(typeof request.body.anonymousId === 'string')
t.true(typeof request.body.userId === 'string')
t.true(Number.isInteger(request.body.duration))
t.is(request.body.event, 'cli:command')
t.is(request.body.status, 'error')
t.deepEqual(request.body.properties, { command: 'dev:exec' })
})
})

0 comments on commit 9ee00c7

Please sign in to comment.