Skip to content

Commit 0b78672

Browse files
committed
✅ Fix test for challenge-01
1 parent f7b32ec commit 0b78672

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

2022/01-arregla-twitter/solution.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
1+
/* eslint-disable implicit-arrow-linebreak */
2+
/* eslint-disable operator-linebreak */
13
const fs = require('fs');
24

35
const obtenerUsuariosIncorrectos = (fileName) => {
46
let results = [];
57
try {
6-
const text = fs.readFileSync(`./2022/01-arregla-twitter/${fileName}`, 'utf8');
7-
const arr = text.toString().split(/\n\s*\n/).map((el) => el.replace(/\n/g, ' '));
8-
results = arr.filter((data) => data.includes('usr:')
9-
&& data.includes('eme:')
10-
&& data.includes('psw:')
11-
&& data.includes('age:')
12-
&& data.includes('loc:')
13-
&& data.includes('fll:'));
14-
return `submit: ${results.length}${results.at(-1)}`;
8+
const text = fs.readFileSync(
9+
`./2022/01-arregla-twitter/${fileName}`,
10+
'utf8',
11+
);
12+
const arr = text
13+
.toString()
14+
.split(/\n\s*\n/)
15+
.map((el) => el.replace(/\n/g, ' '));
16+
results = arr.filter(
17+
(data) =>
18+
data.includes('usr:') &&
19+
data.includes('eme:') &&
20+
data.includes('psw:') &&
21+
data.includes('age:') &&
22+
data.includes('loc:') &&
23+
data.includes('fll:'),
24+
);
25+
return `submit: ${results.length}${results
26+
.at(-1)
27+
.replace(/\s/g, ' ')
28+
.replace(/\s{2,}/g, ' ')
29+
.trim()}`;
1530
} catch (e) {
16-
return `Error: ${e.message}`;
31+
return `Error: when reading file ${fileName}`;
1732
}
1833
};
1934

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1+
/* eslint-disable operator-linebreak */
12
const obtenerUsuariosIncorrectos = require('./solution');
23

34
describe('obtenerUsuariosIncorrectos', () => {
4-
const expected = 'submit: 156usr:@giroz age:22 src:12 icon:avatar.png terminal:yes pages:server '
5-
+ 'pages:blog blog:about loc:tierra psw:aaa fll:222 eme:giroz@gmail.com';
5+
// eslint-disable-next-line operator-linebreak
6+
const expected =
7+
'submit: 156usr:@giroz age:22 src:12 icon:avatar.png terminal:yes pages:server ' +
8+
'pages:blog blog:about loc:tierra psw:aaa fll:222 eme:giroz@gmail.com';
69

710
it(`should return "${expected}"`, () => {
811
expect(obtenerUsuariosIncorrectos('users.txt')).toBe(expected);
912
});
1013

11-
const expectedError = 'Error: ENOENT: no such file or directory, open \'./2022/01-arregla-twitter/users2.txt\'';
12-
13-
it(`should return "${expectedError}"`, () => {
14-
expect(obtenerUsuariosIncorrectos('users2.txt')).toBe(expectedError);
14+
it("should return no such file o directory error'", () => {
15+
const FILE_NAME = 'users2.txt';
16+
expect(obtenerUsuariosIncorrectos(FILE_NAME)).toBe(
17+
`Error: when reading file ${FILE_NAME}`,
18+
);
1519
});
1620
});

0 commit comments

Comments
 (0)