generated from Richienb/node-module-boilerplate
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.js
32 lines (29 loc) · 1.05 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
import test from 'ava';
import driveUrl from './index.js';
test('main', t => {
t.is(
driveUrl(
'https://drive.google.com/file/d/1Px8bePd7pFSz5r6bTA7GKN9HloCzMfFk/view?usp=sharing',
),
'https://drive.google.com/uc?export=download&id=1Px8bePd7pFSz5r6bTA7GKN9HloCzMfFk',
);
t.is(
driveUrl(
'https://drive.google.com/file/d/1Px8bePd7pFSz5r6bTA7GKN9HloCzMfFk/view?usp=share_link',
),
'https://drive.google.com/uc?export=download&id=1Px8bePd7pFSz5r6bTA7GKN9HloCzMfFk',
);
t.is(
driveUrl(
'https://drive.google.com/file/d/1Px8bePd7pFSz5r6bTA7GKN9HloCzMfFk/view?usp=sharing',
{apiKey: 'foo'},
),
'https://www.googleapis.com/drive/v3/files/1Px8bePd7pFSz5r6bTA7GKN9HloCzMfFk?alt=media&key=foo',
);
});
test('errors', t => {
t.throws(() => driveUrl(null), {message: 'Invalid URL provided.'});
t.throws(() => driveUrl(''), {message: 'Invalid URL provided.'});
t.throws(() => driveUrl('url', {apiKey: ''}), {message: 'Invalid api key provided.'});
t.throws(() => driveUrl('url', {apiKey: '$$$'}), {message: 'Invalid api key provided.'});
});