Skip to content

Commit

Permalink
Remove YT dislikes
Browse files Browse the repository at this point in the history
  • Loading branch information
pzygielo committed Dec 22, 2021
1 parent 459a8e5 commit 19b56b1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 53 deletions.
40 changes: 1 addition & 39 deletions services/youtube/youtube-likes.service.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,34 @@
import Joi from 'joi'
import { metric } from '../text-formatters.js'
import { documentation, YouTubeVideoBase } from './youtube-base.js'

const documentationWithDislikes = `
${documentation}
<p>
When enabling the <code>withDislikes</code> option, 👍 corresponds to the number
of likes of a given video, 👎 corresponds to the number of dislikes.
</p>
`

const queryParamSchema = Joi.object({
withDislikes: Joi.equal(''),
}).required()

export default class YouTubeLikes extends YouTubeVideoBase {
static route = {
base: 'youtube/likes',
pattern: ':videoId',
queryParamSchema,
}

static get examples() {
const previewLikes = this.render({
statistics: { likeCount: 7 },
id: 'abBdk8bSPKU',
})
const previewVotes = this.render(
{
statistics: { likeCount: 10236, dislikeCount: 396 },
id: 'pU9Q6oiQNd0',
},
{ withDislikes: '' }
)
// link[] is not allowed in examples
delete previewLikes.link
delete previewVotes.link
return [
{
title: 'YouTube Video Likes',
namedParams: { videoId: 'abBdk8bSPKU' },
staticPreview: previewLikes,
documentation,
},
{
title: 'YouTube Video Likes and Dislikes',
namedParams: { videoId: 'pU9Q6oiQNd0' },
staticPreview: previewVotes,
queryParams: {
withDislikes: null,
},
documentation: documentationWithDislikes,
},
]
}

static render({ statistics, id }, queryParams) {
let renderedBadge = super.renderSingleStat({
const renderedBadge = super.renderSingleStat({
statistics,
statisticName: 'like',
id,
})
if (queryParams && typeof queryParams.withDislikes !== 'undefined') {
renderedBadge = {
...renderedBadge,
message: `${metric(statistics.likeCount)} 👍`,
}
}
return renderedBadge
}
}
15 changes: 1 addition & 14 deletions services/youtube/youtube-likes.tester.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Joi from 'joi'
import { createServiceTester } from '../tester.js'
import { noToken } from '../test-helpers.js'
import { isMetric } from '../test-validators.js'
Expand All @@ -16,21 +15,9 @@ t.create('video like count')
link: ['https://www.youtube.com/video/pU9Q6oiQNd0'],
})

t.create('video vote count')
.skipWhen(noYouTubeToken)
.get('/pU9Q6oiQNd0.json?withDislikes')
.expectBadge({
label: 'likes',
message: Joi.string().regex(
/^([1-9][0-9]*[kMGTPEZY]?|[1-9]\.[1-9][kMGTPEZY]) 👍$/
),
color: 'red',
link: ['https://www.youtube.com/video/pU9Q6oiQNd0'],
})

t.create('video not found')
.skipWhen(noYouTubeToken)
.get('/doesnotexist.json?withDislikes')
.get('/doesnotexist.json')
.expectBadge({
label: 'youtube',
message: 'video not found',
Expand Down

0 comments on commit 19b56b1

Please sign in to comment.