forked from rawroland/matomo-javascript-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClient.test.ts
36 lines (26 loc) · 1.01 KB
/
Client.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import axios from 'axios';
import {MatomoClient} from '../src';
import {objectToQueryString} from '../src/utils';
import {bareOriginalParameters, baseParameters, parametersWithApiVersion} from './fixtures';
jest.mock('axios');
const siteId = 1;
const trackingEndpoint = `https://example.com/matomo.php`;
const parameterizedEndpoint = `https://example.com/matomo.php?rec=1&idsite=${siteId}`;
describe('Client', () => {
let client: MatomoClient;
beforeEach(() => {
jest.resetModules();
client = new MatomoClient(trackingEndpoint, siteId);
});
it('sends tracking information', async () => {
await client.track(parametersWithApiVersion);
expect(axios.get).toHaveBeenCalledWith(buildUrl(bareOriginalParameters));
});
it('sets the default api version', async () => {
await client.track(baseParameters);
expect(axios.get).toHaveBeenCalledWith(buildUrl(bareOriginalParameters));
});
});
function buildUrl(parameters) {
return parameterizedEndpoint + '&' + objectToQueryString(parameters);
}