-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d97b0c1
commit ec6b5e3
Showing
3 changed files
with
97 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const { send, jitsuEventPayload, isCI } = require('./analytics'); | ||
|
||
describe('analytics tests', () => { | ||
test('userId', async () => { | ||
const action = 'test'; | ||
const cloud = 'azure'; | ||
const more = { one: 1, two: 2 }; | ||
const extra = { cloud, ...more }; | ||
const error = 'Ouch!'; | ||
const regex = /\d+\.\d+\.\d+/; | ||
|
||
const pl = await jitsuEventPayload({ action, error, extra }); | ||
expect(pl.user_id.length).toBe(36); | ||
expect(pl.action).toBe(action); | ||
expect(pl.interface).toBe('cli'); | ||
expect(pl.tool_name).toBe('cml'); | ||
expect(regex.test(pl.tool_version)).toBe(true); | ||
expect(pl.tool_source).toBe(''); | ||
expect(pl.os_name.length > 0).toBe(true); | ||
expect(pl.os_version.length > 0).toBe(true); | ||
expect(pl.backend).toBe(cloud); | ||
expect(pl.error).toBe(error); | ||
expect(Object.keys(pl.extra).sort()).toEqual( | ||
['ci'].concat(Object.keys(more)).sort() | ||
); | ||
|
||
if (isCI()) { | ||
expect(pl.group_id.length).toBe(36); | ||
expect(pl.extra.ci.length > 0).toBe(true); | ||
} | ||
}); | ||
|
||
test('Send should never fail', async () => { | ||
let error = null; | ||
try { | ||
await send({ endpoint: 'https://notfound.cml.dev' }); | ||
} catch (err) { | ||
error = err; | ||
} | ||
|
||
expect(error).toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This comment was marked as off-topic.
Sorry, something went wrong.