-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathdiscourse.tester.js
149 lines (135 loc) · 3.85 KB
/
discourse.tester.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import Joi from 'joi'
import { ServiceTester } from '../tester.js'
export const t = new ServiceTester({
id: 'discourse',
title: 'Discourse',
})
const dataCases = [
{
// Singular form
topic_count: 22513,
post_count: 337719,
user_count: 31220,
topics_7_days: 143,
topics_30_days: 551,
posts_7_days: 2679,
posts_30_days: 10445,
users_7_days: 204,
users_30_days: 803,
active_users_7_days: 762,
active_users_30_days: 1495,
like_count: 308833,
likes_7_days: 3633,
likes_30_days: 13397,
},
{
// Plural form
topics_count: 22513,
posts_count: 337719,
users_count: 31220,
topics_7_days: 143,
topics_30_days: 551,
posts_7_days: 2679,
posts_30_days: 10445,
users_7_days: 204,
users_30_days: 803,
active_users_7_days: 762,
active_users_30_days: 1495,
likes_count: 308833,
likes_7_days: 3633,
likes_30_days: 13397,
},
]
dataCases.forEach(data => {
t.create('Topics')
.get('/topics.json?server=https://meta.discourse.org')
.intercept(nock =>
nock('https://meta.discourse.org')
.get('/site/statistics.json')
.reply(200, data),
)
.expectBadge({ label: 'discourse', message: '23k topics' })
t.create('Posts')
.get('/posts.json?server=https://meta.discourse.org')
.intercept(nock =>
nock('https://meta.discourse.org')
.get('/site/statistics.json')
.reply(200, data),
)
.expectBadge({ label: 'discourse', message: '338k posts' })
t.create('Users')
.get('/users.json?server=https://meta.discourse.org')
.intercept(nock =>
nock('https://meta.discourse.org')
.get('/site/statistics.json')
.reply(200, data),
)
.expectBadge({ label: 'discourse', message: '31k users' })
t.create('Likes')
.get('/likes.json?server=https://meta.discourse.org')
.intercept(nock =>
nock('https://meta.discourse.org')
.get('/site/statistics.json')
.reply(200, data),
)
.expectBadge({ label: 'discourse', message: '309k likes' })
t.create('Status')
.get('/status.json?server=https://meta.discourse.org')
.intercept(nock =>
nock('https://meta.discourse.org')
.get('/site/statistics.json')
.reply(200, data),
)
.expectBadge({ label: 'discourse', message: 'online' })
t.create('Status with http (not https)')
.get('/status.json?server=http://meta.discourse.org')
.intercept(nock =>
nock('http://meta.discourse.org')
.get('/site/statistics.json')
.reply(200, data),
)
.expectBadge({ label: 'discourse', message: 'online' })
})
t.create('Invalid Host')
.get('/status.json?server=https://some.host')
.intercept(nock =>
nock('https://some.host')
.get('/site/statistics.json')
.reply(404, '<h1>Not Found</h1>'),
)
.expectBadge({ label: 'discourse', message: 'not found' })
t.create('Topics')
.get('/topics.json?server=https://meta.discourse.org')
.expectBadge({
label: 'discourse',
message: Joi.string().regex(
/^([0-9]+[kMGTPEZY]?|[1-9]\.[1-9][kMGTPEZY]) topics$/,
),
})
t.create('Posts')
.get('/posts.json?server=https://meta.discourse.org')
.expectBadge({
label: 'discourse',
message: Joi.string().regex(
/^([0-9]+[kMGTPEZY]?|[1-9]\.[1-9][kMGTPEZY]) posts$/,
),
})
t.create('Users')
.get('/users.json?server=https://meta.discourse.org')
.expectBadge({
label: 'discourse',
message: Joi.string().regex(
/^([0-9]+[kMGTPEZY]?|[1-9]\.[1-9][kMGTPEZY]) users$/,
),
})
t.create('Likes')
.get('/likes.json?server=https://meta.discourse.org')
.expectBadge({
label: 'discourse',
message: Joi.string().regex(
/^([0-9]+[kMGTPEZY]?|[1-9]\.[1-9][kMGTPEZY]) likes$/,
),
})
t.create('Status')
.get('/status.json?server=https://meta.discourse.org')
.expectBadge({ label: 'discourse', message: 'online' })