Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add repeat tag #13

Merged
merged 9 commits into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Example: `login.data.yaml`
* [print](#print)
* [only](#only)
* [skip](#skip)
* [repeat](#repeat)
* [before](#before)
* [after](#after)
* [expect](#expect)
Expand Down Expand Up @@ -258,6 +259,15 @@ skip: true
```
<br />

**<a name='repeat'>`repeat:`</a>**
If you want to run a test more than once without repeating the all test data you can use the `repeat` Example:
```sh
repeat: 10
```
In the case above the same test would be repeated 10 times

<br />

**<a name='before'>`before:`</a>**
With its default "BDD"-style interface, openapitest, provides the hooks before, these should be used to set up preconditions or debug before your tests.
```js
Expand Down
26 changes: 26 additions & 0 deletions fixtures/fixture.only.spec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiCalls:
swagger:
- name: Login - success
only: true
call: post_users_login
header:
Content-Type: application/json
data:
email: !faker "internet.email"
password: !faker ["internet.password", "file"]
expect:
status: 200
json:
- user.status: ENABLED
save:
userResponse: json


tests:
- name: Checking login response
expects:
- userResponse.message: to.be User logged Successfully

- name: User information exist
expects:
- userResponse: to.have.key user
26 changes: 26 additions & 0 deletions fixtures/fixture.repeat.spec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiCalls:
swagger:
- name: Login - success
repeat: 3
call: post_users_login
header:
Content-Type: application/json
data:
email: !faker "internet.email"
password: !faker ["internet.password", "file"]
expect:
status: 200
json:
- user.status: ENABLED
save:
userResponse: json


tests:
- name: Checking login response
expects:
- userResponse.message: to.be User logged Successfully

- name: User information exist
expects:
- userResponse: to.have.key user
26 changes: 26 additions & 0 deletions fixtures/fixture.skip.spec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiCalls:
swagger:
- name: Login - success
skip: true
call: post_users_login
header:
Content-Type: application/json
data:
email: !faker "internet.email"
password: !faker ["internet.password", "file"]
expect:
status: 200
json:
- user.status: ENABLED
save:
userResponse: json


tests:
- name: Checking login response
expects:
- userResponse.message: to.be User logged Successfully

- name: User information exist
expects:
- userResponse: to.have.key user
27 changes: 14 additions & 13 deletions fixtures/fixture.spec.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
apiCalls:
- name: Login - success
call: post_users_login
header:
Content-Type: application/json
data:
email: !faker "internet.email"
password: !faker ["internet.password", "file"]
expect:
status: 200
json:
- user.status: ENABLED
save:
userResponse: json
swagger:
- name: Login - success
call: post_users_login
header:
Content-Type: application/json
data:
email: !faker "internet.email"
password: !faker ["internet.password", "file"]
expect:
status: 200
json:
- user.status: ENABLED
save:
userResponse: json


tests:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"superagent": "^4.1.0"
},
"devDependencies": {
"sinon": "^7.4.1",
"eslint": "^5.16.0",
"eslint-config-airbnb-base": "^13.2.0",
"eslint-plugin-import": "^2.18.2"
Expand Down
50 changes: 41 additions & 9 deletions specs/apiCall.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const {
expect,
} = require('chai')

const { first } = require('lodash')
const {
first,
} = require('lodash')
const sinon = require('sinon')

const ApiPort = require('../src/apiPort.js')
const ApiCall = require('../src/apiCall.js')
Expand All @@ -24,7 +26,7 @@ describe('apiCall', () => {
describe('init', () => {
it('Should load file property', () => {
const apiCallConfig = new ApiCall('./fixtures/fixture.spec.yaml', apiPort);
const apiCalls = first(apiCallConfig.apiCalls)
const apiCalls = first(apiCallConfig.apiCalls.swagger)
const test = first(apiCallConfig.tests)

expect(apiCalls).to.deep.include({
Expand All @@ -46,23 +48,53 @@ describe('apiCall', () => {

expect(test).to.deep.include({
name: 'Checking login response',
expects: [
{
'userResponse.message': 'to.be User logged Successfully',
},
],
expects: [{
'userResponse.message': 'to.be User logged Successfully',
}],
})
})


it('Should evaluate global fake data', () => {
const apiCallConfig = new ApiCall('./fixtures/fixture.spec.yaml', apiPort);
const apiCall = first(apiCallConfig.apiCalls)
const apiCall = first(apiCallConfig.apiCalls.swagger)
const body = apiCall.data
expect(body.email).to.be.a('string')
expect(body.email).not.to.have.string('!faker')

expect(body.password).not.to.be.a('string')
})


it('Should repeat the file if the repeat tag is present change the it text', () => {
const fakeIt = sinon.spy()
ApiCall('./fixtures/fixture.repeat.spec.yaml', apiPort, fakeIt)
sinon.assert.callCount(fakeIt, 3)
sinon.assert.calledWith(fakeIt, 'Login - success - 0')
sinon.assert.calledWith(fakeIt, 'Login - success - 1')
sinon.assert.calledWith(fakeIt, 'Login - success - 2')
})

it('Should call the only method if the only tag is present', () => {
const fakeOnly = sinon.spy()
const fakeSkip = sinon.spy()
ApiCall('./fixtures/fixture.only.spec.yaml', apiPort, {
skip: fakeSkip,
only: fakeOnly,
})
sinon.assert.calledWith(fakeOnly, 'Login - success')
sinon.assert.notCalled(fakeSkip)
})

it('Should call the skip method if the skip tag is present', () => {
const fakeSkip = sinon.spy()
const fakeOnly = sinon.spy()
ApiCall('./fixtures/fixture.skip.spec.yaml', apiPort, {
skip: fakeSkip,
only: fakeOnly,
})
sinon.assert.calledWith(fakeSkip, 'Login - success')
sinon.assert.notCalled(fakeOnly)
})
})
})
Loading