Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
Add an end to end test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
f2prateek committed Nov 15, 2017
1 parent 23bfccf commit 72c1315
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import delay from 'delay'
import auth from 'basic-auth'
import pify from 'pify'
import test from 'ava'
import axios from 'axios'
import retries from 'axios-retry'
import uid from 'crypto-token'
import Analytics from '.'
import {version} from './package'

Expand Down Expand Up @@ -447,3 +450,50 @@ test('alias - require previousId and userId', t => {
})
})
})

// E2E test as described in https://paper.dropbox.com/doc/analytics-node-E2E-Test-9oavh3DFcFBXuqCJBe1o9.
test('end to end test', async t => {
const id = uid(16)

// Segment Write Key for https://segment.com/segment-libraries/sources/analytics_node_e2e_test/overview
const analytics = new Analytics('wZqHyttfRO0KxEHyRTujWZQswgTDZx1N')
analytics.track({
userId: 'prateek',
event: 'E2E Test',
properties: { id }
})
analytics.flush()

// Give some time for events to be delivered from the API to destinations.
await delay(5 * 1000) // 5 seconds.

const axiosClient = axios.create({
baseURL: 'https://api.runscope.com',
timeout: 10 * 1000,
headers: { Authorization: `Bearer ${process.env.RUNSCOPE_TOKEN}` }
})
retries(axiosClient, { retries: 3 })

// Runscope Bucket for https://www.runscope.com/stream/zfte7jmy76oz.
const messagesResponse = await axiosClient.get('buckets/zfte7jmy76oz/messages?count=10')
t.is(messagesResponse.status, 200)

let found = false

for (const item of messagesResponse.data.data) {
const response = await axiosClient.get(`buckets/zfte7jmy76oz/messages/${item.uuid}`)
t.is(response.status, 200)

const body = JSON.parse(response.data.data.request.body)
if (id === body.properties.id) {
found = true
break
}
}

if (found) {
t.pass()
} else {
t.fail()
}
})

0 comments on commit 72c1315

Please sign in to comment.