-
Notifications
You must be signed in to change notification settings - Fork 539
/
Copy pathsetQueryParameter.js
65 lines (49 loc) · 2.13 KB
/
setQueryParameter.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict';
var SearchParameters = require('../../../src/SearchParameters');
test('setqueryparameter should update existing parameter', function () {
var sp = new SearchParameters({
facets: ['facet'],
});
var newValue = [];
var newsp = sp.setQueryParameter('facets', newValue);
expect(newsp.facets).toEqual(newValue);
});
test('setqueryparameter should add non-existing parameter', function () {
var sp = new SearchParameters({
facets: ['facet'],
});
var newValue = ['attributesToHighlight'];
var newsp = sp.setQueryParameter('attributesToHighlight', newValue);
expect(newsp.attributesToHighlight).toEqual(newValue);
});
test('setQueryParameter should not create a new instance if the update is non effective', function () {
var sp = new SearchParameters({
facets: ['facet'],
maxValuesPerFacet: 10,
});
var newValue = 10;
var newsp = sp.setQueryParameter('maxValuesPerFacet', newValue);
expect(newsp).toEqual(sp);
});
test('setQueryParameter should not throw an error when trying to add an unknown parameter, and actually add it', function () {
var state0 = new SearchParameters();
var state1 = state0.setQueryParameter('betaParameter', 'configValue');
// manual test that the warnonce message actually display message once
state0.setQueryParameter('betaParameter', 'configValue');
expect(state1.betaParameter).toEqual('configValue');
});
test('setQueryParameter should warn about invalid userToken', function () {
const message =
'[algoliasearch-helper] The `userToken` parameter is invalid. This can lead to wrong analytics.\n - Format: [a-zA-Z0-9_-]{1,64}';
console.warn = jest.fn();
var state = new SearchParameters();
state.setQueryParameter('userToken', null);
expect(console.warn).toHaveBeenCalledTimes(1);
expect(console.warn).toHaveBeenLastCalledWith(message);
state.setQueryParameter('userToken', '');
expect(console.warn).toHaveBeenCalledTimes(2);
expect(console.warn).toHaveBeenLastCalledWith(message);
state.setQueryParameter('userToken', 'my invalid token!');
expect(console.warn).toHaveBeenCalledTimes(3);
expect(console.warn).toHaveBeenLastCalledWith(message);
});