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:
Caleb Cartwright
2020-12-05 18:12:54 -06:00
committed by GitHub
parent f0eabce923
commit c8ef4ec980
5 changed files with 15 additions and 33 deletions

View File

@@ -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
}
}

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,
})

View File

@@ -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 })
}
}