-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
123 lines (115 loc) · 3.02 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
const tap = require('tap')
const uriMatch = require('./').uriMatch
const negativeTests = [
'/en',
'/zh',
'/whatever',
'/something/other-thing/whatever',
'/something/other-thing/whatever?with=a%20querystring'
]
const positiveTests = [
{
source: '/e/content/cat_page.asp?cat_id=211',
expected: '/en/our-program/certification-and-audit/factory-lookup'
},
{
source: '/s/content/cat_page.asp?cat_id=211',
expected: '/zh/our-program-zh/certification-audit-zh/factory-lookup-zh'
},
{
source: '/e/content/cat_page.asp?cat_id=206',
expected: '/en/resources'
},
{
source: '/s/content/cat_page.asp?cat_id=206',
expected: '/zh/resources-zh'
},
{
source: '/e/content/cat_page.asp?cat_id=191',
expected: '/en/factories'
},
{
source: '/s/content/cat_page.asp?cat_id=191',
expected: '/zh/factories-zh'
},
{
source: '/e/content/cat_page.asp?cat_id=257',
expected: '/en/resources/factory-resources/etp-audit-protocol-handbook'
},
{
source: '/s/content/cat_page.asp?cat_id=257',
expected: '/zh/resources-zh/factory-resources-zh/etp-audit-protocol-handbook-zh'
},
{
source: '/e/content/cat_page.asp?cat_id=273',
expected: '/en/resources/factory-resources/etp-guidelines'
},
{
source: '/s/content/cat_page.asp?cat_id=273',
expected: '/zh/resources-zh/factory-resources-zh/etp-guidelines-zh'
},
{
source: '/e/content/cat_page.asp?cat_id=194',
expected: '/en/resources/factory-resources/policies'
},
{
source: '/s/content/cat_page.asp?cat_id=194',
expected: '/zh/resources-zh/factory-resources-zh/policies-zh'
},
{
source: '/uploadfileMgnt/01_201742117591.pdf',
expected: '/en/resources/factory-resources/factory-welcome-pack'
},
{
source: '/uploadfileMgnt/01_2017421182447.pdf',
expected: '/zh/resources-zh/factory-resources-zh/factory-welcome-pack-zh'
},
{
source: '/e/content/cat_page.asp?cat_id=290',
expected: '/en'
},
{
source: '/s/content/cat_page.asp?cat_id=290',
expected: '/zh'
},
{
source: '/e/content/cat_page.asp?cat_id=284',
expected: '/en/news-and-events'
},
{
source: '/s/content/cat_page.asp?cat_id=284',
expected: '/zh/news-and-events-zh'
},
{
source: 'e/content/cont_page.asp?content_id=401',
expected: '/en/introducing-the-ethical-toy-program'
},
{
source: 's/content/cont_page.asp?content_id=401',
expected: '/zh/introducing-the-ethical-toy-program-zh'
},
{
source: 'e/default.asp',
expected: '/en'
},
{
source: 's/default.asp',
expected: '/zh'
}
]
negativeTests.forEach(source => {
const [uri, querystring] = source.split('?')
const request = {uri, querystring}
const result = uriMatch({request})
tap.same(result, {})
})
positiveTests.forEach(({source, expected}, index) => {
const [uri, querystring] = source.split('?')
const request = {uri, querystring}
const result = uriMatch({request})
const expectedResult = {
status: 301,
to: expected
}
tap.same(result, expectedResult)
})