diff --git a/exercises/01_setup/index.js b/exercises/01_setup/index.js index ef00019f..af07c3e0 100644 --- a/exercises/01_setup/index.js +++ b/exercises/01_setup/index.js @@ -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 \ No newline at end of file diff --git a/exercises/02_http/01_url/index.js b/exercises/02_http/01_url/index.js index c7a9340a..912dc44a 100644 --- a/exercises/02_http/01_url/index.js +++ b/exercises/02_http/01_url/index.js @@ -37,12 +37,26 @@ 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)) @@ -50,8 +64,19 @@ 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 => { diff --git a/exercises/07_unit_testing/todo/modules/todo.js b/exercises/07_unit_testing/todo/modules/todo.js index f4fdd7b8..6ce40d22 100644 --- a/exercises/07_unit_testing/todo/modules/todo.js +++ b/exercises/07_unit_testing/todo/modules/todo.js @@ -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 = () => { diff --git a/exercises/07_unit_testing/todo/package.json b/exercises/07_unit_testing/todo/package.json index 8b83c896..ace21014 100644 --- a/exercises/07_unit_testing/todo/package.json +++ b/exercises/07_unit_testing/todo/package.json @@ -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", diff --git a/exercises/07_unit_testing/todo/unit tests/todo.spec.js b/exercises/07_unit_testing/todo/unit tests/todo.spec.js index 55eb70db..2c46bac0 100644 --- a/exercises/07_unit_testing/todo/unit tests/todo.spec.js +++ b/exercises/07_unit_testing/todo/unit tests/todo.spec.js @@ -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() + } + }) }) diff --git a/npm-debug.log b/npm-debug.log new file mode 100644 index 00000000..74e9b8d4 --- /dev/null +++ b/npm-debug.log @@ -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 ]