This repository has been archived by the owner on Apr 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtest-search-utils.js
60 lines (51 loc) · 1.81 KB
/
test-search-utils.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
import assert from 'assert';
import querystring from 'querystring';
import { createPreprintQs, apifyPreprintQs } from '../src/utils/search';
import {
arXivId,
crossrefDoi,
openAireDoi
} from './utils/create-preprint-server';
describe('search utils', () => {
describe('createPreprintQs and apifyPreprintQs', () => {
it('should create qs in the default case', () => {
const ui = createPreprintQs();
assert.equal(ui, undefined);
assert(apifyPreprintQs(ui).startsWith('?'));
});
it('should create qs in the bookmark case', () => {
const ui = createPreprintQs();
assert(apifyPreprintQs(ui, 'bookmark').includes('bookmark=bookmark'));
});
it('should create qs in the search case', () => {
const ui = createPreprintQs({
text: 'text',
hasReviews: true,
subjects: ['influenza', 'zika'],
sort: 'new'
});
assert.equal(
ui,
'?q=text&reviews=true&sort=new&subject=influenza%2Czika'
);
const p = querystring.parse(apifyPreprintQs(ui).substring(1));
assert.equal(
p.q,
'(name:"text" OR name:text*) AND hasReviews:true AND (subjectName:"influenza" OR subjectName:"zika")'
);
});
it('should allow multiple terms to be used', () => {
const ui = createPreprintQs({ text: ['text1', 'text2'] });
assert.equal(ui, '?q=text1&q=text2');
const p = querystring.parse(apifyPreprintQs(ui).substring(1));
assert.equal(p.q, '(name:"text1" OR name:text1* OR name:"text2" OR name:text2*)' );
});
it('should handle DOI and arXivId', () => {
const ui = createPreprintQs({
text: `text ${arXivId} ${crossrefDoi} ${openAireDoi}`
});
const api = apifyPreprintQs(ui);
assert(api.includes('+OR+doi') && api.includes('+OR+arXivId'));
});
});
});