Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TwitchExtensionVersion] New badge #6900

Merged
merged 5 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions services/twitch/twitch-extension-version.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import Joi from 'joi'
import { renderVersionBadge } from '../version.js'
import TwitchBase from './twitch-base.js'

const helixSchema = Joi.object({
data: Joi.array()
.items(Joi.object({ version: Joi.string().required() }).required())
.min(1)
.required(),
})

export default class TwitchExtensionVersion extends TwitchBase {
static category = 'version'

static route = {
base: 'twitch/extension/v',
pattern: ':extensionId',
}

static examples = [
{
title: 'Twitch Extension Version',
namedParams: {
extensionId: '2nq5cu1nc9f4p75b791w8d3yo9d195',
},
staticPreview: renderVersionBadge({ version: '1.0.0' }),
},
]

static defaultBadgeData = {
label: 'twitch extension',
}

async fetch({ extensionId }) {
const data = this._requestJson({
schema: helixSchema,
url: `https://api.twitch.tv/helix/extensions/released`,
options: {
qs: { extension_id: extensionId },
},
})

return data
}

async handle({ extensionId }) {
const data = await this.fetch({ extensionId })

return renderVersionBadge({ version: data.data[0].version })
}
}
16 changes: 16 additions & 0 deletions services/twitch/twitch-extension-version.tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { isSemver } from '../test-validators.js'
import { createServiceTester } from '../tester.js'
import { noToken } from '../test-helpers.js'
import _noTwitchToken from './twitch.service.js'
const noTwitchToken = noToken(_noTwitchToken)
export const t = await createServiceTester()

t.create('gets the released version of Schedule with Google Calendar')
.skipWhen(noTwitchToken)
.get('/2nq5cu1nc9f4p75b791w8d3yo9d195.json')
.expectBadge({ label: 'twitch extension', message: isSemver })

t.create('invalid extension id')
.skipWhen(noTwitchToken)
.get('/will-never-exist.json')
.expectBadge({ label: 'twitch extension', message: 'not found' })