From 93fafb354f4ee1e5b61cf0d18fd41dd65e44a0fc Mon Sep 17 00:00:00 2001 From: Rishabh Kalakoti Date: Sun, 29 Dec 2019 21:56:11 +0530 Subject: [PATCH 1/9] test: e2e test for fetchtask (incorrect tests/ code) --- .../__e2e__/commands/fetchtask.test.js.md | 131 +++++++++++++++++ .../__e2e__/commands/fetchtask.test.js.snap | Bin 0 -> 944 bytes __e2e__/commands/fetchtask.test.js | 136 ++++++++++++++++++ 3 files changed, 267 insertions(+) create mode 100644 __e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.md create mode 100644 __e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.snap create mode 100644 __e2e__/commands/fetchtask.test.js diff --git a/__e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.md b/__e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.md new file mode 100644 index 0000000..1246d7c --- /dev/null +++ b/__e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.md @@ -0,0 +1,131 @@ +# Snapshot report for `__e2e__/commands/fetchtask.test.js` + +The actual snapshot is saved in `fetchtask.test.js.snap`. + +Generated by [AVA](https://ava.li). + +## display incomplete task with fetchtask key + +> Snapshot 1 + + ` _ _ _ ␊ + | |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊ + | __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊ + | || __/ (_| | (__| | | | (_| (_) | (_| | __/␊ + \\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊ + ␊ +  Learn to code effectively Powered by MadHacks␊ + ␊ + ␊ + User: testConfig Progress: 6/30␊ + ␊ + ␊ + Awesome! Let's move on to Loops. ␊ + Loop is an important statement which is used for repetition of the same code as and when required. ␊ + This task will surely test what you have learnt till now from the previous tasks! ␊ + ␊ + Task 6 ␊ + Syntax of for loop: ␊ + for loop_control_variable in range(start, stop, step): ␊ + Loop Body(indented)␊ + Here's your task: ␊ + ␊ + Task- 6 ␊ + Print even numbers from 1 to 10 (including 10) using for loop.␊ + ` + +> Snapshot 2 + + ` _ _ _ ␊ + | |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊ + | __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊ + | || __/ (_| | (__| | | | (_| (_) | (_| | __/␊ + \\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊ + ␊ +  Learn to code effectively Powered by MadHacks␊ + ␊ + ␊ + This task is already completed!␊ + ␊ + ␊ + User: testConfig Progress: 6/30␊ + ␊ + Awesome! Let's move on to Comparison Operators. They are used to compare two values. They return true or false according to the value of their operands. They are: ==, ===, !=, >, <, >=, <=. Here's your task:␊ + Task 6:-␊ + Use 44 & 29 as your operands. Compare them using the Comparison operators in the same order and print the value which they return.␊ + ␊ + ` + +## display next task with fetchtask + +> Snapshot 1 + + ` _ _ _ ␊ + | |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊ + | __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊ + | || __/ (_| | (__| | | | (_| (_) | (_| | __/␊ + \\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊ + ␊ +  Learn to code effectively Powered by MadHacks␊ + ␊ + ␊ + This task is already completed!␊ + ␊ + ␊ + User: testConfig Progress: 6/30␊ + ␊ + ␊ + Awesome! Let's move on to Loops. ␊ + Loop is an important statement which is used for repetition of the same code as and when required. ␊ + This task will surely test what you have learnt till now from the previous tasks! ␊ + ␊ + Task 6 ␊ + Syntax of for loop: ␊ + for loop_control_variable in range(start, stop, step): ␊ + Loop Body(indented)␊ + Here's your task: ␊ + ␊ + Task- 6 ␊ + Print even numbers from 1 to 10 (including 10) using for loop.␊ + ␊ + ` + +> Snapshot 2 + + ` _ _ _ ␊ + | |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊ + | __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊ + | || __/ (_| | (__| | | | (_| (_) | (_| | __/␊ + \\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊ + ␊ +  Learn to code effectively Powered by MadHacks␊ + ␊ + ␊ + This task is already completed!␊ + ␊ + ␊ + User: testConfig Progress: 6/30␊ + ␊ + Awesome! Let's move on to Comparison Operators. They are used to compare two values. They return true or false according to the value of their operands. They are: ==, ===, !=, >, <, >=, <=. Here's your task:␊ + Task 6:-␊ + Use 44 & 29 as your operands. Compare them using the Comparison operators in the same order and print the value which they return.␊ + ␊ + ` + +## no config file for fetchtask + +> Snapshot 1 + + ` _ _ _ ␊ + | |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊ + | __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊ + | || __/ (_| | (__| | | | (_| (_) | (_| | __/␊ + \\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊ + ␊ +  Learn to code effectively Powered by MadHacks␊ + ␊ + Make sure that you are within the teachcode-solutions directory!␊ + ␊ + cd teachcode-solutions may resolve the issue!␊ + ␊ + ` diff --git a/__e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.snap b/__e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.snap new file mode 100644 index 0000000000000000000000000000000000000000..f54f176f208be9d16fbfa89842e0dab3612060b4 GIT binary patch literal 944 zcmV;h15f-xRzV2%u-C8`)Js*n*00000000B+ zRZ(jdM-<-N5HyQe`X&VATnd_$B=;r}!K*1~UZjl}Y=pK6tdreyvrBe&HZ!yLx^nTQ z&^{KSKJ?9JrGG&LU;P<*?N2D}H?#MetH!<+G~9uiJ#*&lH{UsP&P?Qa-n4fyz5mnE zVf);Rqs}icpT7QM%Cqf!!}Ff}SUhb!`t8rZr@#K;&Ed@RhSNTtsr#$5p7-6EU;ldZ z{MiM%xOx7oqvD=ICw=tjexiZ7`IebF%NgEm-bictC@eTfB@pwMHxSc8PY~4g+#a z^A2XdMyo~J7lu-8#vI?JXKx@=tK@KO5qmvP2TZzDOePkFDp``iq@S2L z0c;FCi!ip}OIoI-No1}mN))z{s%rZFY#5zrlZlEHW8PzjlW1Ks?BB@-F+ItKPbVAv z`V_`%)80{tZQ3J?&BnNhpx8P+AyP=eH?7YP3&hbkcHaK@1OaT3OMz0}~-l?u61ut{w0knFmQ(IVs85n*v6{KPrz4ojq8 zWH;H4fnbC_K*FY}%VW4|`NMXY&anWw)W*e-u~xb4Q&-8%?NKQ1C9!93{ zQ8l0B5yHUHf={<`BnTq7D#xNjBNj`J#+FJzoqO;-FS9*Xx~9KkB<$lM61{AE#Qof@i#`iW6p+& zZ~2UQEk|C{@Humr3h1+PS4!cE>)46ThC+%~3(k5@(>95Gi SoA$rHY5xL?AoCgc4*&qKyY8m| literal 0 HcmV?d00001 diff --git a/__e2e__/commands/fetchtask.test.js b/__e2e__/commands/fetchtask.test.js new file mode 100644 index 0000000..6485ff1 --- /dev/null +++ b/__e2e__/commands/fetchtask.test.js @@ -0,0 +1,136 @@ +'use strict'; + +const path = require('path'); +const execa = require('execa'); +const test = require('ava'); +const fs = require('fs'); + +const rootCommand = path.join(process.cwd(), 'bin/index.js'); +const configFilePath = path.join(process.cwd(), 'config.json'); + +// learning track python, javascript +const learningTracksInfo = [ + { trackName: 'Python', fileExtension: 'py' }, + { trackName: 'JavaScript', fileExtension: 'js' }, +]; + +const userDefaultConfig = { + learningTrack: '', + userName: 'testConfig', + taskCount: 0, + keys: [], + userSubmittedFiles: [], +}; + +const createUserConfig = ( + trackName, + fileExtension, + keysNumber, + filesNumber, +) => { + var userConfig = userDefaultConfig; + userConfig['learningTrack'] = trackName; + for (let i = 0; i < keysNumber; i++) + userConfig['keys'].push('testKey' + (i + 1)); + for (let i = 0; i < filesNumber; i++) + userConfig['userSubmittedFiles'].push( + 'task' + (i + 1) + '.' + fileExtension, + ); + userConfig['taskCount'] = filesNumber; + + return userConfig; +}; + +test.serial('no config file for fetchtask', async t => { + if (fs.existsSync(configFilePath)) fs.unlinkSync(configFilePath); + const { stdout } = await execa(rootCommand, ['fetchtask'], { + reject: false, + }); + t.snapshot(stdout); +}); + +test.skip('incorrect key for fetchtask', async t => { + let snap = null; + t.assert(learningTracksInfo.length > 0); + for (let index in learningTracksInfo) { + const learningTrack = learningTracksInfo[index]; + const trackName = learningTrack['trackName']; + const fileExtension = learningTrack['fileExtension']; + const userConfig = createUserConfig(trackName, fileExtension, 30, 30); + fs.writeFileSync(configFilePath, JSON.stringify(userConfig)); + const { stdout } = await execa(rootCommand, ['fetchtask', 'testKey0']); + fs.unlinkSync(configFilePath); + if (snap) t.true(snap === stdout); + snap = stdout; + } + t.snapshot(snap); +}); + +test.serial('display completed task with fetchtask key', async t => { + t.assert(learningTracksInfo.length > 0); + for (var index = 0; index < learningTracksInfo; index += 1) { + const learningTrack = learningTracksInfo[index]; + const trackName = learningTrack['trackName']; + const fileExtension = learningTrack['fileExtension']; + let userConfig = createUserConfig(trackName, fileExtension, 6, 5); + fs.writeFileSync(configFilePath, JSON.stringify(userConfig)); + const { stdout } = await execa(rootCommand, ['fetchtask', 'testKey2'], { + reject: false, + }); + t.snapshot(stdout); + fs.unlinkSync(configFilePath); + } +}); + +// giving incorrect snapshot +test.serial('display incomplete task with fetchtask key', async t => { + t.assert(learningTracksInfo.length > 0); + for (let index in learningTracksInfo) { + const learningTrack = learningTracksInfo[index]; + const trackName = learningTrack['trackName']; + const fileExtension = learningTrack['fileExtension']; + let userConfig = createUserConfig(trackName, fileExtension, 6, 5); + fs.writeFileSync(configFilePath, JSON.stringify(userConfig)); + const { stdout } = await execa(rootCommand, ['fetchtask', 'testKey6'], { + reject: false, + }); + t.snapshot(stdout); + fs.unlinkSync(configFilePath); + } +}); + +test.skip('no more tasks available', async t => { + let snap = null; + t.assert(learningTracksInfo.length > 0); + for (let index in learningTracksInfo) { + const learningTrack = learningTracksInfo[index]; + const trackName = learningTrack['trackName']; + const fileExtension = learningTrack['fileExtension']; + const userConfig = createUserConfig(trackName, fileExtension, 30, 30); + fs.writeFileSync(configFilePath, JSON.stringify(userConfig)); + const { stdout } = await execa(rootCommand, ['fetchtask'], { + reject: false, + }); + if (snap) t.assert(snap === stdout); + else snap = stdout; + fs.unlinkSync(configFilePath); + } + t.snapshot(snap); +}); + +// giving incorrect snapshots +test.serial('display next task with fetchtask', async t => { + t.assert(learningTracksInfo.length > 0); + for (let index in learningTracksInfo) { + const learningTrack = learningTracksInfo[index]; + const trackName = learningTrack['trackName']; + const fileExtension = learningTrack['fileExtension']; + const userConfig = createUserConfig(trackName, fileExtension, 6, 5); + fs.writeFileSync(configFilePath, JSON.stringify(userConfig)); + const { stdout } = await execa(rootCommand, ['fetchtask'], { + reject: false, + }); + t.snapshot(stdout); + fs.unlinkSync(configFilePath); + } +}); From 20c0492fbfd2eea6c6ba89874d8e8e9b691628de Mon Sep 17 00:00:00 2001 From: Rishabh Kalakoti Date: Sun, 29 Dec 2019 22:34:39 +0530 Subject: [PATCH 2/9] refactor: replaced var by let --- __e2e__/commands/fetchtask.test.js | 4 ++-- task6.py | 0 2 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 task6.py diff --git a/__e2e__/commands/fetchtask.test.js b/__e2e__/commands/fetchtask.test.js index 6485ff1..7cf62be 100644 --- a/__e2e__/commands/fetchtask.test.js +++ b/__e2e__/commands/fetchtask.test.js @@ -28,7 +28,7 @@ const createUserConfig = ( keysNumber, filesNumber, ) => { - var userConfig = userDefaultConfig; + let userConfig = userDefaultConfig; userConfig['learningTrack'] = trackName; for (let i = 0; i < keysNumber; i++) userConfig['keys'].push('testKey' + (i + 1)); @@ -68,7 +68,7 @@ test.skip('incorrect key for fetchtask', async t => { test.serial('display completed task with fetchtask key', async t => { t.assert(learningTracksInfo.length > 0); - for (var index = 0; index < learningTracksInfo; index += 1) { + for (let index = 0; index < learningTracksInfo; index += 1) { const learningTrack = learningTracksInfo[index]; const trackName = learningTrack['trackName']; const fileExtension = learningTrack['fileExtension']; diff --git a/task6.py b/task6.py new file mode 100644 index 0000000..e69de29 From 288945a9f628351ba4359963c168e9abe68f3d30 Mon Sep 17 00:00:00 2001 From: Rishabh Kalakoti Date: Mon, 30 Dec 2019 20:21:37 +0530 Subject: [PATCH 3/9] test: tests giving incorrect snaps, 'incomplete tasks' and 'next task' --- .../__e2e__/commands/fetchtask.test.js.md | 98 +++++++++++++++++- .../__e2e__/commands/fetchtask.test.js.snap | Bin 944 -> 1467 bytes __e2e__/commands/fetchtask.test.js | 14 ++- src/commands/tasks.js | 49 ++++++--- 4 files changed, 139 insertions(+), 22 deletions(-) diff --git a/__e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.md b/__e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.md index 1246d7c..16e8fe7 100644 --- a/__e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.md +++ b/__e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.md @@ -17,7 +17,10 @@ Generated by [AVA](https://ava.li).  Learn to code effectively Powered by MadHacks␊ ␊ ␊ - User: testConfig Progress: 6/30␊ + This task is already completed!␊ + ␊ + ␊ + User: testConfig Progress: 6/30␊ ␊ ␊ Awesome! Let's move on to Loops. ␊ @@ -32,6 +35,7 @@ Generated by [AVA](https://ava.li). ␊ Task- 6 ␊ Print even numbers from 1 to 10 (including 10) using for loop.␊ + ␊ ` > Snapshot 2 @@ -112,6 +116,23 @@ Generated by [AVA](https://ava.li). ␊ ` +## incorrect key for fetchtask + +> Snapshot 1 + + ` _ _ _ ␊ + | |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊ + | __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊ + | || __/ (_| | (__| | | | (_| (_) | (_| | __/␊ + \\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊ + ␊ +  Learn to code effectively Powered by MadHacks␊ + ␊ + ␊ + Make sure that you've grabbed the key correctly!␊ + ␊ + ` + ## no config file for fetchtask > Snapshot 1 @@ -129,3 +150,78 @@ Generated by [AVA](https://ava.li). cd teachcode-solutions may resolve the issue!␊ ␊ ` + +## no more tasks available + +> Snapshot 1 + + ` _ _ _ ␊ + | |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊ + | __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊ + | || __/ (_| | (__| | | | (_| (_) | (_| | __/␊ + \\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊ + ␊ +  Learn to code effectively Powered by MadHacks␊ + ␊ + ␊ + No more tasks available!␊ + ` + +## display completed task with fetchtask key + +> Snapshot 1 + + ` _ _ _ ␊ + | |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊ + | __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊ + | || __/ (_| | (__| | | | (_| (_) | (_| | __/␊ + \\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊ + ␊ +  Learn to code effectively Powered by MadHacks␊ + ␊ + ␊ + This task is already completed!␊ + ␊ + ␊ + User: testConfig Progress: 6/30␊ + ␊ + ␊ + Now lets focus on variables␊ + Unlike other programming languages, Python has no command for declaring a variable.A variable is created the moment you first assign a value to it.␊ + Also consider these variable naming conventions␊ + ␊ + 1.A variable name must start with a letter or the underscore character␊ + 2.A variable name cannot start with a number␊ + 3.A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )␊ + 3.Variable names are case-sensitive (age, Age and AGE are three different variables)␊ + Task 2:-␊ + Consider these variable names:-␊ + variable␊ + sum@␊ + product_of_12␊ + 12_product␊ + Just print out the correct variable names in order␊ + ␊ + ` + +> Snapshot 2 + + ` _ _ _ ␊ + | |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊ + | __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊ + | || __/ (_| | (__| | | | (_| (_) | (_| | __/␊ + \\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊ + ␊ +  Learn to code effectively Powered by MadHacks␊ + ␊ + ␊ + This task is already completed!␊ + ␊ + ␊ + User: testConfig Progress: 6/30␊ + ␊ + Great! Now's let's move on to variables. Variables are used to store data values ␊ + Task 2:-␊ + Declare a variable to store the value 18 and print the value.␊ + ␊ + ` diff --git a/__e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.snap b/__e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.snap index f54f176f208be9d16fbfa89842e0dab3612060b4..f016b7e3235ba1721b90beb3de4f9512f4203543 100644 GIT binary patch literal 1467 zcmV;s1w{HmRzVe!&Qe8)v&FlVT07T_1}G00000000B+ zSWjqNMHqictfkLVksc}r%9ko8k7k%_@#LXW^dzF91wBcnXTf6+UOan}`upbXX17V|Q9{^-nVtD&=9};D?;GBC zp65O29ZoL2dFS%<{x9!TKlt(5&z}x>{5vq{c`qMKo)|sx%iMeA8#m=g4}Lb_sDBK3 z-qkmn*9NbAeB+;?r(VBxdC&DhN6q#Y?Q7rjetmyb-Mo8y>d0H4{2Bc|_S=A?%Ke`A z;@%Jcx^?~YN9pjn1CQSsx;p5ne?MHb*@K?<(D_5(&&_^y;`t6~j zJ^h&H4S9Q=lmmObM+WZ>3@=vB4lhn0pRNrrmeb+InQ}@L(3ameqz=ueby^Q72rx%; zeZVAMXKK(Mf#$}(`=7$jC3J7o`jlH7#hj)(E3~mhOYVksa!X^5%~-*$7;+nLkBVJB z(NYjBu^i}1t`F9oP;SU=ih7p(ZPfeEAM93PbIqncwJkT3(m5$~MpjX%B1y7Vlc9}Q zWzwR3_|bw|lUhc!+@kX$IwQgr)5FIHaYd5JwItgRmRc$&fyr8I8!^~6K$jwHF!Kqc zlHA5BGZe)d*C^c@@%?>awC$c$v`9PN#4iUxmcG>pP~buE^c zaf-dTB3t0C+5Jgtvp3%z>U(nsd6OtL`xB|_tIt}t&HG3|B{iqiu5&h zUS+ko&U_cNsv~htm5xo#Of#RkHRN$BM<9?LMP@4mg>r(OQ>tku;Q}7GTQZ8%rqWhq zmW&lvrV^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Dp``iq@S2L z0c;FCi!ip}OIoI-No1}mN))z{s%rZFY#5zrlZlEHW8PzjlW1Ks?BB@-F+ItKPbVAv z`V_`%)80{tZQ3J?&BnNhpx8P+AyP=eH?7YP3&hbkcHaK@1OaT3OMz0}~-l?u61ut{w0knFmQ(IVs85n*v6{KPrz4ojq8 zWH;H4fnbC_K*FY}%VW4|`NMXY&anWw)W*e-u~xb4Q&-8%?NKQ1C9!93{ zQ8l0B5yHUHf={<`BnTq7D#xNjBNj`J#+FJzoqO;-FS9*Xx~9KkB<$lM61{AE#Qof@i#`iW6p+& zZ~2UQEk|C{@Humr3h1+PS4!cE>)46ThC+%~3(k5@(>95Gi SoA$rHY5xL?AoCgc4*&qKyY8m| diff --git a/__e2e__/commands/fetchtask.test.js b/__e2e__/commands/fetchtask.test.js index 7cf62be..c1cca1d 100644 --- a/__e2e__/commands/fetchtask.test.js +++ b/__e2e__/commands/fetchtask.test.js @@ -49,7 +49,7 @@ test.serial('no config file for fetchtask', async t => { t.snapshot(stdout); }); -test.skip('incorrect key for fetchtask', async t => { +test.serial('incorrect key for fetchtask', async t => { let snap = null; t.assert(learningTracksInfo.length > 0); for (let index in learningTracksInfo) { @@ -58,7 +58,11 @@ test.skip('incorrect key for fetchtask', async t => { const fileExtension = learningTrack['fileExtension']; const userConfig = createUserConfig(trackName, fileExtension, 30, 30); fs.writeFileSync(configFilePath, JSON.stringify(userConfig)); - const { stdout } = await execa(rootCommand, ['fetchtask', 'testKey0']); + const { stdout } = await execa( + rootCommand, + ['fetchtask', 'incorrectTestKey'], + { reject: false }, + ); fs.unlinkSync(configFilePath); if (snap) t.true(snap === stdout); snap = stdout; @@ -68,7 +72,7 @@ test.skip('incorrect key for fetchtask', async t => { test.serial('display completed task with fetchtask key', async t => { t.assert(learningTracksInfo.length > 0); - for (let index = 0; index < learningTracksInfo; index += 1) { + for (let index = 0; index < learningTracksInfo.length; index++) { const learningTrack = learningTracksInfo[index]; const trackName = learningTrack['trackName']; const fileExtension = learningTrack['fileExtension']; @@ -83,6 +87,7 @@ test.serial('display completed task with fetchtask key', async t => { }); // giving incorrect snapshot +// ****************************** test.serial('display incomplete task with fetchtask key', async t => { t.assert(learningTracksInfo.length > 0); for (let index in learningTracksInfo) { @@ -99,7 +104,7 @@ test.serial('display incomplete task with fetchtask key', async t => { } }); -test.skip('no more tasks available', async t => { +test.serial('no more tasks available', async t => { let snap = null; t.assert(learningTracksInfo.length > 0); for (let index in learningTracksInfo) { @@ -119,6 +124,7 @@ test.skip('no more tasks available', async t => { }); // giving incorrect snapshots +// ***************************** test.serial('display next task with fetchtask', async t => { t.assert(learningTracksInfo.length > 0); for (let index in learningTracksInfo) { diff --git a/src/commands/tasks.js b/src/commands/tasks.js index 477df09..5b7f449 100644 --- a/src/commands/tasks.js +++ b/src/commands/tasks.js @@ -47,10 +47,6 @@ const fetchTask = async key => { keys, } = userConfig; - if (!key) { - key = keys.slice(-1).pop(); - } - if (learningTrack === 'Python') { fileName = `task${taskCount + 1}.py`; exercises = require('../workspace/python/tasks'); @@ -60,7 +56,38 @@ const fetchTask = async key => { } // Holding reference to keys of all the completed tasks - let previousKeys = keys.slice(0, keys.length - 1); + let previousKeys = keys.slice( + 0, + // when all tasks have been completed, taskCount === keys.length + keys.length - (taskCount !== keys.length ? 1 : 0), + ); + + // check for incorrect key + let incorrectKey = true; + keys.some(item => { + if (item === key) { + incorrectKey = false; + } + }); + + if (key && incorrectKey) { + console.log(); + console.log( + chalk.red.bold("Make sure that you've grabbed the key correctly!"), + ); + console.log(); + process.exit(1); + } + + if (!key && taskCount === exercises.length) { + console.log(); + console.log(chalk.red.bold('No more tasks available!')); + process.exit(1); + } + + if (!key && taskCount < exercises.length) { + key = keys.slice(-1).pop(); + } let taskAlreadyCompleted = []; @@ -89,12 +116,6 @@ const fetchTask = async key => { process.exit(1); } - if (taskCount === exercises.length) { - console.log(); - console.log(chalk.red.bold('No more tasks available!')); - process.exit(1); - } - if (keys.slice(-1).pop() === key) { if (userSubmittedFiles.indexOf(fileName) === -1) { userSubmittedFiles.push(fileName); @@ -117,12 +138,6 @@ const fetchTask = async key => { let createCmd = process.platform !== 'win32' ? 'touch' : 'notepad'; execSync(`${createCmd} ${fileName}`); - } else { - console.log(); - console.log( - chalk.red.bold("Make sure that you've grabbed the key correctly!"), - ); - console.log(); } }; From 7813646132555004e85bb4fe6cf144d72487f702 Mon Sep 17 00:00:00 2001 From: Rishabh Kalakoti Date: Mon, 30 Dec 2019 20:31:15 +0530 Subject: [PATCH 4/9] refactor: updated code to not reject promises when task is printed --- .../__e2e__/commands/fetchtask.test.js.md | 116 +++++++++--------- .../__e2e__/commands/fetchtask.test.js.snap | Bin 1467 -> 1466 bytes __e2e__/commands/fetchtask.test.js | 8 +- src/commands/tasks.js | 2 +- 4 files changed, 58 insertions(+), 68 deletions(-) diff --git a/__e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.md b/__e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.md index 16e8fe7..f994c1b 100644 --- a/__e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.md +++ b/__e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.md @@ -4,7 +4,7 @@ The actual snapshot is saved in `fetchtask.test.js.snap`. Generated by [AVA](https://ava.li). -## display incomplete task with fetchtask key +## display completed task with fetchtask key > Snapshot 1 @@ -23,19 +23,21 @@ Generated by [AVA](https://ava.li). User: testConfig Progress: 6/30␊ ␊ ␊ - Awesome! Let's move on to Loops. ␊ - Loop is an important statement which is used for repetition of the same code as and when required. ␊ - This task will surely test what you have learnt till now from the previous tasks! ␊ - ␊ - Task 6 ␊ - Syntax of for loop: ␊ - for loop_control_variable in range(start, stop, step): ␊ - Loop Body(indented)␊ - Here's your task: ␊ - ␊ - Task- 6 ␊ - Print even numbers from 1 to 10 (including 10) using for loop.␊ + Now lets focus on variables␊ + Unlike other programming languages, Python has no command for declaring a variable.A variable is created the moment you first assign a value to it.␊ + Also consider these variable naming conventions␊ ␊ + 1.A variable name must start with a letter or the underscore character␊ + 2.A variable name cannot start with a number␊ + 3.A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )␊ + 3.Variable names are case-sensitive (age, Age and AGE are three different variables)␊ + Task 2:-␊ + Consider these variable names:-␊ + variable␊ + sum@␊ + product_of_12␊ + 12_product␊ + Just print out the correct variable names in order␊ ` > Snapshot 2 @@ -54,13 +56,12 @@ Generated by [AVA](https://ava.li). ␊ User: testConfig Progress: 6/30␊ ␊ - Awesome! Let's move on to Comparison Operators. They are used to compare two values. They return true or false according to the value of their operands. They are: ==, ===, !=, >, <, >=, <=. Here's your task:␊ - Task 6:-␊ - Use 44 & 29 as your operands. Compare them using the Comparison operators in the same order and print the value which they return.␊ - ␊ + Great! Now's let's move on to variables. Variables are used to store data values ␊ + Task 2:-␊ + Declare a variable to store the value 18 and print the value.␊ ` -## display next task with fetchtask +## display incomplete task with fetchtask key > Snapshot 1 @@ -91,7 +92,6 @@ Generated by [AVA](https://ava.li). ␊ Task- 6 ␊ Print even numbers from 1 to 10 (including 10) using for loop.␊ - ␊ ` > Snapshot 2 @@ -113,10 +113,9 @@ Generated by [AVA](https://ava.li). Awesome! Let's move on to Comparison Operators. They are used to compare two values. They return true or false according to the value of their operands. They are: ==, ===, !=, >, <, >=, <=. Here's your task:␊ Task 6:-␊ Use 44 & 29 as your operands. Compare them using the Comparison operators in the same order and print the value which they return.␊ - ␊ ` -## incorrect key for fetchtask +## display next task with fetchtask > Snapshot 1 @@ -129,13 +128,27 @@ Generated by [AVA](https://ava.li).  Learn to code effectively Powered by MadHacks␊ ␊ ␊ - Make sure that you've grabbed the key correctly!␊ + This task is already completed!␊ + ␊ ␊ + User: testConfig Progress: 6/30␊ + ␊ + ␊ + Awesome! Let's move on to Loops. ␊ + Loop is an important statement which is used for repetition of the same code as and when required. ␊ + This task will surely test what you have learnt till now from the previous tasks! ␊ + ␊ + Task 6 ␊ + Syntax of for loop: ␊ + for loop_control_variable in range(start, stop, step): ␊ + Loop Body(indented)␊ + Here's your task: ␊ + ␊ + Task- 6 ␊ + Print even numbers from 1 to 10 (including 10) using for loop.␊ ` -## no config file for fetchtask - -> Snapshot 1 +> Snapshot 2 ` _ _ _ ␊ | |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊ @@ -145,13 +158,18 @@ Generated by [AVA](https://ava.li). ␊  Learn to code effectively Powered by MadHacks␊ ␊ - Make sure that you are within the teachcode-solutions directory!␊ ␊ - cd teachcode-solutions may resolve the issue!␊ + This task is already completed!␊ ␊ + ␊ + User: testConfig Progress: 6/30␊ + ␊ + Awesome! Let's move on to Comparison Operators. They are used to compare two values. They return true or false according to the value of their operands. They are: ==, ===, !=, >, <, >=, <=. Here's your task:␊ + Task 6:-␊ + Use 44 & 29 as your operands. Compare them using the Comparison operators in the same order and print the value which they return.␊ ` -## no more tasks available +## incorrect key for fetchtask > Snapshot 1 @@ -164,10 +182,11 @@ Generated by [AVA](https://ava.li).  Learn to code effectively Powered by MadHacks␊ ␊ ␊ - No more tasks available!␊ + Make sure that you've grabbed the key correctly!␊ + ␊ ` -## display completed task with fetchtask key +## no config file for fetchtask > Snapshot 1 @@ -179,32 +198,15 @@ Generated by [AVA](https://ava.li). ␊  Learn to code effectively Powered by MadHacks␊ ␊ + Make sure that you are within the teachcode-solutions directory!␊ ␊ - This task is already completed!␊ - ␊ - ␊ - User: testConfig Progress: 6/30␊ - ␊ - ␊ - Now lets focus on variables␊ - Unlike other programming languages, Python has no command for declaring a variable.A variable is created the moment you first assign a value to it.␊ - Also consider these variable naming conventions␊ - ␊ - 1.A variable name must start with a letter or the underscore character␊ - 2.A variable name cannot start with a number␊ - 3.A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )␊ - 3.Variable names are case-sensitive (age, Age and AGE are three different variables)␊ - Task 2:-␊ - Consider these variable names:-␊ - variable␊ - sum@␊ - product_of_12␊ - 12_product␊ - Just print out the correct variable names in order␊ + cd teachcode-solutions may resolve the issue!␊ ␊ ` -> Snapshot 2 +## no more tasks available + +> Snapshot 1 ` _ _ _ ␊ | |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊ @@ -215,13 +217,5 @@ Generated by [AVA](https://ava.li).  Learn to code effectively Powered by MadHacks␊ ␊ ␊ - This task is already completed!␊ - ␊ - ␊ - User: testConfig Progress: 6/30␊ - ␊ - Great! Now's let's move on to variables. Variables are used to store data values ␊ - Task 2:-␊ - Declare a variable to store the value 18 and print the value.␊ - ␊ + No more tasks available!␊ ` diff --git a/__e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.snap b/__e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.snap index f016b7e3235ba1721b90beb3de4f9512f4203543..6857da0a58bd8900078c3ec1acedc2fa702a37ef 100644 GIT binary patch literal 1466 zcmV;r1x5NnRzVQ|n1dI=e?a2zRrl;nb~oOHWtoQRsebk9)vH&( z_j@(pI*zl~IUHZQeD})qqhH;f`|yYBKYcdf@N;0$ab7(XKRtTl=lS=mH*d+0_kKQL zrGE@L&Lig^|89Qv>zm)7I`Yk(<8NFYw9?BD7wtFKajw19ygqpKlbinxJ^SYED|>DX zT4{8kXg3Zz&MzN~s$2K&OdWaq(?5gX$9^5KQty!Cyu9zDzi!|7;t4u@?!Z%bhpr7; z>EDkPt@@t*hnJ?0PuGW+s>$%uOf@0$Xv?#Ws3UV}oz^|_ zJba_sx5pwLXQ@~AAhUhf{!T%28LxL}eaa4w;+v*ABeXF@%XWozvO{Cm%vfQq=yDq` zdxe%uwCs7y><3;I`}WqYQ?|=(ih73JZMOHH58_tiaLpzzm64lC=$sTfrA(2p0!gx7 zmwpzl$+%7X@zA1bNi73fY14TToDu%2>9ONNxGKryT2dB@jM^$Efsa;{g%Qk#kW1l* zY<$9~IL{)L8VVwfWt47@xbA*G*j6VIZPF6oYtq_@jL9YR??c0neKhPKG`L&QFpAS_ zXtA<_S$vACvJKmsk3Vj2K27yd|1@{dY0||oGL#9kisT~^YbgRgy`&k-Oa?eT_mYu% z4(V&M1(nvL2HRcKs)58c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Rb3WiT{0H*uvz z(-X5Lw-nGg^MAFMyK%@C3L__sgmE~UXbe6o(Og}+V{@lppaM3uloZ7XI?X2E@c4Ke zf+`F_^Y=HgG`yih@$mvlpYu6DqCB*Lss-f=tX>J)6rawry$j4yd4W6a&v={oGF&;7 z+6+H~efZgZ@N=5ee}pjzg)rG%#5clnk~)!Y?kV4RXkr!#+lB~3z480JgCE%gKHW3j V!dHG~yLyP~_b+Ir?z! { const fileExtension = learningTrack['fileExtension']; let userConfig = createUserConfig(trackName, fileExtension, 6, 5); fs.writeFileSync(configFilePath, JSON.stringify(userConfig)); - const { stdout } = await execa(rootCommand, ['fetchtask', 'testKey2'], { - reject: false, - }); + const { stdout } = await execa(rootCommand, ['fetchtask', 'testKey2']); t.snapshot(stdout); fs.unlinkSync(configFilePath); } @@ -96,9 +94,7 @@ test.serial('display incomplete task with fetchtask key', async t => { const fileExtension = learningTrack['fileExtension']; let userConfig = createUserConfig(trackName, fileExtension, 6, 5); fs.writeFileSync(configFilePath, JSON.stringify(userConfig)); - const { stdout } = await execa(rootCommand, ['fetchtask', 'testKey6'], { - reject: false, - }); + const { stdout } = await execa(rootCommand, ['fetchtask', 'testKey6']); t.snapshot(stdout); fs.unlinkSync(configFilePath); } diff --git a/src/commands/tasks.js b/src/commands/tasks.js index 5b7f449..d49706d 100644 --- a/src/commands/tasks.js +++ b/src/commands/tasks.js @@ -113,7 +113,7 @@ const fetchTask = async key => { console.log(); console.log(chalk.green(`${exercises[taskAlreadyCompleted[1]].task}`)); console.log(); - process.exit(1); + return; } if (keys.slice(-1).pop() === key) { From d6c2ebaf1319bcb351fa81c2a119936b37fda19c Mon Sep 17 00:00:00 2001 From: Rishabh Kalakoti Date: Mon, 30 Dec 2019 21:05:47 +0530 Subject: [PATCH 5/9] refactor: tasks.js updated --- .../__e2e__/commands/fetchtask.test.js.md | 20 +++-------- .../__e2e__/commands/fetchtask.test.js.snap | Bin 1466 -> 1470 bytes __e2e__/commands/fetchtask.test.js | 4 +-- src/commands/tasks.js | 32 +++++++++--------- task6.js | 0 5 files changed, 21 insertions(+), 35 deletions(-) create mode 100644 task6.js diff --git a/__e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.md b/__e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.md index f994c1b..82b8fff 100644 --- a/__e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.md +++ b/__e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.md @@ -74,10 +74,7 @@ Generated by [AVA](https://ava.li).  Learn to code effectively Powered by MadHacks␊ ␊ ␊ - This task is already completed!␊ - ␊ - ␊ - User: testConfig Progress: 6/30␊ + User: testConfig Progress: 6/30␊ ␊ ␊ Awesome! Let's move on to Loops. ␊ @@ -105,10 +102,7 @@ Generated by [AVA](https://ava.li).  Learn to code effectively Powered by MadHacks␊ ␊ ␊ - This task is already completed!␊ - ␊ - ␊ - User: testConfig Progress: 6/30␊ + User: testConfig Progress: 6/30␊ ␊ Awesome! Let's move on to Comparison Operators. They are used to compare two values. They return true or false according to the value of their operands. They are: ==, ===, !=, >, <, >=, <=. Here's your task:␊ Task 6:-␊ @@ -128,10 +122,7 @@ Generated by [AVA](https://ava.li).  Learn to code effectively Powered by MadHacks␊ ␊ ␊ - This task is already completed!␊ - ␊ - ␊ - User: testConfig Progress: 6/30␊ + User: testConfig Progress: 6/30␊ ␊ ␊ Awesome! Let's move on to Loops. ␊ @@ -159,10 +150,7 @@ Generated by [AVA](https://ava.li).  Learn to code effectively Powered by MadHacks␊ ␊ ␊ - This task is already completed!␊ - ␊ - ␊ - User: testConfig Progress: 6/30␊ + User: testConfig Progress: 6/30␊ ␊ Awesome! Let's move on to Comparison Operators. They are used to compare two values. They return true or false according to the value of their operands. They are: ==, ===, !=, >, <, >=, <=. Here's your task:␊ Task 6:-␊ diff --git a/__e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.snap b/__e2e__/__snapshots__/__e2e__/commands/fetchtask.test.js.snap index 6857da0a58bd8900078c3ec1acedc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T!W2Vw<>!V}N^3$#VkMTw zrAuiX0W}Kf(A4C)B1xjOL9s|1xoAjJp~ZF&rM#OY5orKxngZ#^umyFoVRUkS zqsxx_@H;Evm#9Rh1x?i>Z88$ZM2*x=j&sSein2+U=3~R_q$UdB6=oXQwV4X*ABNYH z`2s0_YFq61B2CpMOKG00u=dP$+6ZvW=agmw94z8yC?+sL>d5b|gabtgyFM5io1eH^ zq3Ma)iXHN3obA8fYu#9K_k{sbO9Y3}L}NIk3e7j9oi=~^C99N$T1pT-K&Lt68z&B{ z7a3Buxe1pR9vot6SfL|vK`Y4%E(0XU{mfH;b+1}O)N5WTap^3_y9q30r1H#$xMZ45 zb_r2Y8mn$%pTR!+>^}B6&DlS~6f|l$0r5^0P^+wK8>pP54$upX=Y|1is!}u#mrTU!Bi~^b);>r8b_ufz+eY+2Rs3a}iVG}t5hc;pFoKj7H z;Lf!jyGlw?(o{MVsipf&+G5oTBR}MEi%BkeS~g`CapfUZw}>*9`gy0KAof-$Q|MjE zanlZXk?ww4Q5@S#8e+lTL$|!ShXT&U95~>VwNe!Bx>ku@qp9Uur1HXw86mgKgk!M& zS{udYUG|3ki?N|ONH;z_E=F3#UbilP!#mV>IcCdRg>$CKZ`mB@nfr^NoKiu1EJBS+ z5pxudGdME@5x#2c#T<3Kn6Pdv+7y#0%VmW$h5J>GcXgUz%a8Mbt9NyJ90BEC$H`3z zS?ed{E={c%ygX_Uy0A_CzYa)u7iAVa^kR5y+X#HzQ{~FRy$laHa{cFhoc@6m&nR3HY>ly$6K8eOo diff --git a/__e2e__/commands/fetchtask.test.js b/__e2e__/commands/fetchtask.test.js index 5c659c3..190036a 100644 --- a/__e2e__/commands/fetchtask.test.js +++ b/__e2e__/commands/fetchtask.test.js @@ -129,9 +129,7 @@ test.serial('display next task with fetchtask', async t => { const fileExtension = learningTrack['fileExtension']; const userConfig = createUserConfig(trackName, fileExtension, 6, 5); fs.writeFileSync(configFilePath, JSON.stringify(userConfig)); - const { stdout } = await execa(rootCommand, ['fetchtask'], { - reject: false, - }); + const { stdout } = await execa(rootCommand, ['fetchtask']); t.snapshot(stdout); fs.unlinkSync(configFilePath); } diff --git a/src/commands/tasks.js b/src/commands/tasks.js index d49706d..9fe6a62 100644 --- a/src/commands/tasks.js +++ b/src/commands/tasks.js @@ -42,9 +42,9 @@ const fetchTask = async key => { const { learningTrack, userName, - userSubmittedFiles, taskCount, keys, + userSubmittedFiles, } = userConfig; if (learningTrack === 'Python') { @@ -55,14 +55,7 @@ const fetchTask = async key => { exercises = require('../workspace/js/tasks'); } - // Holding reference to keys of all the completed tasks - let previousKeys = keys.slice( - 0, - // when all tasks have been completed, taskCount === keys.length - keys.length - (taskCount !== keys.length ? 1 : 0), - ); - - // check for incorrect key + // check for incorrect key if key is provided let incorrectKey = true; keys.some(item => { if (item === key) { @@ -79,18 +72,23 @@ const fetchTask = async key => { process.exit(1); } + // check if no more tasks are available (no key provided) if (!key && taskCount === exercises.length) { console.log(); console.log(chalk.red.bold('No more tasks available!')); process.exit(1); } - if (!key && taskCount < exercises.length) { + // in case no key is provided, make the last key as the key + if (!key) { key = keys.slice(-1).pop(); } let taskAlreadyCompleted = []; + // Holding reference to keys of all the completed tasks + let previousKeys = keys.slice(0, taskCount); + previousKeys.some((item, index) => { if (item === key) { taskAlreadyCompleted = [true, index]; @@ -105,9 +103,10 @@ const fetchTask = async key => { console.log(); console.log( chalk.green.bold( - `User: ${userName}${`\t`.repeat(4)}Progress: ${taskCount + 1}/${ - exercises.length - }`, + `User: ${userName}${`\t`.repeat(4)}Progress: ${Math.min( + taskCount + 1, + 30, + )}/${exercises.length}`, ), ); console.log(); @@ -126,9 +125,10 @@ const fetchTask = async key => { console.log(); console.log( chalk.cyan.bold( - `User: ${userName}${`\t`.repeat(6)}Progress: ${taskCount + 1}/${ - exercises.length - }`, + `User: ${userName}${`\t`.repeat(6)}Progress: ${Math.min( + taskCount + 1, + 30, + )}/${exercises.length}`, ), ); // Displaying respective task within the the console screen. diff --git a/task6.js b/task6.js new file mode 100644 index 0000000..e69de29 From afb73f458cadef9290a24fb83a82b2690c4f477a Mon Sep 17 00:00:00 2001 From: Rishabh Kalakoti Date: Mon, 30 Dec 2019 21:09:00 +0530 Subject: [PATCH 6/9] fix: deleted extra files created --- __e2e__/commands/fetchtask.test.js | 7 ++----- task6.js | 0 task6.py | 0 3 files changed, 2 insertions(+), 5 deletions(-) delete mode 100644 task6.js delete mode 100644 task6.py diff --git a/__e2e__/commands/fetchtask.test.js b/__e2e__/commands/fetchtask.test.js index 190036a..432164a 100644 --- a/__e2e__/commands/fetchtask.test.js +++ b/__e2e__/commands/fetchtask.test.js @@ -8,7 +8,6 @@ const fs = require('fs'); const rootCommand = path.join(process.cwd(), 'bin/index.js'); const configFilePath = path.join(process.cwd(), 'config.json'); -// learning track python, javascript const learningTracksInfo = [ { trackName: 'Python', fileExtension: 'py' }, { trackName: 'JavaScript', fileExtension: 'js' }, @@ -84,8 +83,6 @@ test.serial('display completed task with fetchtask key', async t => { } }); -// giving incorrect snapshot -// ****************************** test.serial('display incomplete task with fetchtask key', async t => { t.assert(learningTracksInfo.length > 0); for (let index in learningTracksInfo) { @@ -97,6 +94,7 @@ test.serial('display incomplete task with fetchtask key', async t => { const { stdout } = await execa(rootCommand, ['fetchtask', 'testKey6']); t.snapshot(stdout); fs.unlinkSync(configFilePath); + fs.unlinkSync(path.join(process.cwd(), 'task6.' + fileExtension)); } }); @@ -119,8 +117,6 @@ test.serial('no more tasks available', async t => { t.snapshot(snap); }); -// giving incorrect snapshots -// ***************************** test.serial('display next task with fetchtask', async t => { t.assert(learningTracksInfo.length > 0); for (let index in learningTracksInfo) { @@ -132,5 +128,6 @@ test.serial('display next task with fetchtask', async t => { const { stdout } = await execa(rootCommand, ['fetchtask']); t.snapshot(stdout); fs.unlinkSync(configFilePath); + fs.unlinkSync(path.join(process.cwd(), 'task6.' + fileExtension)); } }); diff --git a/task6.js b/task6.js deleted file mode 100644 index e69de29..0000000 diff --git a/task6.py b/task6.py deleted file mode 100644 index e69de29..0000000 From 85e215f3eb7330a8dd3a01338323c342015511dd Mon Sep 17 00:00:00 2001 From: Rishabh Kalakoti Date: Tue, 31 Dec 2019 00:07:00 +0530 Subject: [PATCH 7/9] refactor: style update --- __e2e__/commands/fetchtask.test.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/__e2e__/commands/fetchtask.test.js b/__e2e__/commands/fetchtask.test.js index 432164a..99e9a33 100644 --- a/__e2e__/commands/fetchtask.test.js +++ b/__e2e__/commands/fetchtask.test.js @@ -63,8 +63,11 @@ test.serial('incorrect key for fetchtask', async t => { { reject: false }, ); fs.unlinkSync(configFilePath); - if (snap) t.true(snap === stdout); - snap = stdout; + if (snap) { + t.true(snap === stdout); + } else { + snap = stdout; + } } t.snapshot(snap); }); @@ -110,8 +113,11 @@ test.serial('no more tasks available', async t => { const { stdout } = await execa(rootCommand, ['fetchtask'], { reject: false, }); - if (snap) t.assert(snap === stdout); - else snap = stdout; + if (snap) { + t.assert(snap === stdout); + } else { + snap = stdout; + } fs.unlinkSync(configFilePath); } t.snapshot(snap); From 10d8e0c1cba6e9d23ccaa6a608cef871550f4b3e Mon Sep 17 00:00:00 2001 From: Rishabh Kalakoti Date: Tue, 31 Dec 2019 10:48:27 +0530 Subject: [PATCH 8/9] refactor: style changes --- __e2e__/commands/fetchtask.test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/__e2e__/commands/fetchtask.test.js b/__e2e__/commands/fetchtask.test.js index 99e9a33..bdbf875 100644 --- a/__e2e__/commands/fetchtask.test.js +++ b/__e2e__/commands/fetchtask.test.js @@ -29,12 +29,14 @@ const createUserConfig = ( ) => { let userConfig = userDefaultConfig; userConfig['learningTrack'] = trackName; - for (let i = 0; i < keysNumber; i++) + for (let i = 0; i < keysNumber; i++) { userConfig['keys'].push('testKey' + (i + 1)); - for (let i = 0; i < filesNumber; i++) + } + for (let i = 0; i < filesNumber; i++) { userConfig['userSubmittedFiles'].push( 'task' + (i + 1) + '.' + fileExtension, ); + } userConfig['taskCount'] = filesNumber; return userConfig; From 72368d6f72c2288cea23aa1fa47710a01e7f1f00 Mon Sep 17 00:00:00 2001 From: Rishabh Kalakoti Date: Thu, 9 Jan 2020 16:15:37 +0530 Subject: [PATCH 9/9] refactor: destructuring --- __e2e__/commands/fetchtask.test.js | 32 ++++++++++-------------------- src/commands/tasks.js | 10 +--------- 2 files changed, 11 insertions(+), 31 deletions(-) diff --git a/__e2e__/commands/fetchtask.test.js b/__e2e__/commands/fetchtask.test.js index bdbf875..940f150 100644 --- a/__e2e__/commands/fetchtask.test.js +++ b/__e2e__/commands/fetchtask.test.js @@ -30,12 +30,10 @@ const createUserConfig = ( let userConfig = userDefaultConfig; userConfig['learningTrack'] = trackName; for (let i = 0; i < keysNumber; i++) { - userConfig['keys'].push('testKey' + (i + 1)); + userConfig['keys'].push(`testKey${i + 1}`); } for (let i = 0; i < filesNumber; i++) { - userConfig['userSubmittedFiles'].push( - 'task' + (i + 1) + '.' + fileExtension, - ); + userConfig['userSubmittedFiles'].push(`task${i + 1}.${fileExtension}`); } userConfig['taskCount'] = filesNumber; @@ -54,9 +52,7 @@ test.serial('incorrect key for fetchtask', async t => { let snap = null; t.assert(learningTracksInfo.length > 0); for (let index in learningTracksInfo) { - const learningTrack = learningTracksInfo[index]; - const trackName = learningTrack['trackName']; - const fileExtension = learningTrack['fileExtension']; + let { trackName, fileExtension } = learningTracksInfo[index]; const userConfig = createUserConfig(trackName, fileExtension, 30, 30); fs.writeFileSync(configFilePath, JSON.stringify(userConfig)); const { stdout } = await execa( @@ -76,10 +72,8 @@ test.serial('incorrect key for fetchtask', async t => { test.serial('display completed task with fetchtask key', async t => { t.assert(learningTracksInfo.length > 0); - for (let index = 0; index < learningTracksInfo.length; index++) { - const learningTrack = learningTracksInfo[index]; - const trackName = learningTrack['trackName']; - const fileExtension = learningTrack['fileExtension']; + for (let index in learningTracksInfo) { + let { trackName, fileExtension } = learningTracksInfo[index]; let userConfig = createUserConfig(trackName, fileExtension, 6, 5); fs.writeFileSync(configFilePath, JSON.stringify(userConfig)); const { stdout } = await execa(rootCommand, ['fetchtask', 'testKey2']); @@ -91,15 +85,13 @@ test.serial('display completed task with fetchtask key', async t => { test.serial('display incomplete task with fetchtask key', async t => { t.assert(learningTracksInfo.length > 0); for (let index in learningTracksInfo) { - const learningTrack = learningTracksInfo[index]; - const trackName = learningTrack['trackName']; - const fileExtension = learningTrack['fileExtension']; + let { trackName, fileExtension } = learningTracksInfo[index]; let userConfig = createUserConfig(trackName, fileExtension, 6, 5); fs.writeFileSync(configFilePath, JSON.stringify(userConfig)); const { stdout } = await execa(rootCommand, ['fetchtask', 'testKey6']); t.snapshot(stdout); fs.unlinkSync(configFilePath); - fs.unlinkSync(path.join(process.cwd(), 'task6.' + fileExtension)); + fs.unlinkSync(path.join(process.cwd(), `task6.${fileExtension}`)); } }); @@ -107,9 +99,7 @@ test.serial('no more tasks available', async t => { let snap = null; t.assert(learningTracksInfo.length > 0); for (let index in learningTracksInfo) { - const learningTrack = learningTracksInfo[index]; - const trackName = learningTrack['trackName']; - const fileExtension = learningTrack['fileExtension']; + let { trackName, fileExtension } = learningTracksInfo[index]; const userConfig = createUserConfig(trackName, fileExtension, 30, 30); fs.writeFileSync(configFilePath, JSON.stringify(userConfig)); const { stdout } = await execa(rootCommand, ['fetchtask'], { @@ -128,14 +118,12 @@ test.serial('no more tasks available', async t => { test.serial('display next task with fetchtask', async t => { t.assert(learningTracksInfo.length > 0); for (let index in learningTracksInfo) { - const learningTrack = learningTracksInfo[index]; - const trackName = learningTrack['trackName']; - const fileExtension = learningTrack['fileExtension']; + let { trackName, fileExtension } = learningTracksInfo[index]; const userConfig = createUserConfig(trackName, fileExtension, 6, 5); fs.writeFileSync(configFilePath, JSON.stringify(userConfig)); const { stdout } = await execa(rootCommand, ['fetchtask']); t.snapshot(stdout); fs.unlinkSync(configFilePath); - fs.unlinkSync(path.join(process.cwd(), 'task6.' + fileExtension)); + fs.unlinkSync(path.join(process.cwd(), `task6.${fileExtension}`)); } }); diff --git a/src/commands/tasks.js b/src/commands/tasks.js index 9fe6a62..2ac72f4 100644 --- a/src/commands/tasks.js +++ b/src/commands/tasks.js @@ -55,15 +55,7 @@ const fetchTask = async key => { exercises = require('../workspace/js/tasks'); } - // check for incorrect key if key is provided - let incorrectKey = true; - keys.some(item => { - if (item === key) { - incorrectKey = false; - } - }); - - if (key && incorrectKey) { + if (key && !keys.includes(key)) { console.log(); console.log( chalk.red.bold("Make sure that you've grabbed the key correctly!"),