diff --git a/test/api/unit/libs/analyticsService.test.js b/test/api/unit/libs/analyticsService.test.js index c977bef7fc..68177557cb 100644 --- a/test/api/unit/libs/analyticsService.test.js +++ b/test/api/unit/libs/analyticsService.test.js @@ -1,4 +1,5 @@ /* eslint-disable camelcase */ +import nconf from 'nconf'; import Amplitude from 'amplitude'; import { Visitor } from 'universal-analytics'; import * as analyticsService from '../../../../website/server/libs/analyticsService'; @@ -15,6 +16,22 @@ describe('analyticsService', () => { sandbox.restore(); }); + describe('#getServiceByEnvironment', () => { + it('returns mock methods when not in production', () => { + sandbox.stub(nconf, 'get').withArgs('IS_PROD').returns(false); + expect(analyticsService.getAnalyticsServiceByEnvironment()) + .to.equal(analyticsService.mockAnalyticsService); + }); + + it('returns real methods when in production', () => { + sandbox.stub(nconf, 'get').withArgs('IS_PROD').returns(true); + expect(analyticsService.getAnalyticsServiceByEnvironment().track) + .to.equal(analyticsService.track); + expect(analyticsService.getAnalyticsServiceByEnvironment().trackPurchase) + .to.equal(analyticsService.trackPurchase); + }); + }); + describe('#track', () => { let eventType; let data; diff --git a/test/api/unit/libs/payments/payments.test.js b/test/api/unit/libs/payments/payments.test.js index 8b3c03cfd9..79c41995eb 100644 --- a/test/api/unit/libs/payments/payments.test.js +++ b/test/api/unit/libs/payments/payments.test.js @@ -32,8 +32,8 @@ describe('payments/index', () => { sandbox.stub(sender, 'sendTxn'); sandbox.stub(user, 'sendMessage'); - sandbox.stub(analytics, 'trackPurchase'); - sandbox.stub(analytics, 'track'); + sandbox.stub(analytics.mockAnalyticsService, 'trackPurchase'); + sandbox.stub(analytics.mockAnalyticsService, 'track'); sandbox.stub(notifications, 'sendNotification'); data = { @@ -237,8 +237,8 @@ describe('payments/index', () => { it('tracks subscription purchase as gift', async () => { await api.createSubscription(data); - expect(analytics.trackPurchase).to.be.calledOnce; - expect(analytics.trackPurchase).to.be.calledWith({ + expect(analytics.mockAnalyticsService.trackPurchase).to.be.calledOnce; + expect(analytics.mockAnalyticsService.trackPurchase).to.be.calledWith({ uuid: user._id, groupId: undefined, itemPurchased: 'Subscription', @@ -335,8 +335,8 @@ describe('payments/index', () => { it('tracks subscription purchase', async () => { await api.createSubscription(data); - expect(analytics.trackPurchase).to.be.calledOnce; - expect(analytics.trackPurchase).to.be.calledWith({ + expect(analytics.mockAnalyticsService.trackPurchase).to.be.calledOnce; + expect(analytics.mockAnalyticsService.trackPurchase).to.be.calledWith({ uuid: user._id, groupId: undefined, itemPurchased: 'Subscription',