refactor [vaadindirectory] badges (#3339)
This commit is contained in:
34
services/vaadin-directory/vaadin-directory-base.js
Normal file
34
services/vaadin-directory/vaadin-directory-base.js
Normal file
@@ -0,0 +1,34 @@
|
||||
'use strict'
|
||||
|
||||
const Joi = require('joi')
|
||||
const { BaseJsonService } = require('..')
|
||||
const { nonNegativeInteger } = require('../validators')
|
||||
|
||||
const schema = Joi.object({
|
||||
ratingCount: nonNegativeInteger,
|
||||
averageRating: Joi.number()
|
||||
.min(0)
|
||||
.required(),
|
||||
latestAvailableRelease: Joi.object({
|
||||
publicationDate: Joi.date().required(),
|
||||
name: Joi.string().required(),
|
||||
}).required(),
|
||||
status: Joi.string().required(),
|
||||
}).required()
|
||||
|
||||
class BaseVaadinDirectoryService extends BaseJsonService {
|
||||
async fetch({ packageName }) {
|
||||
return this._requestJson({
|
||||
schema,
|
||||
url: `https://vaadin.com/vaadincom/directory-service/components/search/findByUrlIdentifier`,
|
||||
options: {
|
||||
qs: {
|
||||
projection: 'summary',
|
||||
urlIdentifier: packageName,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { BaseVaadinDirectoryService }
|
||||
@@ -0,0 +1,46 @@
|
||||
'use strict'
|
||||
|
||||
const { metric } = require('../text-formatters')
|
||||
const { floorCount: floorCountColor } = require('../color-formatters')
|
||||
const { BaseVaadinDirectoryService } = require('./vaadin-directory-base')
|
||||
|
||||
module.exports = class VaadinDirectoryRatingCount extends BaseVaadinDirectoryService {
|
||||
static get category() {
|
||||
return 'rating'
|
||||
}
|
||||
|
||||
static get route() {
|
||||
return {
|
||||
base: 'vaadin-directory',
|
||||
pattern: ':which(rc|rating-count)/:packageName',
|
||||
}
|
||||
}
|
||||
|
||||
static get examples() {
|
||||
return [
|
||||
{
|
||||
title: 'Vaadin Directory',
|
||||
pattern: 'rating-count/:packageName',
|
||||
namedParams: { packageName: 'vaadinvaadin-grid' },
|
||||
staticPreview: this.render({ ratingCount: 6 }),
|
||||
keywords: ['vaadin-directory', 'rating-count', 'rating count'],
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
static get defaultBadgeData() {
|
||||
return { label: 'rating count' }
|
||||
}
|
||||
|
||||
static render({ ratingCount }) {
|
||||
return {
|
||||
message: `${metric(ratingCount)} total`,
|
||||
color: floorCountColor(ratingCount, 5, 50, 500),
|
||||
}
|
||||
}
|
||||
|
||||
async handle({ which, packageName }) {
|
||||
const { ratingCount } = await this.fetch({ packageName })
|
||||
return this.constructor.render({ ratingCount })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
'use strict'
|
||||
|
||||
const Joi = require('joi')
|
||||
const t = (module.exports = require('../tester').createServiceTester())
|
||||
|
||||
t.create('rating count of component')
|
||||
.get('/rating-count/vaadinvaadin-grid.json')
|
||||
.expectBadge({
|
||||
label: 'rating count',
|
||||
message: Joi.string().regex(/^\d+?\stotal$/),
|
||||
})
|
||||
|
||||
t.create('rating count of component')
|
||||
.get('/rc/vaadinvaadin-grid.json')
|
||||
.expectBadge({
|
||||
label: 'rating count',
|
||||
message: Joi.string().regex(/^\d+?\stotal$/),
|
||||
})
|
||||
|
||||
t.create('not found')
|
||||
.get('/rating-count/does-not-exist.json')
|
||||
.expectBadge({
|
||||
label: 'rating count',
|
||||
message: 'not found',
|
||||
})
|
||||
55
services/vaadin-directory/vaadin-directory-rating.service.js
Normal file
55
services/vaadin-directory/vaadin-directory-rating.service.js
Normal file
@@ -0,0 +1,55 @@
|
||||
'use strict'
|
||||
|
||||
const { starRating } = require('../text-formatters')
|
||||
const { floorCount: floorCountColor } = require('../color-formatters')
|
||||
const { BaseVaadinDirectoryService } = require('./vaadin-directory-base')
|
||||
|
||||
module.exports = class VaadinDirectoryRating extends BaseVaadinDirectoryService {
|
||||
static get category() {
|
||||
return 'rating'
|
||||
}
|
||||
|
||||
static get route() {
|
||||
return {
|
||||
base: 'vaadin-directory',
|
||||
pattern: ':which(star|stars|rating)/:packageName',
|
||||
}
|
||||
}
|
||||
|
||||
static get examples() {
|
||||
return [
|
||||
{
|
||||
title: 'Vaadin Directory',
|
||||
pattern: ':which(stars|rating)/:packageName',
|
||||
namedParams: { which: 'rating', packageName: 'vaadinvaadin-grid' },
|
||||
staticPreview: this.render({ which: 'rating', score: 4.75 }),
|
||||
keywords: ['vaadin-directory', 'rating'],
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
static get defaultBadgeData() {
|
||||
return { label: 'rating' }
|
||||
}
|
||||
|
||||
static render({ which, score }) {
|
||||
const rating = (Math.round(score * 10) / 10).toFixed(1)
|
||||
if (which === 'rating') {
|
||||
return {
|
||||
label: 'rating',
|
||||
message: `${rating}/5`,
|
||||
color: floorCountColor(rating, 2, 3, 4),
|
||||
}
|
||||
}
|
||||
return {
|
||||
label: 'stars',
|
||||
message: starRating(rating),
|
||||
color: floorCountColor(rating, 2, 3, 4),
|
||||
}
|
||||
}
|
||||
|
||||
async handle({ which, packageName }) {
|
||||
const { averageRating } = await this.fetch({ packageName })
|
||||
return this.constructor.render({ which, score: averageRating })
|
||||
}
|
||||
}
|
||||
33
services/vaadin-directory/vaadin-directory-rating.tester.js
Normal file
33
services/vaadin-directory/vaadin-directory-rating.tester.js
Normal file
@@ -0,0 +1,33 @@
|
||||
'use strict'
|
||||
|
||||
const Joi = require('joi')
|
||||
const { isStarRating } = require('../test-validators')
|
||||
const t = (module.exports = require('../tester').createServiceTester())
|
||||
|
||||
t.create('stars of component displayed in star icons')
|
||||
.get('/star/vaadinvaadin-grid.json')
|
||||
.expectBadge({
|
||||
label: 'stars',
|
||||
message: isStarRating,
|
||||
})
|
||||
|
||||
t.create('stars of component displayed in star icons')
|
||||
.get('/stars/vaadinvaadin-grid.json')
|
||||
.expectBadge({
|
||||
label: 'stars',
|
||||
message: isStarRating,
|
||||
})
|
||||
|
||||
t.create('rating of the component (eg: 4.2/5)')
|
||||
.get('/rating/vaadinvaadin-grid.json')
|
||||
.expectBadge({
|
||||
label: 'rating',
|
||||
message: Joi.string().regex(/^\d\.\d\/5$/),
|
||||
})
|
||||
|
||||
t.create('not found')
|
||||
.get('/rating/does-not-exist.json')
|
||||
.expectBadge({
|
||||
label: 'rating',
|
||||
message: 'not found',
|
||||
})
|
||||
@@ -0,0 +1,45 @@
|
||||
'use strict'
|
||||
|
||||
const { formatDate } = require('../text-formatters')
|
||||
const { age: ageColor } = require('../color-formatters')
|
||||
const { BaseVaadinDirectoryService } = require('./vaadin-directory-base')
|
||||
|
||||
module.exports = class VaadinDirectoryReleaseDate extends BaseVaadinDirectoryService {
|
||||
static get category() {
|
||||
return 'activity'
|
||||
}
|
||||
|
||||
static get route() {
|
||||
return {
|
||||
base: 'vaadin-directory',
|
||||
pattern: ':which(rd|release-date)/:packageName',
|
||||
}
|
||||
}
|
||||
|
||||
static get examples() {
|
||||
return [
|
||||
{
|
||||
title: 'Vaadin Directory',
|
||||
pattern: 'release-date/:packageName',
|
||||
namedParams: { packageName: 'vaadinvaadin-grid' },
|
||||
staticPreview: this.render({ date: '2018-12-12' }),
|
||||
keywords: ['vaadin-directory', 'date', 'latest release date'],
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
static get defaultBadgeData() {
|
||||
return { label: 'latest release date' }
|
||||
}
|
||||
|
||||
static render({ date }) {
|
||||
return { message: formatDate(date), color: ageColor(date) }
|
||||
}
|
||||
|
||||
async handle({ which, packageName }) {
|
||||
const data = await this.fetch({ packageName })
|
||||
return this.constructor.render({
|
||||
date: data.latestAvailableRelease.publicationDate,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
'use strict'
|
||||
|
||||
const { isFormattedDate } = require('../test-validators')
|
||||
const t = (module.exports = require('../tester').createServiceTester())
|
||||
|
||||
t.create('latest release date of the component (format: yyyy-mm-dd)')
|
||||
.get('/rd/vaadinvaadin-grid.json')
|
||||
.expectBadge({
|
||||
label: 'latest release date',
|
||||
message: isFormattedDate,
|
||||
})
|
||||
|
||||
t.create('latest release date of the component (format: yyyy-mm-dd)')
|
||||
.get('/release-date/vaadinvaadin-grid.json')
|
||||
.expectBadge({
|
||||
label: 'latest release date',
|
||||
message: isFormattedDate,
|
||||
})
|
||||
|
||||
t.create('not found')
|
||||
.get('/release-date/does-not-exist.json')
|
||||
.expectBadge({ label: 'latest release date', message: 'not found' })
|
||||
43
services/vaadin-directory/vaadin-directory-status.service.js
Normal file
43
services/vaadin-directory/vaadin-directory-status.service.js
Normal file
@@ -0,0 +1,43 @@
|
||||
'use strict'
|
||||
|
||||
const { BaseVaadinDirectoryService } = require('./vaadin-directory-base')
|
||||
|
||||
module.exports = class VaadinDirectoryStatus extends BaseVaadinDirectoryService {
|
||||
static get category() {
|
||||
return 'other'
|
||||
}
|
||||
|
||||
static get route() {
|
||||
return {
|
||||
base: 'vaadin-directory/status',
|
||||
pattern: ':packageName',
|
||||
}
|
||||
}
|
||||
|
||||
static get examples() {
|
||||
return [
|
||||
{
|
||||
title: 'Vaadin Directory',
|
||||
namedParams: { packageName: 'vaadinvaadin-grid' },
|
||||
staticPreview: this.render({ status: 'published' }),
|
||||
keywords: ['vaadin-directory', 'status'],
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
static get defaultBadgeData() {
|
||||
return { label: 'vaadin directory' }
|
||||
}
|
||||
|
||||
static render({ status }) {
|
||||
if (status.toLowerCase() === 'published') {
|
||||
return { message: 'published', color: '#00b4f0' }
|
||||
}
|
||||
return { message: 'unpublished' }
|
||||
}
|
||||
|
||||
async handle({ packageName }) {
|
||||
const { status } = await this.fetch({ packageName })
|
||||
return this.constructor.render({ status })
|
||||
}
|
||||
}
|
||||
18
services/vaadin-directory/vaadin-directory-status.tester.js
Normal file
18
services/vaadin-directory/vaadin-directory-status.tester.js
Normal file
@@ -0,0 +1,18 @@
|
||||
'use strict'
|
||||
|
||||
const Joi = require('joi')
|
||||
const t = (module.exports = require('../tester').createServiceTester())
|
||||
|
||||
t.create('publish status of the component')
|
||||
.get('/vaadinvaadin-grid.json')
|
||||
.expectBadge({
|
||||
label: 'vaadin directory',
|
||||
message: Joi.equal('published', 'unpublished'),
|
||||
})
|
||||
|
||||
t.create('not found')
|
||||
.get('/does-not-exist.json')
|
||||
.expectBadge({
|
||||
label: 'vaadin directory',
|
||||
message: 'not found',
|
||||
})
|
||||
@@ -0,0 +1,39 @@
|
||||
'use strict'
|
||||
|
||||
const { renderVersionBadge } = require('../version')
|
||||
const { BaseVaadinDirectoryService } = require('./vaadin-directory-base')
|
||||
|
||||
module.exports = class VaadinDirectoryVersion extends BaseVaadinDirectoryService {
|
||||
static get category() {
|
||||
return 'version'
|
||||
}
|
||||
|
||||
static get route() {
|
||||
return {
|
||||
base: 'vaadin-directory',
|
||||
pattern: ':which(v|version)/:packageName',
|
||||
}
|
||||
}
|
||||
|
||||
static get examples() {
|
||||
return [
|
||||
{
|
||||
title: 'Vaadin Directory',
|
||||
pattern: 'v/:packageName',
|
||||
namedParams: { packageName: 'vaadinvaadin-grid' },
|
||||
staticPreview: renderVersionBadge({ version: 'v5.3.0-alpha4' }),
|
||||
keywords: ['vaadin-directory', 'version', 'latest version'],
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
static get defaultBadgeData() {
|
||||
return { label: 'vaadin directory' }
|
||||
}
|
||||
|
||||
async handle({ which, packageName }) {
|
||||
const data = await this.fetch({ packageName })
|
||||
const lv = data.latestAvailableRelease.name.toLowerCase()
|
||||
return renderVersionBadge({ version: lv })
|
||||
}
|
||||
}
|
||||
25
services/vaadin-directory/vaadin-directory-version.tester.js
Normal file
25
services/vaadin-directory/vaadin-directory-version.tester.js
Normal file
@@ -0,0 +1,25 @@
|
||||
'use strict'
|
||||
|
||||
const { isSemver } = require('../test-validators')
|
||||
const t = (module.exports = require('../tester').createServiceTester())
|
||||
|
||||
t.create('latest version of the component (can have v prefixed or without)')
|
||||
.get('/v/vaadinvaadin-grid.json')
|
||||
.expectBadge({
|
||||
label: 'vaadin directory',
|
||||
message: isSemver,
|
||||
})
|
||||
|
||||
t.create('latest version of the component (can have v prefixed or without)')
|
||||
.get('/version/vaadinvaadin-grid.json')
|
||||
.expectBadge({
|
||||
label: 'vaadin directory',
|
||||
message: isSemver,
|
||||
})
|
||||
|
||||
t.create('not found')
|
||||
.get('/v/does-not-exist.json')
|
||||
.expectBadge({
|
||||
label: 'vaadin directory',
|
||||
message: 'not found',
|
||||
})
|
||||
@@ -1,272 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
const LegacyService = require('../legacy-service')
|
||||
const {
|
||||
makeBadgeData: getBadgeData,
|
||||
makeLabel: getLabel,
|
||||
} = require('../../lib/badge-data')
|
||||
const { checkErrorResponse } = require('../../lib/error-helper')
|
||||
const { metric, starRating, formatDate } = require('../text-formatters')
|
||||
const {
|
||||
floorCount: floorCountColor,
|
||||
age: ageColor,
|
||||
} = require('../color-formatters')
|
||||
|
||||
class VaadinDirectoryRating extends LegacyService {
|
||||
static get category() {
|
||||
return 'rating'
|
||||
}
|
||||
|
||||
static get route() {
|
||||
return {
|
||||
base: 'vaadin-directory',
|
||||
pattern: ':which(rating|stars|rating-count)/:packageName',
|
||||
}
|
||||
}
|
||||
|
||||
static get examples() {
|
||||
return [
|
||||
{
|
||||
title: 'Vaadin Directory',
|
||||
pattern: 'rating/:packageName',
|
||||
namedParams: { packageName: 'vaadinvaadin-grid' },
|
||||
staticPreview: {
|
||||
label: 'rating',
|
||||
message: '5.0/5',
|
||||
color: 'brightgreen',
|
||||
},
|
||||
keywords: ['vaadin-directory', 'rating'],
|
||||
},
|
||||
{
|
||||
title: 'Vaadin Directory',
|
||||
pattern: 'stars/:packageName',
|
||||
namedParams: { packageName: 'vaadinvaadin-grid' },
|
||||
staticPreview: {
|
||||
label: 'stars',
|
||||
message: starRating(4.75),
|
||||
color: 'brightgreen',
|
||||
},
|
||||
keywords: ['vaadin-directory', 'star', 'stars'],
|
||||
},
|
||||
{
|
||||
title: 'Vaadin Directory',
|
||||
pattern: 'rating-count/:packageName',
|
||||
namedParams: { packageName: 'vaadinvaadin-grid' },
|
||||
staticPreview: {
|
||||
label: 'rating count',
|
||||
message: '6 total',
|
||||
color: 'yellow',
|
||||
},
|
||||
keywords: ['vaadin-directory', 'rating-count', 'rating count'],
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
static registerLegacyRouteHandler() {}
|
||||
}
|
||||
|
||||
class VaadinDirectoryVersion extends LegacyService {
|
||||
static get category() {
|
||||
return 'version'
|
||||
}
|
||||
|
||||
static get route() {
|
||||
return {
|
||||
base: 'vaadin-directory/v',
|
||||
pattern: ':packageName',
|
||||
}
|
||||
}
|
||||
|
||||
static get examples() {
|
||||
return [
|
||||
{
|
||||
title: 'Vaadin Directory',
|
||||
namedParams: { packageName: 'vaadinvaadin-grid' },
|
||||
staticPreview: {
|
||||
label: 'latest ver',
|
||||
message: 'v5.3.0-alpha4',
|
||||
color: '00b4f0',
|
||||
},
|
||||
keywords: ['vaadin-directory', 'version', 'latest version'],
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
static registerLegacyRouteHandler() {}
|
||||
}
|
||||
|
||||
class VaadinDirectoryStatus extends LegacyService {
|
||||
static get category() {
|
||||
return 'other'
|
||||
}
|
||||
|
||||
static get route() {
|
||||
return {
|
||||
base: 'vaadin-directory/status',
|
||||
pattern: ':packageName',
|
||||
}
|
||||
}
|
||||
|
||||
static get examples() {
|
||||
return [
|
||||
{
|
||||
title: 'Vaadin Directory',
|
||||
namedParams: { packageName: 'vaadinvaadin-grid' },
|
||||
staticPreview: {
|
||||
label: 'vaadin directory',
|
||||
message: 'published',
|
||||
color: '00b4f0',
|
||||
},
|
||||
keywords: ['vaadin-directory', 'status'],
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
static registerLegacyRouteHandler() {}
|
||||
}
|
||||
|
||||
class VaadinDirectoryReleaseDate extends LegacyService {
|
||||
static get category() {
|
||||
return 'activity'
|
||||
}
|
||||
|
||||
static get route() {
|
||||
return {
|
||||
base: 'vaadin-directory/release-date',
|
||||
pattern: ':packageName',
|
||||
}
|
||||
}
|
||||
|
||||
static get examples() {
|
||||
return [
|
||||
{
|
||||
title: 'Vaadin Directory',
|
||||
namedParams: { packageName: 'vaadinvaadin-grid' },
|
||||
staticPreview: {
|
||||
label: 'latest release date',
|
||||
message: 'last wednesday',
|
||||
color: 'brightgreen',
|
||||
},
|
||||
keywords: ['vaadin-directory', 'date', 'latest release date'],
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
static registerLegacyRouteHandler() {}
|
||||
}
|
||||
|
||||
// This legacy service should be rewritten to use e.g. BaseJsonService.
|
||||
//
|
||||
// Tips for rewriting:
|
||||
// https://github.com/badges/shields/blob/master/doc/rewriting-services.md
|
||||
//
|
||||
// Do not base new services on this code.
|
||||
class VaadinDirectory extends LegacyService {
|
||||
static get category() {
|
||||
return 'other'
|
||||
}
|
||||
|
||||
static get route() {
|
||||
return {
|
||||
base: 'vaadin-directory',
|
||||
pattern:
|
||||
':which(star|stars|status|rating|rc|rating-count|v|version|rd|release-date)/:urlIdentifier',
|
||||
}
|
||||
}
|
||||
|
||||
static registerLegacyRouteHandler({ camp, cache }) {
|
||||
camp.route(
|
||||
/^\/vaadin-directory\/(star|stars|status|rating|rc|rating-count|v|version|rd|release-date)\/(.*).(svg|png|gif|jpg|json)$/,
|
||||
cache((data, match, sendBadge, request) => {
|
||||
const type = match[1] // Field required
|
||||
const urlIdentifier = match[2] // Name of repository
|
||||
const format = match[3] // Format
|
||||
// API URL which contains also authentication info
|
||||
const apiUrl = `https://vaadin.com/vaadincom/directory-service/components/search/findByUrlIdentifier?projection=summary&urlIdentifier=${urlIdentifier}`
|
||||
|
||||
// Set left-side text to 'Vaadin-Directory' by default
|
||||
const badgeData = getBadgeData('vaadin directory', data)
|
||||
request(apiUrl, (err, res, buffer) => {
|
||||
if (checkErrorResponse(badgeData, err, res)) {
|
||||
sendBadge(format, badgeData)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const data = JSON.parse(buffer)
|
||||
// Round the rating to 1 points decimal
|
||||
const rating = (Math.round(data.averageRating * 10) / 10).toFixed(1)
|
||||
const ratingCount = data.ratingCount
|
||||
const lv = data.latestAvailableRelease.name.toLowerCase()
|
||||
const ld = data.latestAvailableRelease.publicationDate
|
||||
switch (type) {
|
||||
// Since the first deploy was with `star`, I put the case there
|
||||
// for safety pre-caution
|
||||
case 'star':
|
||||
case 'stars': // Stars
|
||||
badgeData.text[0] = getLabel('stars', data)
|
||||
badgeData.text[1] = starRating(rating)
|
||||
badgeData.colorscheme = floorCountColor(rating, 2, 3, 4)
|
||||
break
|
||||
case 'status': {
|
||||
// Status of the component
|
||||
const isPublished = data.status.toLowerCase()
|
||||
if (isPublished === 'published') {
|
||||
badgeData.text[1] = 'published'
|
||||
badgeData.colorB = '#00b4f0'
|
||||
} else {
|
||||
badgeData.text[1] = 'unpublished'
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'rating': // rating
|
||||
badgeData.text[0] = getLabel('rating', data)
|
||||
if (!isNaN(rating)) {
|
||||
badgeData.text[1] = `${rating}/5`
|
||||
badgeData.colorscheme = floorCountColor(rating, 2, 3, 4)
|
||||
}
|
||||
break
|
||||
case 'rc': // rating count
|
||||
case 'rating-count':
|
||||
badgeData.text[0] = getLabel('rating count', data)
|
||||
if (ratingCount && ratingCount !== 0) {
|
||||
badgeData.text[1] = `${metric(data.ratingCount)} total`
|
||||
badgeData.colorscheme = floorCountColor(
|
||||
data.ratingCount,
|
||||
5,
|
||||
50,
|
||||
500
|
||||
)
|
||||
}
|
||||
break
|
||||
case 'v': // latest version
|
||||
case 'version':
|
||||
badgeData.text[0] = getLabel('latest ver', data)
|
||||
badgeData.text[1] = lv
|
||||
badgeData.colorB = '#00b4f0'
|
||||
break
|
||||
case 'rd':
|
||||
case 'release-date': // The release date of the latest version
|
||||
badgeData.text[0] = getLabel('latest release date', data)
|
||||
badgeData.text[1] = formatDate(ld)
|
||||
badgeData.colorscheme = ageColor(ld)
|
||||
break
|
||||
}
|
||||
sendBadge(format, badgeData)
|
||||
} catch (e) {
|
||||
badgeData.text[1] = 'invalid'
|
||||
sendBadge(format, badgeData)
|
||||
}
|
||||
})
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
VaadinDirectoryRating,
|
||||
VaadinDirectoryVersion,
|
||||
VaadinDirectoryStatus,
|
||||
VaadinDirectoryReleaseDate,
|
||||
VaadinDirectory,
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
const Joi = require('joi')
|
||||
const {
|
||||
isSemver,
|
||||
isStarRating,
|
||||
isFormattedDate,
|
||||
} = require('../test-validators')
|
||||
const { ServiceTester } = require('../tester')
|
||||
|
||||
const t = (module.exports = new ServiceTester({
|
||||
id: 'vaadin-directory',
|
||||
title: 'vaadin directory',
|
||||
}))
|
||||
|
||||
t.create('stars of component displayed in star icons')
|
||||
.get('/star/vaadinvaadin-grid.json')
|
||||
.expectBadge({
|
||||
label: 'stars',
|
||||
message: isStarRating,
|
||||
})
|
||||
|
||||
t.create('stars of component displayed in star icons')
|
||||
.get('/stars/vaadinvaadin-grid.json')
|
||||
.expectBadge({
|
||||
label: 'stars',
|
||||
message: isStarRating,
|
||||
})
|
||||
|
||||
t.create('publish status of the component')
|
||||
.get('/status/vaadinvaadin-grid.json')
|
||||
.expectBadge({
|
||||
label: 'vaadin directory',
|
||||
message: Joi.equal(
|
||||
'published',
|
||||
'unpublished',
|
||||
'incomplete',
|
||||
'reported',
|
||||
'suspended',
|
||||
'deleted'
|
||||
),
|
||||
})
|
||||
|
||||
t.create('rating of the component (eg: 4.2/5)')
|
||||
.get('/rating/vaadinvaadin-grid.json')
|
||||
.expectBadge({
|
||||
label: 'rating',
|
||||
message: Joi.string().regex(/^\d\.\d\/5$/),
|
||||
})
|
||||
|
||||
t.create('rating count of component')
|
||||
.get('/rc/vaadinvaadin-grid.json')
|
||||
.expectBadge({
|
||||
label: 'rating count',
|
||||
message: Joi.string().regex(/^\d+?\stotal$/),
|
||||
})
|
||||
|
||||
t.create('rating count of component')
|
||||
.get('/rating-count/vaadinvaadin-grid.json')
|
||||
.expectBadge({
|
||||
label: 'rating count',
|
||||
message: Joi.string().regex(/^\d+?\stotal$/),
|
||||
})
|
||||
|
||||
t.create('latest version of the component (can have v prefixed or without)')
|
||||
.get('/v/vaadinvaadin-grid.json')
|
||||
.expectBadge({
|
||||
label: 'latest ver',
|
||||
message: isSemver,
|
||||
})
|
||||
|
||||
t.create('latest version of the component (can have v prefixed or without)')
|
||||
.get('/version/vaadinvaadin-grid.json')
|
||||
.expectBadge({
|
||||
label: 'latest ver',
|
||||
message: isSemver,
|
||||
})
|
||||
|
||||
t.create('latest release date of the component (format: yyyy-mm-dd)')
|
||||
.get('/rd/vaadinvaadin-grid.json')
|
||||
.expectBadge({
|
||||
label: 'latest release date',
|
||||
message: isFormattedDate,
|
||||
})
|
||||
|
||||
t.create('latest release date of the component (format: yyyy-mm-dd)')
|
||||
.get('/release-date/vaadinvaadin-grid.json')
|
||||
.expectBadge({
|
||||
label: 'latest release date',
|
||||
message: isFormattedDate,
|
||||
})
|
||||
|
||||
t.create('Invalid addon')
|
||||
.get('/stars/404.json')
|
||||
.expectBadge({
|
||||
label: 'vaadin directory',
|
||||
message: 'not found',
|
||||
})
|
||||
|
||||
t.create('No connection')
|
||||
.get('/stars/vaadinvaadin-grid.json')
|
||||
.networkOff()
|
||||
.expectBadge({
|
||||
label: 'vaadin directory',
|
||||
message: 'inaccessible',
|
||||
})
|
||||
Reference in New Issue
Block a user