Skip to content

Commit 0d47caf

Browse files
Improve webship-js AIP: Change I as optional I / We #227
1 parent 6c3784c commit 0d47caf

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

tests/step-definitions/webship-api.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Given(/^I am authenticating as "([^"]*)" with "([^"]*)" password$/, function (us
8989
* Example #2: Given I set header "Authorization" with value "Bearer token123"
9090
* Example #3: Given I set header "Accept" with value "application/xml"
9191
*/
92-
Given(/^I set header "([^"]*)" with value "([^"]*)"$/, function (name, value) {
92+
Given(/^(?:I |we )?set header "([^"]*)" with value "([^"]*)"$/, function (name, value) {
9393
apiHeaders[name] = replacePlaceHolder(value);
9494
});
9595

@@ -111,7 +111,7 @@ Given(/^(?:the API base URL is|I set the API base URL to|the base URL is) "([^"]
111111
* Example #2: Given I set the header "Authorization" to "Bearer token123"
112112
* Example #3: Given the header "Accept" is "application/json"
113113
*/
114-
Given(/^(?:I set the header|the header) "([^"]*)" (?:to|is) "([^"]*)"$/, function (headerName, headerValue) {
114+
Given(/^(?:I set the header|we set the header|the header) "([^"]*)" (?:to|is) "([^"]*)"$/, function (headerName, headerValue) {
115115
apiHeaders[headerName] = replacePlaceHolder(headerValue);
116116
});
117117

@@ -123,7 +123,7 @@ Given(/^(?:I set the header|the header) "([^"]*)" (?:to|is) "([^"]*)"$/, functio
123123
* | Authorization | Bearer token123 |
124124
* | Accept | application/json |
125125
*/
126-
Given(/^I set the following headers:$/, function (table) {
126+
Given(/^(?:I|we) set the following headers:$/, function (table) {
127127
table.rows().forEach(row => {
128128
apiHeaders[row[0]] = replacePlaceHolder(row[1]);
129129
});
@@ -135,7 +135,7 @@ Given(/^I set the following headers:$/, function (table) {
135135
* Example #1: Given I set the request body to '{"name": "John", "email": "john@example.com"}'
136136
* Example #2: Given the request body is '{"title": "Test Post", "body": "This is a test"}'
137137
*/
138-
Given(/^(?:I set the request body to|the request body is) '([^']*)'$/, function (jsonData) {
138+
Given(/^(?:I set the request body to|we set the request body to|the request body is) '([^']*)'$/, function (jsonData) {
139139
try {
140140
const processedData = replacePlaceHolder(jsonData);
141141
apiRequestData = JSON.parse(processedData);
@@ -152,7 +152,7 @@ Given(/^(?:I set the request body to|the request body is) '([^']*)'$/, function
152152
* | email | [email protected] |
153153
* | age | 30 |
154154
*/
155-
Given(/^I set the request body with:$/, function (table) {
155+
Given(/^(?:I|we) set the request body with:$/, function (table) {
156156
apiRequestData = {};
157157
table.rows().forEach(row => {
158158
let value = replacePlaceHolder(row[1]);
@@ -170,11 +170,11 @@ Given(/^I set the request body with:$/, function (table) {
170170
* Sends HTTP request to specific relative URL.
171171
*
172172
* Example #1: When I send a GET request to "/users"
173-
* Example #2: When I send a POST request to "/posts"
173+
* Example #2: When we send a POST request to "/posts"
174174
* Example #3: When I send a PUT request to "/users/1"
175-
* Example #4: When I send a DELETE request to "/posts/1"
175+
* Example #4: When we send a DELETE request to "/posts/1"
176176
*/
177-
When(/^(?:I )?send a ([A-Z]+) request to "([^"]+)"$/, async function (method, endpoint) {
177+
When(/^(?:I |we )?send a ([A-Z]+) request to "([^"]+)"$/, async function (method, endpoint) {
178178
const url = baseURL + '/' + prepareUrl(endpoint);
179179

180180
try {
@@ -196,11 +196,12 @@ When(/^(?:I )?send a ([A-Z]+) request to "([^"]+)"$/, async function (method, en
196196
* Sends HTTP request to specific URL with field values from Table.
197197
*
198198
* Example: When I send a POST request to "/users" with values:
199+
* When we send a POST request to "/users" with values:
199200
* | name | John Doe |
200201
* | email | [email protected] |
201202
* | age | 30 |
202203
*/
203-
When(/^(?:I )?send a ([A-Z]+) request to "([^"]+)" with values:$/, async function (method, endpoint, table) {
204+
When(/^(?:I |we )?send a ([A-Z]+) request to "([^"]+)" with values:$/, async function (method, endpoint, table) {
204205
const url = baseURL + '/' + prepareUrl(endpoint);
205206
const fields = {};
206207

@@ -228,14 +229,15 @@ When(/^(?:I )?send a ([A-Z]+) request to "([^"]+)" with values:$/, async functio
228229
* Sends HTTP request to specific URL with raw body from PyString.
229230
*
230231
* Example: When I send a POST request to "/users" with body:
232+
* When we send a POST request to "/users" with body:
231233
* """
232234
* {
233235
* "name": "John Doe",
234236
* "email": "john@example.com"
235237
* }
236238
* """
237239
*/
238-
When(/^(?:I )?send a ([A-Z]+) request to "([^"]+)" with body:$/, async function (method, endpoint, docString) {
240+
When(/^(?:I |we )?send a ([A-Z]+) request to "([^"]+)" with body:$/, async function (method, endpoint, docString) {
239241
const url = baseURL + '/' + prepareUrl(endpoint);
240242
const body = replacePlaceHolder(docString.trim());
241243

@@ -276,13 +278,14 @@ When(/^(?:I )?send a ([A-Z]+) request to "([^"]+)" with body:$/, async function
276278
* Sends HTTP request to specific URL with form data.
277279
*
278280
* Example: When I send a POST request to "/login" with form data:
281+
* When we send a POST request to "/login" with form data:
279282
* """
280283
* username=admin
281284
* password=secret
282285
* remember=true
283286
* """
284287
*/
285-
When(/^(?:I )?send a ([A-Z]+) request to "([^"]+)" with form data:$/, async function (method, endpoint, docString) {
288+
When(/^(?:I |we )?send a ([A-Z]+) request to "([^"]+)" with form data:$/, async function (method, endpoint, docString) {
286289
const url = baseURL + '/' + prepareUrl(endpoint);
287290
const body = replacePlaceHolder(docString.trim());
288291

@@ -530,6 +533,6 @@ Then(/^print API response$/, function () {
530533
*
531534
* Example: Given I set placeholder "{{userId}}" to "123"
532535
*/
533-
Given(/^I set placeholder "([^"]*)" to "([^"]*)"$/, function (placeholder, value) {
536+
Given(/^(?:I|we) set placeholder "([^"]*)" to "([^"]*)"$/, function (placeholder, value) {
534537
placeHolders[placeholder] = value;
535538
});

0 commit comments

Comments
 (0)