Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
fix(Api): better names for metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Thore3 committed Aug 16, 2017
1 parent 2bd216f commit b76adc0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
8 changes: 3 additions & 5 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,9 @@ API.prototype.incrementLoginViaQrStats = function () {
};

This comment has been minimized.

Copy link
@ethereum772

ethereum772 Aug 16, 2017

How do I change the API URL?

This comment has been minimized.

Copy link
@jtormey

jtormey Aug 16, 2017

Contributor

Not sure I understand, would you mind opening a github issue with more details as to what your question is about? Thanks :)

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 () {
Expand Down
20 changes: 6 additions & 14 deletions tests/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
})
})
});

1 comment on commit b76adc0

@Artic2019
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тест

Please sign in to comment.