Skip to content

Commit 5bd79e3

Browse files
committed
Include more e2e tests
1 parent fc97497 commit 5bd79e3

File tree

5 files changed

+119
-12
lines changed

5 files changed

+119
-12
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"@types/cookie-parser": "^1.4.2",
6969
"@types/cookie-session": "^2.0.41",
7070
"@types/cucumber": "^6.0.1",
71-
"@types/faker": "^5.1.0",
71+
"@types/faker": "^5.1.2",
7272
"@types/jest": "^26.0.14",
7373
"@types/nunjucks": "^3.1.3",
7474
"@types/supertest": "^2.0.10",

src/apps/backoffice/frontend/controllers/CoursesPostController.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ export class CoursesPostController extends WebController {
1111

1212
static validator(): ValidationChain[] {
1313
return [
14-
body('id').isUUID(),
15-
body('name').isLength({ min: 1, max: 30 }),
16-
body('duration').isLength({ min: 4, max: 100 })
14+
body('id').isUUID().withMessage('Invalid course id'),
15+
body('name').isLength({ min: 1, max: 30 }).withMessage('Invalid name'),
16+
body('duration').isLength({ min: 4, max: 100 }).withMessage('Invalid duration')
1717
];
1818
}
1919

src/apps/backoffice/frontend/controllers/WebController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export abstract class WebController {
4040

4141
protected render(req: Request, res: Response, template: string, data: { [key: string]: any }) {
4242
const flash = this.feedFlash(req, data);
43-
res.render('pages/courses/courses', {
43+
res.render(template, {
4444
...data,
4545
...flash
4646
});
Lines changed: 111 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import faker from 'faker';
22

33
describe('Courses', () => {
4-
beforeEach(() => {
4+
before(() => {
55
cy.task('reset:db');
66
});
77

8-
it('can create courses', () => {
8+
beforeEach(() => {
99
cy.visit('courses');
10+
});
1011

12+
it('can create courses', () => {
1113
cy.contains('Actualmente CodelyTV Pro cuenta con 0 cursos.');
1214

1315
let i = 0;
14-
while (i <= 5) {
16+
while (i <= 3) {
1517
i++;
16-
const courseName = faker.lorem.sentence(2);
18+
const courseName = faker.random.words(1);
1719
cy.get('input[name="name"]').type(courseName);
1820
cy.get('input[name="duration"]').type('8 days');
1921
cy.get('form').submit();
@@ -22,4 +24,109 @@ describe('Courses', () => {
2224
cy.contains(`Actualmente CodelyTV Pro cuenta con ${i} cursos.`);
2325
}
2426
});
27+
28+
describe('Course id field', () => {
29+
it('has value by default', () => {
30+
cy.get('input[name="id"]').invoke('val').should('not.be.empty');
31+
});
32+
33+
it('has flash messages when is invalid', () => {
34+
cy.get('input[name="id"]').clear().type('invalid course id');
35+
cy.get('form').submit();
36+
37+
cy.get('input[name="id"] + p').contains('Invalid course id');
38+
});
39+
40+
it('maintain the value introduced by the user when invalid', () => {
41+
cy.get('input[name="id"]').clear().type('invalid course id');
42+
cy.get('form').submit();
43+
44+
cy.get('input[name="id"]').should('have.value', 'invalid course id');
45+
});
46+
47+
it('maintain the value introduced by the user when valid', () => {
48+
const uuid = faker.random.uuid();
49+
50+
cy.get('input[name="id"]').clear().type(uuid);
51+
cy.get('form').submit();
52+
53+
cy.get('input[name="id"]').should('have.value', uuid);
54+
});
55+
});
56+
57+
describe('Name field', () => {
58+
it('has flash messages when is empty', () => {
59+
cy.get('form').submit();
60+
61+
cy.get('input[name="name"] + p').contains('Invalid name');
62+
});
63+
64+
it('has flash messages when is longer than 30 character', () => {
65+
cy.get('input[name="name"]').type(faker.random.alphaNumeric(31));
66+
67+
cy.get('form').submit();
68+
69+
cy.get('input[name="name"] + p').contains('Invalid name');
70+
});
71+
72+
it('maintain the value introduced by the user when invalid', () => {
73+
const invalidCourseName = faker.random.alphaNumeric(3);
74+
75+
cy.get('input[name="name"]').clear().type(invalidCourseName);
76+
cy.get('form').submit();
77+
78+
cy.get('input[name="name"]').should('have.value', invalidCourseName);
79+
});
80+
81+
it('maintain the value introduced by the user when valid', () => {
82+
const validCourseName = faker.random.alphaNumeric(1);
83+
84+
cy.get('input[name="name"]').clear().type(validCourseName);
85+
cy.get('form').submit();
86+
87+
cy.get('input[name="name"]').should('have.value', validCourseName);
88+
});
89+
});
90+
91+
describe('Duration field', () => {
92+
it('has flash messages when is empty', () => {
93+
cy.get('form').submit();
94+
95+
cy.get('input[name="duration"] + p').contains('Invalid duration');
96+
});
97+
98+
it('has flash messages when is shorter than 4 character', () => {
99+
cy.get('input[name="duration"]').type(faker.random.alphaNumeric(3));
100+
101+
cy.get('form').submit();
102+
103+
cy.get('input[name="duration"] + p').contains('Invalid duration');
104+
});
105+
106+
it('has flash messages when is longer than 100 character', () => {
107+
cy.get('input[name="duration"]').type(faker.random.alphaNumeric(101));
108+
109+
cy.get('form').submit();
110+
111+
cy.get('input[name="duration"] + p').contains('Invalid duration');
112+
});
113+
114+
it('maintain the value introduced by the user when invalid', () => {
115+
const invalidCourseDuration = faker.random.alphaNumeric(101);
116+
117+
cy.get('input[name="duration"]').clear().type(invalidCourseDuration);
118+
cy.get('form').submit();
119+
120+
cy.get('input[name="duration"]').should('have.value', invalidCourseDuration);
121+
});
122+
123+
it('maintain the value introduced by the user when valid', () => {
124+
const validCourseDuration = faker.random.alphaNumeric(5);
125+
126+
cy.get('input[name="duration"]').clear().type(validCourseDuration);
127+
cy.get('form').submit();
128+
129+
cy.get('input[name="duration"]').should('have.value', validCourseDuration);
130+
});
131+
});
25132
});

0 commit comments

Comments
 (0)