Skip to content

Commit 144ecc2

Browse files
rishabhKalakotijamesgeorge007
authored andcommitted
chore: e2e test case for fetchtask (#64)
* test: e2e test for fetchtask (incorrect tests/ code) * refactor: replaced var by let * test: tests giving incorrect snaps, 'incomplete tasks' and 'next task' * refactor: updated code to not reject promises when task is printed * refactor: tasks.js updated * fix: deleted extra files created * refactor: style update * refactor: style changes * refactor: destructuring
1 parent ed3ad48 commit 144ecc2

File tree

4 files changed

+371
-26
lines changed

4 files changed

+371
-26
lines changed
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
# Snapshot report for `__e2e__/commands/fetchtask.test.js`
2+
3+
The actual snapshot is saved in `fetchtask.test.js.snap`.
4+
5+
Generated by [AVA](https://ava.li).
6+
7+
## display completed task with fetchtask key
8+
9+
> Snapshot 1
10+
11+
` _ _ _ ␊
12+
| |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊
13+
| __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊
14+
| || __/ (_| | (__| | | | (_| (_) | (_| | __/␊
15+
\\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊
16+
␊
17+
 Learn to code effectively Powered by MadHacks␊
18+
19+
20+
This task is already completed!␊
21+
22+
23+
User: testConfig Progress: 6/30␊
24+
25+
26+
Now lets focus on variables␊
27+
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.␊
28+
Also consider these variable naming conventions␊
29+
30+
1.A variable name must start with a letter or the underscore character␊
31+
2.A variable name cannot start with a number␊
32+
3.A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )␊
33+
3.Variable names are case-sensitive (age, Age and AGE are three different variables)␊
34+
Task 2:-␊
35+
Consider these variable names:-␊
36+
variable␊
37+
sum@␊
38+
product_of_12␊
39+
12_product␊
40+
Just print out the correct variable names in order␊
41+
`
42+
43+
> Snapshot 2
44+
45+
` _ _ _ ␊
46+
| |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊
47+
| __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊
48+
| || __/ (_| | (__| | | | (_| (_) | (_| | __/␊
49+
\\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊
50+
␊
51+
 Learn to code effectively Powered by MadHacks␊
52+
53+
54+
This task is already completed!␊
55+
56+
57+
User: testConfig Progress: 6/30␊
58+
59+
Great! Now's let's move on to variables. Variables are used to store data values ␊
60+
Task 2:-␊
61+
Declare a variable to store the value 18 and print the value.␊
62+
`
63+
64+
## display incomplete task with fetchtask key
65+
66+
> Snapshot 1
67+
68+
` _ _ _ ␊
69+
| |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊
70+
| __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊
71+
| || __/ (_| | (__| | | | (_| (_) | (_| | __/␊
72+
\\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊
73+
␊
74+
 Learn to code effectively Powered by MadHacks␊
75+
76+
77+
User: testConfig Progress: 6/30␊
78+
79+
80+
Awesome! Let's move on to Loops. ␊
81+
Loop is an important statement which is used for repetition of the same code as and when required. ␊
82+
This task will surely test what you have learnt till now from the previous tasks! ␊
83+
84+
Task 6 ␊
85+
Syntax of for loop: ␊
86+
for loop_control_variable in range(start, stop, step): ␊
87+
Loop Body(indented)␊
88+
Here's your task: ␊
89+
90+
Task- 6 ␊
91+
Print even numbers from 1 to 10 (including 10) using for loop.␊
92+
`
93+
94+
> Snapshot 2
95+
96+
` _ _ _ ␊
97+
| |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊
98+
| __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊
99+
| || __/ (_| | (__| | | | (_| (_) | (_| | __/␊
100+
\\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊
101+
␊
102+
 Learn to code effectively Powered by MadHacks␊
103+
104+
105+
User: testConfig Progress: 6/30␊
106+
107+
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:␊
108+
Task 6:-␊
109+
Use 44 & 29 as your operands. Compare them using the Comparison operators in the same order and print the value which they return.␊
110+
`
111+
112+
## display next task with fetchtask
113+
114+
> Snapshot 1
115+
116+
` _ _ _ ␊
117+
| |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊
118+
| __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊
119+
| || __/ (_| | (__| | | | (_| (_) | (_| | __/␊
120+
\\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊
121+
␊
122+
 Learn to code effectively Powered by MadHacks␊
123+
124+
125+
User: testConfig Progress: 6/30␊
126+
127+
128+
Awesome! Let's move on to Loops. ␊
129+
Loop is an important statement which is used for repetition of the same code as and when required. ␊
130+
This task will surely test what you have learnt till now from the previous tasks! ␊
131+
132+
Task 6 ␊
133+
Syntax of for loop: ␊
134+
for loop_control_variable in range(start, stop, step): ␊
135+
Loop Body(indented)␊
136+
Here's your task: ␊
137+
138+
Task- 6 ␊
139+
Print even numbers from 1 to 10 (including 10) using for loop.␊
140+
`
141+
142+
> Snapshot 2
143+
144+
` _ _ _ ␊
145+
| |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊
146+
| __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊
147+
| || __/ (_| | (__| | | | (_| (_) | (_| | __/␊
148+
\\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊
149+
␊
150+
 Learn to code effectively Powered by MadHacks␊
151+
152+
153+
User: testConfig Progress: 6/30␊
154+
155+
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:␊
156+
Task 6:-␊
157+
Use 44 & 29 as your operands. Compare them using the Comparison operators in the same order and print the value which they return.␊
158+
`
159+
160+
## incorrect key for fetchtask
161+
162+
> Snapshot 1
163+
164+
` _ _ _ ␊
165+
| |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊
166+
| __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊
167+
| || __/ (_| | (__| | | | (_| (_) | (_| | __/␊
168+
\\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊
169+
␊
170+
 Learn to code effectively Powered by MadHacks␊
171+
172+
173+
Make sure that you've grabbed the key correctly!␊
174+
175+
`
176+
177+
## no config file for fetchtask
178+
179+
> Snapshot 1
180+
181+
` _ _ _ ␊
182+
| |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊
183+
| __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊
184+
| || __/ (_| | (__| | | | (_| (_) | (_| | __/␊
185+
\\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊
186+
␊
187+
 Learn to code effectively Powered by MadHacks␊
188+
189+
Make sure that you are within the teachcode-solutions directory!␊
190+
191+
cd teachcode-solutions may resolve the issue!␊
192+
193+
`
194+
195+
## no more tasks available
196+
197+
> Snapshot 1
198+
199+
` _ _ _ ␊
200+
| |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊
201+
| __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊
202+
| || __/ (_| | (__| | | | (_| (_) | (_| | __/␊
203+
\\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊
204+
␊
205+
 Learn to code effectively Powered by MadHacks␊
206+
207+
208+
No more tasks available!␊
209+
`
Binary file not shown.

__e2e__/commands/fetchtask.test.js

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
const execa = require('execa');
5+
const test = require('ava');
6+
const fs = require('fs');
7+
8+
const rootCommand = path.join(process.cwd(), 'bin/index.js');
9+
const configFilePath = path.join(process.cwd(), 'config.json');
10+
11+
const learningTracksInfo = [
12+
{ trackName: 'Python', fileExtension: 'py' },
13+
{ trackName: 'JavaScript', fileExtension: 'js' },
14+
];
15+
16+
const userDefaultConfig = {
17+
learningTrack: '',
18+
userName: 'testConfig',
19+
taskCount: 0,
20+
keys: [],
21+
userSubmittedFiles: [],
22+
};
23+
24+
const createUserConfig = (
25+
trackName,
26+
fileExtension,
27+
keysNumber,
28+
filesNumber,
29+
) => {
30+
let userConfig = userDefaultConfig;
31+
userConfig['learningTrack'] = trackName;
32+
for (let i = 0; i < keysNumber; i++) {
33+
userConfig['keys'].push(`testKey${i + 1}`);
34+
}
35+
for (let i = 0; i < filesNumber; i++) {
36+
userConfig['userSubmittedFiles'].push(`task${i + 1}.${fileExtension}`);
37+
}
38+
userConfig['taskCount'] = filesNumber;
39+
40+
return userConfig;
41+
};
42+
43+
test.serial('no config file for fetchtask', async t => {
44+
if (fs.existsSync(configFilePath)) fs.unlinkSync(configFilePath);
45+
const { stdout } = await execa(rootCommand, ['fetchtask'], {
46+
reject: false,
47+
});
48+
t.snapshot(stdout);
49+
});
50+
51+
test.serial('incorrect key for fetchtask', async t => {
52+
let snap = null;
53+
t.assert(learningTracksInfo.length > 0);
54+
for (let index in learningTracksInfo) {
55+
let { trackName, fileExtension } = learningTracksInfo[index];
56+
const userConfig = createUserConfig(trackName, fileExtension, 30, 30);
57+
fs.writeFileSync(configFilePath, JSON.stringify(userConfig));
58+
const { stdout } = await execa(
59+
rootCommand,
60+
['fetchtask', 'incorrectTestKey'],
61+
{ reject: false },
62+
);
63+
fs.unlinkSync(configFilePath);
64+
if (snap) {
65+
t.true(snap === stdout);
66+
} else {
67+
snap = stdout;
68+
}
69+
}
70+
t.snapshot(snap);
71+
});
72+
73+
test.serial('display completed task with fetchtask key', async t => {
74+
t.assert(learningTracksInfo.length > 0);
75+
for (let index in learningTracksInfo) {
76+
let { trackName, fileExtension } = learningTracksInfo[index];
77+
let userConfig = createUserConfig(trackName, fileExtension, 6, 5);
78+
fs.writeFileSync(configFilePath, JSON.stringify(userConfig));
79+
const { stdout } = await execa(rootCommand, ['fetchtask', 'testKey2']);
80+
t.snapshot(stdout);
81+
fs.unlinkSync(configFilePath);
82+
}
83+
});
84+
85+
test.serial('display incomplete task with fetchtask key', async t => {
86+
t.assert(learningTracksInfo.length > 0);
87+
for (let index in learningTracksInfo) {
88+
let { trackName, fileExtension } = learningTracksInfo[index];
89+
let userConfig = createUserConfig(trackName, fileExtension, 6, 5);
90+
fs.writeFileSync(configFilePath, JSON.stringify(userConfig));
91+
const { stdout } = await execa(rootCommand, ['fetchtask', 'testKey6']);
92+
t.snapshot(stdout);
93+
fs.unlinkSync(configFilePath);
94+
fs.unlinkSync(path.join(process.cwd(), `task6.${fileExtension}`));
95+
}
96+
});
97+
98+
test.serial('no more tasks available', async t => {
99+
let snap = null;
100+
t.assert(learningTracksInfo.length > 0);
101+
for (let index in learningTracksInfo) {
102+
let { trackName, fileExtension } = learningTracksInfo[index];
103+
const userConfig = createUserConfig(trackName, fileExtension, 30, 30);
104+
fs.writeFileSync(configFilePath, JSON.stringify(userConfig));
105+
const { stdout } = await execa(rootCommand, ['fetchtask'], {
106+
reject: false,
107+
});
108+
if (snap) {
109+
t.assert(snap === stdout);
110+
} else {
111+
snap = stdout;
112+
}
113+
fs.unlinkSync(configFilePath);
114+
}
115+
t.snapshot(snap);
116+
});
117+
118+
test.serial('display next task with fetchtask', async t => {
119+
t.assert(learningTracksInfo.length > 0);
120+
for (let index in learningTracksInfo) {
121+
let { trackName, fileExtension } = learningTracksInfo[index];
122+
const userConfig = createUserConfig(trackName, fileExtension, 6, 5);
123+
fs.writeFileSync(configFilePath, JSON.stringify(userConfig));
124+
const { stdout } = await execa(rootCommand, ['fetchtask']);
125+
t.snapshot(stdout);
126+
fs.unlinkSync(configFilePath);
127+
fs.unlinkSync(path.join(process.cwd(), `task6.${fileExtension}`));
128+
}
129+
});

0 commit comments

Comments
 (0)