Last active
September 21, 2016 15:42
-
-
Save tshortt/e453cf12ea7c3114f0c166dc9e75bdfa to your computer and use it in GitHub Desktop.
Two Pact interactions, one with, one without query string
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
/*eslint-disable*/ | |
(function(Pact) { | |
describe('Client', function() { | |
var client, projectsProvider; | |
beforeAll(function(done) { | |
client = example.createClient('http://localhost:1234'); //jshint ignore:line | |
projectsProvider = Pact({ //jshint ignore:line | |
consumer: 'Employee Records', | |
provider: 'Employee' | |
}); | |
// required for slower Travis CI environment | |
setTimeout(function() { | |
done(); | |
}, 2000); | |
}); | |
afterAll(function(done) { | |
projectsProvider.finalize() | |
.then(function() { | |
done(); | |
}, function(err) { | |
done.fail(err); | |
}); | |
}); | |
describe('employee', function() { | |
beforeEach(function(done) { | |
projectsProvider.addInteraction({ | |
uponReceiving: 'a request for employee', | |
withRequest: { | |
method: 'get', | |
path: '/EmployeeApi/api/organizations/0/employees' | |
}, | |
willRespondWith: { | |
status: 200, | |
headers: { | |
'Content-Type': 'application/json; charset=utf-8' | |
}, | |
body: { | |
'data': [{ | |
'id': '0', | |
'type': 'employees' | |
}] | |
} | |
} | |
}) | |
.then(function() { | |
done(); | |
}, function(err) { | |
done.fail(err); | |
}); | |
}); | |
it('should respond with proper schema', function(done) { | |
//Run the tests | |
client.employee() | |
.then(projectsProvider.verify) | |
.then(function(response) { | |
// var resp = JSON.parse(response); | |
done(); | |
}) | |
.catch(function(err) { | |
done.fail(err); | |
}); | |
}); | |
}); | |
describe('employees with email', function() { | |
beforeEach(function(done) { | |
projectsProvider.addInteraction({ | |
uponReceiving: 'a request for employee with email', | |
withRequest: { | |
method: 'get', | |
path: '/EmployeeApi/api/organizations/0/employees', | |
query: { | |
'include': 'emails' | |
} | |
}, | |
willRespondWith: { | |
status: 200, | |
headers: { | |
'Content-Type': 'application/json; charset=utf-8' | |
}, | |
body: { | |
'data': [{ | |
'id': '0', | |
'type': 'employees', | |
'email': 'employee@foo.com' | |
}] | |
} | |
} | |
}) | |
.then(function() { | |
done(); | |
}, function(err) { | |
done.fail(err); | |
}); | |
}); | |
it('should respond with proper schema', function(done) { | |
//Run the tests | |
client.employeesWithEmails() | |
.then(projectsProvider.verify) | |
.then(function(response) { | |
// var resp = JSON.parse(response); | |
// expect(resp.data[0].attributes.firstName).toEqual('firstName'); | |
done(); | |
}) | |
.catch(function(err) { | |
done.fail(err); | |
}); | |
}); | |
}); | |
}); | |
})(Pact); |
Author
tshortt
commented
Sep 21, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment