-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
129 lines (118 loc) · 4.14 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
'use strict';
const { GDriveError, getItemId, fetchInfo } = require('./');
const test = require('tape');
const isUrl = str => /^https?:\/\//.test(str);
test('Extract item id from `open` link', t => {
const id = '1ObJEVgO6Y4cFjfxszUb1LhdyeKrq_wGD';
const url = `https://drive.google.com/open?id=${id}`;
t.plan(1);
t.equals(getItemId(url), id, `extracted id=${id}`);
});
test('Extract item id from `view` link', t => {
const id = '1ObJEVgO6Y4cFjfxszUb1LhdyeKrq_wGD';
const url = `https://drive.google.com/file/d/${id}/view?usp=sharing`;
t.plan(1);
t.equals(getItemId(url), id, `extracted id=${id}`);
});
test('Extract item id from `edit` link', t => {
const id = '1OHA32KWVF21s0ahDMr8Qv2oDamQuLNoYkTN0N_RuRXA';
const url = `https://docs.google.com/document/d/1OHA32KWVF21s0ahDMr8Qv2oDamQuLNoYkTN0N_RuRXA/edit`;
t.plan(1);
t.equals(getItemId(url), id, `extracted id=${id}`);
});
test('Use invalid item id', async t => {
t.plan(2);
try {
await fetchInfo('Invalid **video** id');
} catch (err) {
t.equals(err.name, TypeError.name, 'throws TypeError');
t.equals(err.message, 'Invalid ID provided.', `with message: ${err.message}`);
}
});
test('Fetch public video info', async t => {
const id = '1ObJEVgO6Y4cFjfxszUb1LhdyeKrq_wGD';
const url = `https://drive.google.com/open?id=${id}`;
const expected = {
disposition: 'TOO_LARGE',
fileName: 'big-buck-bunny-720p-h264.mp4',
scanResult: 'WARNING',
sizeBytes: 158008374
};
const info = await fetchInfo(url);
t.plan(4);
t.equals(info && info.sizeBytes, expected.sizeBytes, 'correct file fetched (size match)');
t.equals(info && info.fileName, expected.fileName, 'correct filename');
const downloadUrl = info && info.downloadUrl;
t.assert(
downloadUrl && isUrl(downloadUrl) && downloadUrl.endsWith(id),
`correct url=${downloadUrl}`
);
const thumbnailUrl = await info.thumbnailUrl({ width: 1280, height: 720 });
t.assert(
thumbnailUrl && isUrl(thumbnailUrl),
`thumbnail url=${thumbnailUrl}`
);
});
test('Fetch missing video info', async t => {
const url = 'https://drive.google.com/open?id=dummy_gO6Y4cFjfxszUb1LhdyeKrq_wGD';
t.plan(2);
try {
await fetchInfo(url);
} catch (err) {
t.equals(err.name, GDriveError.name, 'throws GDriveError');
t.equals(err.message, 'Item is not found.', `with message: ${err.message}`);
}
});
test('Fetch private video info', async t => {
const url = 'https://drive.google.com/open?id=1-AszYwYOagB6hkvJVgz9cfkwd4nVG4rd';
t.plan(2);
try {
await fetchInfo(url);
} catch (err) {
t.equals(err.name, GDriveError.name, 'throws GDriveError');
t.equals(err.message, 'Item is not accessible.', `with message: ${err.message}`);
}
});
test('Fetch picture info', async t => {
const id = '1X-1PiZWpgZrpmBcVpyUPSuz_7hI383LC';
const url = `https://drive.google.com/open?id=${id}`;
const expected = {
disposition: 'SCAN_CLEAN',
fileName: 'flower.png',
scanResult: 'OK',
sizeBytes: 114590
};
const info = await fetchInfo(url);
t.plan(4);
t.equals(info && info.sizeBytes, expected.sizeBytes, 'correct file fetched (size match)');
t.equals(info && info.fileName, expected.fileName, 'correct filename');
const downloadUrl = info && info.downloadUrl;
t.assert(
downloadUrl && isUrl(downloadUrl) && downloadUrl.endsWith(id),
`correct url=${downloadUrl}`
);
const thumbnailUrl = await info.thumbnailUrl({ width: 256, height: 256 });
t.assert(
thumbnailUrl && isUrl(thumbnailUrl),
`thumbnail url=${thumbnailUrl}`
);
});
test('Fetch .txt file info', async t => {
const id = '1oTQi2sxyTRHHhKoviK_YJCO6nPh7Obmf';
const url = `https://drive.google.com/open?id=${id}`;
const expected = {
disposition: 'NO_SCAN_NEEDED',
fileName: 'dummy.txt',
scanResult: 'OK',
sizeBytes: 0
};
const info = await fetchInfo(url);
t.plan(3);
t.equals(info && info.sizeBytes, expected.sizeBytes, 'correct file fetched (size match)');
t.equals(info && info.fileName, expected.fileName, 'correct filename');
const downloadUrl = info && info.downloadUrl;
t.assert(
downloadUrl && isUrl(downloadUrl) && downloadUrl.endsWith(id),
`correct url=${downloadUrl}`
);
});