Skip to content

Commit

Permalink
Throw NotFound when license not found
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoffSelby committed May 18, 2021
1 parent ffaa723 commit c8692bc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions services/packagist/packagist-license.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const Joi = require('joi')
const { renderLicenseBadge } = require('../licenses')
const { optionalUrl } = require('../validators')
const { NotFound } = require('..')
const {
keywords,
BasePackagistService,
Expand Down Expand Up @@ -60,6 +61,10 @@ module.exports = class PackagistLicense extends BasePackagistService {

const license = json.packages[packageName][0].license

if (!license) {
throw new NotFound({ prettyMessage: 'license not found' })
}

return { license }
}

Expand Down
26 changes: 26 additions & 0 deletions services/packagist/packagist-license.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const { expect } = require('chai')
const { NotFound } = require('..')
const PackagistLicense = require('./packagist-license.service')

describe('PackagistLicense', function () {
Expand Down Expand Up @@ -30,4 +31,29 @@ describe('PackagistLicense', function () {
.to.have.property('license')
.that.equals('MIT-latest')
})

it('should throw NotFound when license key not in response', function () {
const json = {
packages: {
'frodo/the-one-package': [
{
version: '1.2.4',
},
{
version: '1.2.3',
},
],
},
}

expect(() =>
PackagistLicense.prototype.transform({
json,
user: 'frodo',
repo: 'the-one-package',
})
)
.to.throw(NotFound)
.with.property('prettyMessage', 'license not found')
})
})

0 comments on commit c8692bc

Please sign in to comment.