forked from ikovac/google-scholarly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
89 lines (81 loc) · 2.81 KB
/
test.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
'use strict';
const nock = require('nock');
const path = require('path');
const Scholar = require('.');
nock.back.fixtures = path.join(__dirname, '__nock_fixtures__');
// NOTE: Retries are disabled due to: https://github.com/nock/nock/issues/1523
beforeAll(() => Scholar.init('dummy', { retries: 0 }));
afterEach(() => nock.restore());
test('search publications', async () => {
const { nockDone } = await nock.back('pub-search.json');
const query = '"A frequency-domain analysis of haptic gratings"';
const pub = await Scholar.searchPub(query);
nockDone();
expect(pub).toEqual(expect.objectContaining({
title: 'A frequency-domain analysis of haptic gratings',
authors: expect.arrayContaining([
expect.objectContaining({ id: '4bahYMkAAAAJ', name: 'SA Cholewiak' }),
expect.objectContaining({ id: 'itUoRvUAAAAJ', name: 'K Kim' }),
expect.objectContaining({ id: 'OiVOAHMAAAAJ', name: 'HZ Tan' })
])
}));
}, 10000);
test('fetch publication authors', async () => {
const { nockDone } = await nock.back('pub-authors.json');
const query = '"A frequency-domain analysis of haptic gratings"';
const authors = await Scholar.getPubAuthors(query);
nockDone();
expect(authors).toEqual(expect.arrayContaining([
expect.objectContaining({
id: '4bahYMkAAAAJ',
name: 'Steven A. Cholewiak, PhD',
// affiliation: 'Vision Scientist',
affiliation: 'Applied Vision Scientist at Google LLC',
homepage: 'http://steven.cholewiak.com/',
interests: [
'Depth Cues',
'3D Shape',
'Shape from Texture & Shading',
'Naive Physics',
'Haptics'
]
}),
expect.objectContaining({
id: 'itUoRvUAAAAJ',
name: 'Kwangtaek Kim',
affiliation: 'Kent State University',
domain: 'cs.kent.edu',
hindex: '12'
}),
expect.objectContaining({
id: 'OiVOAHMAAAAJ',
name: 'Hong Z Tan',
affiliation: 'Professor of ECE, Purdue University',
homepage: 'http://engineering.purdue.edu/~hongtan',
domain: 'purdue.edu',
hindex: '49'
})
]));
}, 10000);
test('handle invalid API key', async () => {
const { nockDone } = await nock.back('invalid-api-key.json');
const query = '"A frequency-domain analysis of haptic gratings"';
try {
await Scholar.searchPub(query);
} catch (error) {
nockDone();
expect(error).toBeInstanceOf(Scholar.ScholarlyError);
expect(error).toBeInstanceOf(Scholar.ProxyError);
}
}, 10000);
test('handle captcha', async () => {
const { nockDone } = await nock.back('captcha.json');
const query = '"A frequency-domain analysis of haptic gratings"';
try {
await Scholar.searchPub(query);
} catch (error) {
nockDone();
expect(error).toBeInstanceOf(Scholar.ScholarlyError);
expect(error).toBeInstanceOf(Scholar.CaptchaError);
}
}, 10000);