-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
958dc6a
commit 5fafad7
Showing
7 changed files
with
133 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"cSpell.words": [ | ||
"pactum" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,30 @@ | ||
const { request, settings } = require('pactum'); | ||
const { Before } = require('@cucumber/cucumber'); | ||
const { request, settings, events } = require('pactum'); | ||
const { Before, AfterStep } = require('@cucumber/cucumber'); | ||
|
||
|
||
Before(() => { | ||
request.setBaseUrl('https://reqres.in'); | ||
settings.setReporterAutoRun(false); | ||
}); | ||
|
||
let req = {}; | ||
let res = {}; | ||
|
||
AfterStep(function(ctx) { | ||
this.attach(JSON.stringify({req, res}), { mediaType: 'application/json' }); | ||
}); | ||
|
||
events.pactumEvents.on(events.EVENT_TYPES.AFTER_RESPONSE, (ctx) => { | ||
|
||
req = {}; | ||
req.url = ctx.request.url; | ||
req.method = ctx.request.method; | ||
req.body = ctx.request.body; | ||
req.headers = ctx.request.headers; | ||
|
||
res = {}; | ||
res.status = ctx.response.statusCode; | ||
res.body = ctx.response.body; | ||
res.headers = ctx.response.headers; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ Given('I create a new user', async () => { | |
}); | ||
}); | ||
|
||
Given('I fetch users', async () => { | ||
Given('I fetch user by id', async () => { | ||
await spec() | ||
.get('/api/users/2') | ||
.expectStatus(200) | ||
|
@@ -32,4 +32,19 @@ Given('I fetch users', async () => { | |
"avatar": "https://reqres.in/img/faces/2-image.jpg" | ||
} | ||
}); | ||
}); | ||
|
||
Given('I fetch all users', async () => { | ||
await spec() | ||
.get('/api/users') | ||
.expectStatus(200) | ||
.expectJsonLike({ | ||
"data": { | ||
"id": 2, | ||
"email": "[email protected]", | ||
"first_name": "Janet", | ||
"last_name": "Weaver", | ||
"avatar": "https://reqres.in/img/faces/2-image.jpg" | ||
} | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters