Skip to content

Commit

Permalink
fix(types): default type should be an IANA STATUS code link
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad Nassri committed Jan 26, 2019
1 parent 0cd9fc0 commit 6c67e08
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ module.exports = class Problem {

if (!title && STATUS_CODES.hasOwnProperty(status)) {
title = STATUS_CODES[status]
}

if (type === DEFAULT_TYPE) {
type = IANA_STATUS_CODES + status
if (type === DEFAULT_TYPE) {
type = IANA_STATUS_CODES + status

// reset base_uri
base = ''
}
// reset base_uri
base = ''
}

if (!title) {
Expand Down
4 changes: 2 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tap.test('API Problem', assert => {
assert.equal(new Problem(402).title, STATUS_CODES[402], '"title" SHOULD be the same as the recommended HTTP status phrase for "status"')
assert.equal(new Problem(402).type, IANA_STATUS_CODES + 402, '"type" should use IANA_STATUS_CODES when using standard "STATUS_CODES" and no "type" provided')

assert.equal(new Problem(444, 'foo').type, DEFAULT_TYPE, `default "type" should be ${DEFAULT_TYPE}`)
assert.equal(new Problem(444, 'foo').type, IANA_STATUS_CODES + 444, `default "type" should be an IANA_STATUS_CODE link`)

Problem.BASE_URI = 'foo://bar/'

Expand All @@ -43,7 +43,7 @@ tap.test('API Problem', assert => {
assert.equal(new Problem(404, 'foo', 'foo://bar/').type, 'foo://bar/', 'custom "type" ')

assert.deepEqual(new Problem(404, { foo: 'bar' }), { status: '404', title: STATUS_CODES[404], type: IANA_STATUS_CODES + 404, foo: 'bar' }, 'members immediatly after "status"')
assert.deepEqual(new Problem(404, 'foo', { foo: 'bar' }), { status: '404', title: 'foo', type: DEFAULT_TYPE, foo: 'bar' }, 'members immediatly after "title"')
assert.deepEqual(new Problem(404, 'foo', { foo: 'bar' }), { status: '404', title: 'foo', type: IANA_STATUS_CODES + 404, foo: 'bar' }, 'members immediatly after "title"')
assert.deepEqual(new Problem(404, 'foo', 'foo://bar/', { foo: 'bar' }), { status: '404', title: 'foo', type: 'foo://bar/', foo: 'bar' }, 'members immediatly after "type"')

Problem.BASE_URI = 'foo://bar/'
Expand Down

0 comments on commit 6c67e08

Please sign in to comment.