From 18ee923f022caebb81cf9db3c32f016c7420af2f Mon Sep 17 00:00:00 2001 From: Kyle Gray Date: Mon, 1 Apr 2019 15:41:40 -0400 Subject: [PATCH] feat(analytics-core): added dma logging service --- packages/analytics-core/src/dma.js | 17 +++++++++++++ packages/analytics-core/src/index.js | 3 ++- packages/analytics-core/src/tests/dma.test.js | 24 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 packages/analytics-core/src/dma.js create mode 100644 packages/analytics-core/src/tests/dma.test.js diff --git a/packages/analytics-core/src/dma.js b/packages/analytics-core/src/dma.js new file mode 100644 index 000000000..44b523620 --- /dev/null +++ b/packages/analytics-core/src/dma.js @@ -0,0 +1,17 @@ +import AvAnalyticsPlugin from './plugin'; + +export default class AvDmaAnalytics extends AvAnalyticsPlugin { + constructor(AvLogMessages, enabled) { + super(enabled); + this.AvLogMessages = AvLogMessages; + } + + trackEvent(properties) { + properties.level = properties.level || 'info'; + return this.AvLogMessages.send(properties); + } + + trackPageView(url) { + return this.trackEvent({ event: 'page', url }); + } +} diff --git a/packages/analytics-core/src/index.js b/packages/analytics-core/src/index.js index 73cfc82fe..ff7cb5c00 100644 --- a/packages/analytics-core/src/index.js +++ b/packages/analytics-core/src/index.js @@ -1,5 +1,6 @@ import AvAnalytics from './analytics'; import AvAnalyticsPlugin from './plugin'; import AvSplunkAnalytics from './splunk'; +import AvDmaAnalytics from './dma'; -export { AvAnalytics, AvAnalyticsPlugin, AvSplunkAnalytics }; +export { AvAnalytics, AvAnalyticsPlugin, AvSplunkAnalytics, AvDmaAnalytics }; diff --git a/packages/analytics-core/src/tests/dma.test.js b/packages/analytics-core/src/tests/dma.test.js new file mode 100644 index 000000000..8cc40f981 --- /dev/null +++ b/packages/analytics-core/src/tests/dma.test.js @@ -0,0 +1,24 @@ +import { AvDmaAnalytics } from '..'; + +describe('AvSplunkAnalytics', () => { + let mockLog; + let mockAvSplunkAnalytics; + + beforeEach(() => { + mockLog = { + send: jest.fn(), + }; + + mockAvSplunkAnalytics = new AvDmaAnalytics(mockLog); + }); + + test('AvSplunkAnalytics should be defined', () => { + expect(mockAvSplunkAnalytics).toBeDefined(); + }); + + test('trackEvent should call AvLogMessages.send', () => { + const level = 'info'; + mockAvSplunkAnalytics.trackEvent({ level }); + expect(mockLog.send).toHaveBeenCalledTimes(1); + }); +});