From fae1963445a6ebc27fc090225855e757d30c5fb5 Mon Sep 17 00:00:00 2001 From: Anir Nathwani Date: Tue, 17 Sep 2019 14:51:43 +0100 Subject: [PATCH 1/5] 1.3.2 --- exercises/02_http/01_url/index.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/exercises/02_http/01_url/index.js b/exercises/02_http/01_url/index.js index c7a9340a..30eac127 100644 --- a/exercises/02_http/01_url/index.js +++ b/exercises/02_http/01_url/index.js @@ -37,12 +37,17 @@ 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) { + ctx.body = "Number cannot be greater than 3" + }else{ + const title = books[parameters.index] + const title2 = books[parameters.index2] + ctx.body = title + title2 + parameters.index + } }) router.get('/name', ctx => ctx.body = JSON.stringify(ctx.query)) From 83c9e2ddf4ece2995a23c27378f0f0a1b2b14feb Mon Sep 17 00:00:00 2001 From: Anir Nathwani Date: Tue, 24 Sep 2019 13:07:44 +0100 Subject: [PATCH 2/5] update --- exercises/02_http/01_url/index.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/exercises/02_http/01_url/index.js b/exercises/02_http/01_url/index.js index 30eac127..912dc44a 100644 --- a/exercises/02_http/01_url/index.js +++ b/exercises/02_http/01_url/index.js @@ -41,12 +41,21 @@ 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) - if (parameters.index > 3) { + + + if (parameters.index > 3 || parameters.index2 > 3) { ctx.body = "Number cannot be greater than 3" - }else{ + } + 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 + parameters.index + ctx.body = title + title2 } }) @@ -55,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 => { From 847df4b9e8bd2d7c2781112653c9d3b7b4ce7690 Mon Sep 17 00:00:00 2001 From: Anir Nathwani Date: Tue, 24 Sep 2019 14:46:15 +0100 Subject: [PATCH 3/5] update --- exercises/07_unit_testing/todo/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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", From 6f04e7d7f1b69b0076b099454de1d8d7c38f0bbf Mon Sep 17 00:00:00 2001 From: Anir Nathwani Date: Fri, 27 Sep 2019 10:59:51 +0100 Subject: [PATCH 4/5] test --- exercises/01_setup/index.js | 1 + 1 file changed, 1 insertion(+) 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 From cae34b63aaecffb72e83cbd0d94a54d460420d13 Mon Sep 17 00:00:00 2001 From: Anir Nathwani Date: Tue, 8 Oct 2019 14:25:37 +0100 Subject: [PATCH 5/5] push --- .../07_unit_testing/todo/modules/todo.js | 11 +++++++++- .../todo/unit tests/todo.spec.js | 20 ++++++++++++++++++- npm-debug.log | 19 ++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 npm-debug.log diff --git a/exercises/07_unit_testing/todo/modules/todo.js b/exercises/07_unit_testing/todo/modules/todo.js index 5a034683..c03b8174 100644 --- a/exercises/07_unit_testing/todo/modules/todo.js +++ b/exercises/07_unit_testing/todo/modules/todo.js @@ -10,7 +10,16 @@ module.exports.clear = () => { module.exports.add = (item, qty) => { qty = Number(qty) if(isNaN(qty)) throw new Error('the quantity must be a number') - data.push({item: item, qty: qty}) + 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}) + } } module.exports.getAll = () => { 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 ]