This repository was archived by the owner on Mar 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
110 lines (87 loc) · 2.31 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
import test from 'ava'
import {mediaUrlParser} from './index.js'
import {youtubeDict, fileDict, discogsDict, bandcampDict} from './tests/provider-dictionaries'
/*
Providers, check if they are correctly discovered in a url
*/
test('It throws when it cannot detect a provider', t => {
const error = t.throws(() => {
mediaUrlParser('notanurl')
})
})
test('Youtube URL correctly parses the provider', t => {
t.plan(youtubeDict.length)
youtubeDict.forEach(item => {
let r = mediaUrlParser(item[0])
t.is(r.provider, 'youtube')
})
})
test('Object returned includes a normalized url property', t => {
youtubeDict.forEach(item => {
let r = mediaUrlParser(item[0])
t.truthy(typeof r.url, 'string')
t.is(r.url.includes(item[0]), true)
})
})
test('File URL correctly parses the provider', async t => {
t.plan(fileDict.length)
fileDict.forEach(item => {
let r = mediaUrlParser(item[0])
t.is(r.provider, 'file')
})
})
test('Discogs URL correctly parses the provider', async t => {
t.plan(discogsDict.length)
discogsDict.forEach(item => {
let r = mediaUrlParser(item[0])
t.is(r.provider, 'discogs')
})
})
test('Bandcamp URL correctly parses the provider', async t => {
t.plan(bandcampDict.length)
bandcampDict.forEach(item => {
let r = mediaUrlParser(item[0])
t.is(r.provider, 'bandcamp')
})
})
/*
ID, check if the if is found in a url of a specific provider
*/
test('Youtube URL correctly parses the id', t => {
t.plan(youtubeDict.length)
youtubeDict.forEach(item => {
let r = mediaUrlParser(item[0])
t.is(r.id, item[1])
})
})
test('File URL correctly parses the id', t => {
t.plan(fileDict.length)
fileDict.forEach(item => {
let r = mediaUrlParser(item[0])
t.is(r.id, item[1])
})
})
test('Discogs URL correctly parses the id', t => {
t.plan(discogsDict.length)
discogsDict.forEach(item => {
let r = mediaUrlParser(item[0])
t.is(r.id, item[1])
})
})
test('Bandcamp URL correctly parses the id ', t => {
t.plan(bandcampDict.length)
bandcampDict.forEach(item => {
let r = mediaUrlParser(item[0])
t.is(r.id, item[1])
})
})
/*
Type, check if the type is found in a url of a specific provider
*/
test('Bandcamp URL correctly parses the media type', async t => {
t.plan(bandcampDict.length)
bandcampDict.forEach(item => {
let r = mediaUrlParser(item[0])
t.is(r.type, item[2])
})
})