feat: init files
This commit is contained in:
45
features/crud.feature
Normal file
45
features/crud.feature
Normal file
@ -0,0 +1,45 @@
|
||||
Feature: CRUD Operations on Records
|
||||
|
||||
Scenario Outline: Create a record with name "<name>", age <age>, and email "<email>"
|
||||
Given the API is runing
|
||||
When I create a record with name "<name>", age <age>, email "<email>"
|
||||
Then the response status should be 201
|
||||
And the response should contain an id
|
||||
|
||||
Examples:
|
||||
| name | age | email |
|
||||
| John Smith | 30 | john@example.com |
|
||||
| Jane Doe | 25 | jane@example.com |
|
||||
|
||||
Scenario Outline: Get the record by ID after creation with name "<name>", age <age>, email "<email>"
|
||||
Given the API is running
|
||||
And I have a created record with name "<name>", age <age>, email "<email>"
|
||||
When I get the record by ID
|
||||
Then the response status should be 200
|
||||
And the response should contain the correct data for name "<name>", age <age>, email "<email>"
|
||||
|
||||
Examples:
|
||||
| name | age | email |
|
||||
| Temp_Name | 25 | temp@example.com |
|
||||
|
||||
Scenario Outline: Update the record with name "<oldName>", age <oldAge>, email "<oldEmail>" to name "<newName>", age <newAge>, email "<newEmail>"
|
||||
Given the API is running
|
||||
And I have a created record with name "<oldName>", age <oldAge>, email "<oldEmail>"
|
||||
When I update the record with name "<newName>", age <newAge>, email "<newEmail>"
|
||||
Then the response status should be 200
|
||||
And the response should contain updated true
|
||||
|
||||
Examples:
|
||||
| oldName | oldAge | oldEmail | newName | newAge | newEmail |
|
||||
| Temp_Name | 25 | temp@example.com | Jane Smith | 28 | jane@example.com |
|
||||
|
||||
Scenario Outline: Delete the record with name "<name>", age <age>, email "<email>"
|
||||
Given the API is running
|
||||
And I have a created record with name "<name>", age <age>, email "<email>"
|
||||
When I delete the record by ID
|
||||
Then the response status should be 200
|
||||
And the response should contain deleted true
|
||||
|
||||
Examples:
|
||||
| name | age | email |
|
||||
| Temp_Name | 25 | temp@example.com |
|
||||
93
features/step_definitions/crud.steps.js
Normal file
93
features/step_definitions/crud.steps.js
Normal file
@ -0,0 +1,93 @@
|
||||
import { Given, When, Then } from '@cucumber/cucumber';
|
||||
import assert from 'assert';
|
||||
import axios from 'axios';
|
||||
|
||||
const BASE_URL = 'http://localhost:3000';
|
||||
let response;
|
||||
let createdRecord;
|
||||
|
||||
// Utility to log requests
|
||||
function logRequest(method, url, data) {
|
||||
console.log(`\n>>> REQUEST: ${method.toUpperCase()} ${url}`);
|
||||
if (data) {
|
||||
console.log('Payload:', JSON.stringify(data, null, 2));
|
||||
}
|
||||
}
|
||||
|
||||
// Utility to log responses
|
||||
function logResponse(res) {
|
||||
console.log(`<<< RESPONSE: Status ${res.status}`);
|
||||
console.log('Response data:', JSON.stringify(res.data, null, 2));
|
||||
}
|
||||
|
||||
Given('the API is running', async function () {
|
||||
// Optionally ping /health or just assume running
|
||||
// Example:
|
||||
// const res = await axios.get(`${BASE_URL}/health`);
|
||||
// assert.strictEqual(res.status, 200);
|
||||
});
|
||||
|
||||
When('I create a record with name {string}, age {int}, email {string}', async function (name, age, email) {
|
||||
const url = `${BASE_URL}/records`;
|
||||
const payload = { name, age, email };
|
||||
logRequest('post', url, payload);
|
||||
response = await axios.post(url, payload);
|
||||
logResponse(response);
|
||||
createdRecord = response.data;
|
||||
});
|
||||
|
||||
Then('the response status should be {int}', function (status) {
|
||||
assert.strictEqual(response.status, status);
|
||||
});
|
||||
|
||||
Then('the response should contain an id', function () {
|
||||
assert.ok(createdRecord.id, 'Response does not contain an id');
|
||||
});
|
||||
|
||||
Given('I have a created record with name {string}, age {int}, email {string}', async function (name, age, email) {
|
||||
const url = `${BASE_URL}/records`;
|
||||
const payload = { name, age, email };
|
||||
logRequest('post', url, payload);
|
||||
const res = await axios.post(url, payload);
|
||||
logResponse(res);
|
||||
createdRecord = res.data;
|
||||
});
|
||||
|
||||
When('I get the record by ID', async function () {
|
||||
const url = `${BASE_URL}/records/${createdRecord.id}`;
|
||||
logRequest('get', url);
|
||||
response = await axios.get(url);
|
||||
logResponse(response);
|
||||
});
|
||||
|
||||
Then(
|
||||
'the response should contain the correct data for name {string}, age {int}, email {string}',
|
||||
function (name, age, email) {
|
||||
assert.strictEqual(response.data.name, name);
|
||||
assert.strictEqual(response.data.age, age);
|
||||
assert.strictEqual(response.data.email, email);
|
||||
}
|
||||
);
|
||||
|
||||
When('I update the record with name {string}, age {int}, email {string}', async function (name, age, email) {
|
||||
const url = `${BASE_URL}/records/${createdRecord.id}`;
|
||||
const payload = { name, age, email };
|
||||
logRequest('put', url, payload);
|
||||
response = await axios.put(url, payload);
|
||||
logResponse(response);
|
||||
});
|
||||
|
||||
Then('the response should contain updated true', function () {
|
||||
assert.strictEqual(response.data.updated, true);
|
||||
});
|
||||
|
||||
When('I delete the record by ID', async function () {
|
||||
const url = `${BASE_URL}/records/${createdRecord.id}`;
|
||||
logRequest('delete', url);
|
||||
response = await axios.delete(url);
|
||||
logResponse(response);
|
||||
});
|
||||
|
||||
Then('the response should contain deleted true', function () {
|
||||
assert.strictEqual(response.data.deleted, true);
|
||||
});
|
||||
Reference in New Issue
Block a user