-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TwitchExtensionVersion] New badge (#6900)
* 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
1 parent
48b7f70
commit 70947e1
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }) |