Skip to content

Commit

Permalink
fix bug with null category
Browse files Browse the repository at this point in the history
  • Loading branch information
ttpro1995 committed Jan 8, 2017
1 parent 2110b4a commit 74c4bd1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ thecatapi.linkbuilder = function (category, apiKey, type, size) {
var baselink = 'http://thecatapi.com/api/images/get?'
var link = baselink

if (apiKey !== undefined) {
link = link + 'api_key=' + apiKey
}

if (category !== undefined) {
link = link + '&category=' + category + '&'
}

if (size !== 'small' && size !== 'med' && size !== 'full') {
size = 'full'
}
Expand All @@ -48,6 +40,14 @@ thecatapi.linkbuilder = function (category, apiKey, type, size) {
'type=' + type +
'&size=' + size

if (apiKey !== undefined) {
link = link + '&api_key=' + apiKey
}

if (category !== undefined && category !== null) {
link = link + '&category=' + category
}

return link
}

Expand Down
10 changes: 6 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const assert = require('assert')
// just an simple link with no api, no argument
var simpleLink = thecatapi.linkbuilder()
console.log(simpleLink)
var simpleLink2 = thecatapi.linkbuilder(null, 'MTM1MDM1')
console.log(simpleLink2)

// with category and api
var normalLink = thecatapi.linkbuilder('caturday', 'MTM1MDM1')
Expand All @@ -43,10 +45,10 @@ console.log(customizeLink2)
console.log(customizeLink3)

assert.equal(simpleLink, 'http://thecatapi.com/api/images/get?type=jpg&size=full')
assert.equal(normalLink, 'http://thecatapi.com/api/images/get?api_key=MTM1MDM1&category=caturday&type=jpg&size=full')
assert.equal(customizeLink1, 'http://thecatapi.com/api/images/get?api_key=MTM1MDM1&category=caturday&type=jpg&size=full')
assert.equal(customizeLink2, 'http://thecatapi.com/api/images/get?api_key=MTM1MDM1&category=caturday&type=png&size=med')
assert.equal(customizeLink3, 'http://thecatapi.com/api/images/get?api_key=MTM1MDM1&category=caturday&type=gif&size=small')
assert.equal(normalLink, 'http://thecatapi.com/api/images/get?type=jpg&size=full&api_key=MTM1MDM1&category=caturday')
assert.equal(customizeLink1, 'http://thecatapi.com/api/images/get?type=jpg&size=full&api_key=MTM1MDM1&category=caturday')
assert.equal(customizeLink2, 'http://thecatapi.com/api/images/get?type=png&size=med&api_key=MTM1MDM1&category=caturday')
assert.equal(customizeLink3, 'http://thecatapi.com/api/images/get?type=gif&size=small&api_key=MTM1MDM1&category=caturday')

/*
http://thecatapi.com/api/images/get?type=jpg&size=full
Expand Down

0 comments on commit 74c4bd1

Please sign in to comment.