Skip to content
Merged
merged 6 commits into from
Oct 26, 2019
Merged

s #19

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions exercises/01_setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
35 changes: 30 additions & 5 deletions exercises/02_http/01_url/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
14 changes: 14 additions & 0 deletions exercises/07_unit_testing/todo/modules/todo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down
2 changes: 1 addition & 1 deletion exercises/07_unit_testing/todo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 19 additions & 1 deletion exercises/07_unit_testing/todo/unit tests/todo.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
})

})

Expand Down
19 changes: 19 additions & 0 deletions npm-debug.log
Original file line number Diff line number Diff line change
@@ -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 ]