1
0
mirror of https://github.com/badges/shields.git synced 2025-04-18 19:44:04 +03:00
shields/services/discourse/discourse.tester.js
Joshua Newton f6e40a600e
[Discourse] Update schema keys to use plural form (topic_count -> topics_count) (#9778)
* Discourse: Update schema to use plural keys

(e.g. topic_count -> topics_countN)

* Revert "Discourse: Update schema to use plural keys"

This reverts commit 4073a17aaaaa253ce9ef01754ede77ba5deaa7f5.

* `discourse.service.js`: Add `Joi.alternatives` plural schema

* `discourse.service.js`: Update func to be plural-agnostic

Previously, for e.g. 'topic', the call to the `DiscourseMetricIntegrationFactory` function supplied both 'topics' and 'topic_count'. And, we now need to check for 'topics_count' as well. To cover all three string variations, why not supply only 'topic' to the function, then selectively add the 's' on a case-by-case basis.

((Note: I've preserved the old metricName variable as to minimize the diff here and make my changes clearer.))

* `discourse.tester.js`: Add second `data` case

* Address Prettier linting warnings
2023-12-06 19:54:39 +00:00

150 lines
3.9 KiB
JavaScript

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' })