-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
77 lines (63 loc) · 2.46 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
const { ok, strictEqual } = require('assert')
const { get } = require('./metaweb')
const winston = require('winston')
const { assert } = require('console')
log = winston.createLogger({
level: 'debug',
transports: [
new (winston.transports.File)({
filename: './test.log',
prepend: true,
level: 'debug'
})
]
})
describe('metaweb', function() {
this.timeout(5000)
it('unshortens', async () => {
const result = await get('https://bit.ly/348J1DN')
strictEqual(result.url, 'https://www.youtube.com/watch?v=oHg5SJYRHA0')
strictEqual(result.status, 200)
strictEqual(result.content_type, 'text/html; charset=utf-8')
})
it('handles bad protocol', async () => {
try {
result = await get('foo')
ok(! result)
} catch(error) {
ok(error.message.match(/Invalid URI/))
}
})
it('handles 404', async () => {
const result = await get('http://example.com/inkdroid')
strictEqual(result.status, 404)
})
it('handles redirect to 404', async () => {
const result = await get('http://bit.ly/2y1xVk6')
strictEqual(result.status, 404)
})
it('handles connection refused', async () => {
try {
const result = await get('http://inkdroid.org:666/')
} catch(error) {
ok(error.message.match(/ECONNREFUSED/))
}
})
it('handles t.co', async () => {
const result = await get('https://t.co/r2mIeyyY7t')
strictEqual(result.url, 'https://www.newshub.co.nz/home/election/2017/08/patrick-gower-bill-english-in-shutdown-mode-over-todd-barclay-texts.html')
strictEqual(result.status, 200)
})
it('handles canonical link', async () => {
const result = await get('https://www.nytimes.com/2017/05/23/opinion/mitch-landrieu-new-orleans-mayor-speech.html?smprod=nytcore-iphone&smid=nytcore-iphone-share&_r=0')
strictEqual(result.canonical, 'https://www.nytimes.com/2017/05/23/opinion/mitch-landrieu-new-orleans-mayor-speech.html')
})
it('extracts metadata', async () => {
const result = await get('https://www.youtube.com/watch?v=oHg5SJYRHA0')
strictEqual(result.title, "RickRoll'D - YouTube")
strictEqual(result.description, "https://www.facebook.com/rickroll548Reddit AMA: https://www.reddit.com/r/IAmA/comments/mx53y/i_am_youtube_user_cotter548_aka_the_inventor_of/As long as troll...")
strictEqual(result.image, 'https://i.ytimg.com/vi/oHg5SJYRHA0/hqdefault.jpg')
strictEqual(result.publisher, 'YouTube')
assert(result.keywords.length > 0)
})
})