forked from Richienb/drive-url
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
26 lines (23 loc) · 866 Bytes
/
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
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=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.'});
});