From b76adc0b2095fa7cf24c2c0ef3011d3624c51ee1 Mon Sep 17 00:00:00 2001 From: Justin Tormey Date: Wed, 16 Aug 2017 16:02:29 -0400 Subject: [PATCH] fix(Api): better names for metrics --- src/api.js | 8 +++----- tests/api_spec.js | 20 ++++++-------------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/api.js b/src/api.js index 771b8102b..c0d212b68 100644 --- a/src/api.js +++ b/src/api.js @@ -309,11 +309,9 @@ API.prototype.incrementLoginViaQrStats = function () { }; API.prototype.incrementBtcEthUsageStats = function (btcBalance, ethBalance) { - let base = this.ROOT_URL + 'event?name=wallet_login_balance_'; - let makeEventUrl = (curr, cond) => base + curr + '_' + (cond ? 1 : 0); - fetch(makeEventUrl('btc', btcBalance > 0)); - fetch(makeEventUrl('eth', ethBalance > 0)); - fetch(makeEventUrl('btceth', btcBalance > 0 && ethBalance > 0)); + let base = this.ROOT_URL + 'event?name=wallet_login_balance'; + let makeEventUrl = (btc, eth) => `${base}_btc_${btc ? 1 : 0}_eth_${eth ? 1 : 0}`; + fetch(makeEventUrl(btcBalance > 0, ethBalance > 0)); }; API.prototype.getBlockchainAddress = function () { diff --git a/tests/api_spec.js b/tests/api_spec.js index ed00d3843..1ee4d0807 100644 --- a/tests/api_spec.js +++ b/tests/api_spec.js @@ -26,37 +26,29 @@ describe('API', () => { spyOn(window, 'fetch') }) - it('should make three requests, one for each stat', () => { + it('should make one request', () => { API.incrementBtcEthUsageStats(0, 0) - expect(window.fetch).toHaveBeenCalledTimes(3) + expect(window.fetch).toHaveBeenCalledTimes(1) }) it('should record correctly for btc=0, eth=0', () => { API.incrementBtcEthUsageStats(0, 0) - expect(window.fetch).toHaveBeenCalledWith(eventUrl('btc_0')) - expect(window.fetch).toHaveBeenCalledWith(eventUrl('eth_0')) - expect(window.fetch).toHaveBeenCalledWith(eventUrl('btceth_0')) + expect(window.fetch).toHaveBeenCalledWith(eventUrl('btc_0_eth_0')) }) it('should record correctly for btc>0, eth=0', () => { API.incrementBtcEthUsageStats(1, 0) - expect(window.fetch).toHaveBeenCalledWith(eventUrl('btc_1')) - expect(window.fetch).toHaveBeenCalledWith(eventUrl('eth_0')) - expect(window.fetch).toHaveBeenCalledWith(eventUrl('btceth_0')) + expect(window.fetch).toHaveBeenCalledWith(eventUrl('btc_1_eth_0')) }) it('should record correctly for btc=0, eth>0', () => { API.incrementBtcEthUsageStats(0, 1) - expect(window.fetch).toHaveBeenCalledWith(eventUrl('btc_0')) - expect(window.fetch).toHaveBeenCalledWith(eventUrl('eth_1')) - expect(window.fetch).toHaveBeenCalledWith(eventUrl('btceth_0')) + expect(window.fetch).toHaveBeenCalledWith(eventUrl('btc_0_eth_1')) }) it('should record correctly for btc>0, eth>0', () => { API.incrementBtcEthUsageStats(1, 1) - expect(window.fetch).toHaveBeenCalledWith(eventUrl('btc_1')) - expect(window.fetch).toHaveBeenCalledWith(eventUrl('eth_1')) - expect(window.fetch).toHaveBeenCalledWith(eventUrl('btceth_1')) + expect(window.fetch).toHaveBeenCalledWith(eventUrl('btc_1_eth_1')) }) }) });