Skip to content

Commit

Permalink
[TwitchExtensionVersion] New badge (#6900)
Browse files Browse the repository at this point in the history
* Create Twitch Extension Version badge

* skip tests when there's no token

* use renderVersionBadge

* improve joi schema

Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
  • Loading branch information
nixxquality and repo-ranger[bot] committed Aug 19, 2021
1 parent 48b7f70 commit 70947e1
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
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' })

0 comments on commit 70947e1

Please sign in to comment.