Skip to content

Commit 7be2cbb

Browse files
committed
Add cypress plugin to clean/seed database
1 parent 9ee5023 commit 7be2cbb

File tree

5 files changed

+46
-29
lines changed

5 files changed

+46
-29
lines changed
Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
1+
import faker from 'faker';
2+
13
describe('Courses', () => {
24

3-
it('can create a course', () => {
4-
const courseName = 'New course';
5+
beforeEach(() => {
6+
cy.task('reset:db');
7+
});
8+
9+
it('can create courses', () => {
510
cy.visit('http://localhost:8032/courses');
611

7-
cy.get('input[name="name"]').type(courseName);
8-
cy.get('input[name="duration"]').type('8 days');
9-
cy.get('form').submit();
12+
cy.contains('Actualmente CodelyTV Pro cuenta con 0 cursos.');
13+
14+
let i = 0;
15+
while (i <= 5) {
16+
i++;
17+
const courseName = faker.lorem.sentence(2);
18+
cy.get('input[name="name"]').type(courseName);
19+
cy.get('input[name="duration"]').type('8 days');
20+
cy.get('form').submit();
1021

11-
cy.get('div[role="alert"]').contains(`Felicidades, el curso ${courseName} ha sido creado!`);
12-
// cy.contains('Actualmente CodelyTV Pro cuenta con 10 curso');
22+
cy.get('div[role="alert"]').contains(`Felicidades, el curso ${courseName} ha sido creado!`);
23+
cy.contains(`Actualmente CodelyTV Pro cuenta con ${i} cursos.`);
24+
}
1325
});
1426
});

cypress/plugins/index.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

cypress/plugins/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import container from '../../src/apps/mooc_backend/config/dependency-injection';
2+
import { EnvironmentArranger } from '../../tests/Contexts/Shared/infrastructure/arranger/EnvironmentArranger';
3+
import {seed} from '../../src/apps/backoffice/frontend/seed';
4+
5+
const environmentArranger: Promise<EnvironmentArranger> = container.get('Mooc.EnvironmentArranger');
6+
7+
export default (on: Cypress.PluginEvents, config: Cypress.PluginConfig) => {
8+
on('task', {
9+
async 'reset:db'() {
10+
await (await environmentArranger).arrange();
11+
await seed();
12+
return null;
13+
}
14+
});
15+
};

cypress/tsconfig.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"lib": ["es2015", "dom"],
5+
"types": ["cypress"]
6+
},
7+
"include": [
8+
"**/*.ts"
9+
]
10+
}
11+

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class CoursesPostController extends WebController {
1212
static validator(): ValidationChain[] {
1313
return [
1414
body('id').isUUID(),
15-
body('name').isLength({ min: 1, max: 255 }),
15+
body('name').isLength({ min: 1, max: 30 }),
1616
body('duration').isLength({ min: 4, max: 100 })
1717
];
1818
}

0 commit comments

Comments
 (0)