tests: fix OpenVSX service tests (#5893)
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
@@ -2,20 +2,12 @@
|
||||
|
||||
const Joi = require('joi')
|
||||
const { optionalNonNegativeInteger } = require('../validators')
|
||||
const { BaseJsonService, NotFound } = require('..')
|
||||
const { BaseJsonService } = require('..')
|
||||
|
||||
const extensionQuerySchema = Joi.object({
|
||||
error: Joi.string(),
|
||||
version: Joi.string().when('error', {
|
||||
is: Joi.exist(),
|
||||
then: Joi.optional(),
|
||||
otherwise: Joi.required(),
|
||||
}),
|
||||
timestamp: Joi.string().isoDate().when('error', {
|
||||
is: Joi.exist(),
|
||||
then: Joi.optional(),
|
||||
otherwise: Joi.required(),
|
||||
}),
|
||||
version: Joi.string().required(),
|
||||
timestamp: Joi.string().isoDate().required(),
|
||||
downloadCount: optionalNonNegativeInteger,
|
||||
reviewCount: optionalNonNegativeInteger,
|
||||
averageRating: Joi.number().when('reviewCount', {
|
||||
@@ -46,17 +38,8 @@ module.exports = class OpenVSXBase extends BaseJsonService {
|
||||
}`,
|
||||
errorMessages: {
|
||||
400: 'invalid extension id',
|
||||
404: 'extension not found',
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
transform({ json }) {
|
||||
const { error, version } = json
|
||||
if (error || !version) {
|
||||
throw new NotFound({
|
||||
prettyMessage: 'extension not found',
|
||||
})
|
||||
}
|
||||
return json
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,9 +47,11 @@ module.exports = class OpenVSXDownloads extends OpenVSXBase {
|
||||
}
|
||||
|
||||
async handle({ namespace, extension, version }) {
|
||||
const json = await this.fetch({ namespace, extension, version })
|
||||
const { version: tag, downloadCount } = this.transform({ json })
|
||||
|
||||
const { version: tag, downloadCount } = await this.fetch({
|
||||
namespace,
|
||||
extension,
|
||||
version,
|
||||
})
|
||||
return this.constructor.render({
|
||||
version: version ? tag : undefined,
|
||||
downloads: downloadCount,
|
||||
|
||||
@@ -67,9 +67,10 @@ module.exports = class OpenVSXRating extends OpenVSXBase {
|
||||
}
|
||||
|
||||
async handle({ format, namespace, extension }) {
|
||||
const json = await this.fetch({ namespace, extension })
|
||||
const { averageRating, reviewCount } = this.transform({ json })
|
||||
|
||||
const { averageRating, reviewCount } = await this.fetch({
|
||||
namespace,
|
||||
extension,
|
||||
})
|
||||
return this.constructor.render({
|
||||
format,
|
||||
averageRating,
|
||||
|
||||
@@ -36,9 +36,7 @@ module.exports = class OpenVSXReleaseDate extends OpenVSXBase {
|
||||
}
|
||||
|
||||
async handle({ namespace, extension }) {
|
||||
const json = await this.fetch({ namespace, extension })
|
||||
const { timestamp } = this.transform({ json })
|
||||
|
||||
const { timestamp } = await this.fetch({ namespace, extension })
|
||||
return this.constructor.render({
|
||||
releaseDate: timestamp,
|
||||
})
|
||||
|
||||
@@ -25,9 +25,7 @@ module.exports = class OpenVSXVersion extends OpenVSXBase {
|
||||
}
|
||||
|
||||
async handle({ namespace, extension }) {
|
||||
const json = await this.fetch({ namespace, extension })
|
||||
const { version } = this.transform({ json })
|
||||
|
||||
const { version } = await this.fetch({ namespace, extension })
|
||||
return this.constructor.render({ version })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user