Skip to content

Commit 359e893

Browse files
committed
Reuse step definitions
1 parent b98cc0e commit 359e893

File tree

6 files changed

+42
-28
lines changed

6 files changed

+42
-28
lines changed

cucumber.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
let common = [
22
'tests/**/features/*.feature', // Specify our feature files
33
'--require-module ts-node/register', // Load TypeScript module
4-
'--require tests/**/features/*.steps.ts' // Load step definitions
4+
'--require tests/**/features/step_definitions/*.steps.ts' // Load step definitions
55
].join(' ');
66

77
module.exports = {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Feature: Create a new course
2+
In order to have courses in the platform
3+
As a user with admin permissions
4+
I want to create a new course
5+
6+
Scenario: A valid unexisting course
7+
Given I send a PUT request to "/courses/ef8ac118-8d7f-49cc-abec-78e0d05af80a" with body:
8+
"""
9+
{
10+
"name": "The best course",
11+
"duration": "5 hours"
12+
}
13+
"""
14+
Then the response status code should be 201
15+
And the response should be empty

tests/apps/mooc_backend/features/create-course.test.ts

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

tests/apps/mooc_backend/features/status.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Feature: Api status
55

66
Scenario: Check the api status
77
Given I send a GET request to "/status"
8-
Then the response code should be 200
8+
Then the response status code should be 200

tests/apps/mooc_backend/features/status.steps.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Given, Then } from 'cucumber';
2+
import request from 'supertest';
3+
import app from '../../../../../src/apps/mooc_backend/app';
4+
import assert from 'assert';
5+
6+
let _request: request.Test;
7+
let _response: request.Response;
8+
9+
Given('I send a GET request to {string}', (route: string) => {
10+
_request = request(app).get(route);
11+
});
12+
13+
Given('I send a PUT request to {string} with body:', (route: string, body: string) => {
14+
_request = request(app)
15+
.put(route)
16+
.send(body);
17+
});
18+
19+
Then('the response status code should be {int}', async (status: number) => {
20+
_response = await _request.expect(status);
21+
});
22+
23+
Then('the response should be empty', () => {
24+
assert.deepEqual(_response.body, {});
25+
});

0 commit comments

Comments
 (0)