Move optional path components to the end for [Debian] and [Ubuntu] (#3409)

Refs https://github.com/badges/shields/pull/3372
This commit is contained in:
Ville Skyttä
2019-05-04 00:05:58 +03:00
committed by Paul Melnikow
parent 001ade3704
commit 742f287f06
4 changed files with 13 additions and 13 deletions

View File

@@ -26,7 +26,7 @@ module.exports = class Debian extends BaseJsonService {
static get route() {
return {
base: 'debian/v',
pattern: ':distribution?/:packageName',
pattern: ':packageName/:distribution?',
}
}
@@ -34,7 +34,7 @@ module.exports = class Debian extends BaseJsonService {
return [
{
title: 'Debian package',
namedParams: { distribution: 'unstable', packageName: 'apt' },
namedParams: { packageName: 'apt', distribution: 'unstable' },
staticPreview: renderVersionBadge({ version: '1.8.0' }),
},
]
@@ -44,7 +44,7 @@ module.exports = class Debian extends BaseJsonService {
return { label: 'debian' }
}
async handle({ distribution = defaultDistribution, packageName }) {
async handle({ packageName, distribution = defaultDistribution }) {
const data = await this._requestJson({
schema,
url: 'https://api.ftp-master.debian.org/madison',

View File

@@ -20,7 +20,7 @@ t.create('Debian package (default distribution, valid, query unsafe chars)')
})
t.create('Debian package (valid, mocked response)')
.get('/unstable/apt.json')
.get('/apt/unstable.json')
.intercept(nock =>
nock('https://api.ftp-master.debian.org')
.get('/madison?f=json&s=unstable&package=apt')
@@ -33,7 +33,7 @@ t.create('Debian package (valid, mocked response)')
.expectBadge({ label: 'debian', message: 'v1.8.0' })
t.create('Debian package (invalid, more than one result)')
.get('/unstable/apt.json')
.get('/apt/unstable.json')
.intercept(nock =>
nock('https://api.ftp-master.debian.org')
.get('/madison?f=json&s=unstable&package=apt')
@@ -49,9 +49,9 @@ t.create('Debian package (invalid, more than one result)')
.expectBadge({ label: 'debian', message: 'invalid response data' })
t.create('Debian package (not found)')
.get('/stable/not-a-package.json')
.get('/not-a-package/stable.json')
.expectBadge({ label: 'debian', message: 'not found' })
t.create('Debian package (distribution not found)')
.get('/not-a-distribution/apt.json')
.get('/apt/not-a-distribution.json')
.expectBadge({ label: 'debian', message: 'not found' })

View File

@@ -22,7 +22,7 @@ module.exports = class Ubuntu extends BaseJsonService {
static get route() {
return {
base: 'ubuntu/v',
pattern: ':series?/:packageName',
pattern: ':packageName/:series?',
}
}
@@ -40,7 +40,7 @@ module.exports = class Ubuntu extends BaseJsonService {
return { label: 'ubuntu' }
}
async fetch({ series, packageName }) {
async fetch({ packageName, series }) {
const seriesParam = series
? {
distro_series: `https://api.launchpad.net/1.0/ubuntu/${encodeURIComponent(
@@ -67,8 +67,8 @@ module.exports = class Ubuntu extends BaseJsonService {
})
}
async handle({ series, packageName }) {
const data = await this.fetch({ series, packageName })
async handle({ packageName, series }) {
const data = await this.fetch({ packageName, series })
if (!data.entries.length) {
throw new NotFound()
}

View File

@@ -13,7 +13,7 @@ t.create('Ubuntu package (default distribution, valid)')
})
t.create('Ubuntu package (valid, mocked response)')
.get('/bionic/ubuntu-wallpapers.json')
.get('/ubuntu-wallpapers/bionic.json')
.intercept(nock =>
nock('https://api.launchpad.net')
.get(
@@ -35,5 +35,5 @@ t.create('Ubuntu package (not found)')
.expectBadge({ label: 'ubuntu', message: 'not found' })
t.create('Ubuntu package (series not found)')
.get('/not-a-series/apt.json')
.get('/apt/not-a-series.json')
.expectBadge({ label: 'ubuntu', message: 'series not found' })