-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from pactumjs/164-save-files-from-response-to-fs
164 save files from response to fs
- Loading branch information
Showing
11 changed files
with
194 additions
and
18 deletions.
There are no files selected for viewing
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
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
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
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
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,126 @@ | ||
const { spec } = require('../../src/index'); | ||
const { like } = require('pactum-matchers'); | ||
const { expect } = require('chai'); | ||
|
||
describe('Form', () => { | ||
|
||
it('single pair of form data', async () => { | ||
await spec() | ||
.useInteraction({ | ||
request: { | ||
method: 'POST', | ||
path: '/api/projects', | ||
headers: { | ||
'content-type': 'application/x-www-form-urlencoded' | ||
}, | ||
form: { | ||
'user': 'drake' | ||
} | ||
}, | ||
response: { | ||
status: 200 | ||
} | ||
}) | ||
.post('http://localhost:9393/api/projects') | ||
.withForm({ 'user': 'drake' }) | ||
.expectStatus(200); | ||
}); | ||
|
||
it('multiple pairs of form data', async () => { | ||
await spec() | ||
.useInteraction({ | ||
request: { | ||
method: 'POST', | ||
path: '/api/projects', | ||
headers: { | ||
'content-type': 'application/x-www-form-urlencoded' | ||
}, | ||
form: { | ||
'user': 'drake', | ||
'age': '10' | ||
} | ||
}, | ||
response: { | ||
status: 200 | ||
} | ||
}) | ||
.post('http://localhost:9393/api/projects') | ||
.withForm({ 'user': 'drake', 'age': 10 }) | ||
.expectStatus(200); | ||
}); | ||
|
||
it('using matchers', async () => { | ||
await spec() | ||
.useInteraction({ | ||
request: { | ||
method: 'POST', | ||
path: '/api/projects', | ||
headers: { | ||
'content-type': 'application/x-www-form-urlencoded' | ||
}, | ||
form: { | ||
'user': like('drake') | ||
} | ||
}, | ||
response: { | ||
status: 200 | ||
} | ||
}) | ||
.post('http://localhost:9393/api/projects') | ||
.withForm({ 'user': 'brake' }) | ||
.expectStatus(200); | ||
}); | ||
|
||
it('fails to match', async () => { | ||
let err; | ||
try { | ||
await spec() | ||
.useInteraction({ | ||
request: { | ||
method: 'POST', | ||
path: '/api/projects', | ||
headers: { | ||
'content-type': 'application/x-www-form-urlencoded' | ||
}, | ||
form: { | ||
'user': 'drake' | ||
} | ||
}, | ||
response: { | ||
status: 200 | ||
} | ||
}) | ||
.post('http://localhost:9393/api/projects') | ||
.withForm({ 'user': 'drake', 'age': 10 }) | ||
.useLogLevel('SILENT') | ||
.expectStatus(200); | ||
} catch (error) { | ||
err = error; | ||
} | ||
expect(err).not.undefined; | ||
}); | ||
|
||
it('disabling strict', async () => { | ||
await spec() | ||
.useInteraction({ | ||
strict: false, | ||
request: { | ||
method: 'POST', | ||
path: '/api/projects', | ||
headers: { | ||
'content-type': 'application/x-www-form-urlencoded' | ||
}, | ||
form: { | ||
'user': 'drake' | ||
} | ||
}, | ||
response: { | ||
status: 200 | ||
} | ||
}) | ||
.post('http://localhost:9393/api/projects') | ||
.withForm({ 'user': 'drake', 'age': 10 }) | ||
.expectStatus(200); | ||
}); | ||
|
||
}); |
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,13 @@ | ||
const { spec } = require('../../src/index'); | ||
|
||
describe('Save', () => { | ||
|
||
it('save json file', async () => { | ||
await spec() | ||
.useInteraction('get people') | ||
.get('http://localhost:9393/api/people') | ||
.save('.pactum/users.json') | ||
.expectStatus(200); | ||
}); | ||
|
||
}); |