Skip to content
Permalink
Browse files
Merge pull request web#19 from nathwan2/master
s
  • Loading branch information
aa7401 committed Oct 26, 2019
2 parents e12506b + ece3438 commit afa4426424f2fe365423bdc3392d783d3ff5f340
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 7 deletions.
@@ -10,3 +10,4 @@ const port = 8080
app.use(async ctx => ctx.body = 'Hello World')

module.exports = app.listen(port, () => console.log(`listening on port ${port}`))
//aasd
@@ -37,21 +37,46 @@ router.get('/anon', ctx => {
// anon case
})

router.get('/books/:index', ctx => {
const books = ['The Hobbit', 'Alice in Wonderland', 'The Secret Garden']
router.get('/books/:index/:index2', ctx => {
const books = ['The Hobbit', 'Alice in Wonderland', 'The Secret Garden','Animal Farm']
const parameters = ctx.params
console.log(parameters)
const title = books[parameters.index]
ctx.body = title


if (parameters.index > 3 || parameters.index2 > 3) {
ctx.body = "Number cannot be greater than 3"
}
else if (isNaN(parameters.index) || isNaN(parameters.index2)){
ctx.body = "A number must be entered"
}
else if (Number.isInteger(parameters.index)){
ctx.body = "A whole number must be entered"
}
else{
const title = books[parameters.index]
const title2 = books[parameters.index2]
ctx.body = title + title2
}
})

router.get('/name', ctx => ctx.body = JSON.stringify(ctx.query))

router.get('/hello/:name', ctx => {
let myname = ctx.params.name
if(ctx.query.format === 'upper') myname = myname.toUpperCase()
else if (ctx.query.format === 'lower') myname = myname.toLowerCase()
else if (ctx.query.format === 'reverse'){
var array1 = myname.split("")
console.log(array1)
var array2 = array1.reverse()
console.log(array2)
var array3 = array1.join("")
console.log(array3)
ctx.body = `hello ${array3}`
//myname = join(Array.reverse(myname.split()))
}
// only applies uppercase if formatting query exists
ctx.body = `hello ${myname}`
//ctx.body = `hello ${myname}`
})

router.post('/form', ctx => {
@@ -9,8 +9,22 @@ module.exports.clear = () => {

module.exports.add = (item, qty) => {
qty = Number(qty)
<<<<<<< HEAD
if(isNaN(qty)) throw new Error('the quantity must be a number')
let flag = false
for(let index in data) {
if (data[index].item === item) {
data[index].qty+= qty
flag = true
}
}
if(flag === false) {
data.push({item: item, qty: qty})
}
=======
if(isNaN(qty)) throw new Error('qty must be a number')
data.push({item: item, qty: qty})
>>>>>>> upstream/master
}

module.exports.getAll = () => {
@@ -10,7 +10,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"handlebars": "^4.2.0",
"handlebars": "^4.3.0",
"http-status-codes": "^1.3.2",
"koa": "^2.8.1",
"koa-bodyparser": "^4.2.1",
@@ -41,8 +41,26 @@ describe('add()', () => {
done()
}
})

// New test goes HERE!
test('duplicates should increase qty', async done => {
expect.assertions(2)
try {
// ACT
todo.add('bread', 4)
todo.add('bread', 2)
// ASSERT
const count = todo.countItems()
expect(count).toBe(1)
const data = todo.getAll()
const qty = data[0].qty
expect(qty).toEqual(6)
} catch(err) {
done.fail('test failed')
} finally {
done()
}
})

})

@@ -0,0 +1,19 @@
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'test' ]
2 info using npm@3.5.2
3 info using node@v8.10.0
4 verbose stack Error: ENOENT: no such file or directory, open '/home/anir/foundation/package.json'
5 verbose cwd /home/anir/foundation
6 error Linux 5.0.0-23-generic
7 error argv "/usr/bin/node" "/usr/bin/npm" "run" "test"
8 error node v8.10.0
9 error npm v3.5.2
10 error path /home/anir/foundation/package.json
11 error code ENOENT
12 error errno -2
13 error syscall open
14 error enoent ENOENT: no such file or directory, open '/home/anir/foundation/package.json'
15 error enoent ENOENT: no such file or directory, open '/home/anir/foundation/package.json'
15 error enoent This is most likely not a problem with npm itself
15 error enoent and is related to npm not being able to find a file.
16 verbose exit [ -2, true ]

0 comments on commit afa4426

Please sign in to comment.