Skip to content

Commit

Permalink
Add some edge tests
Browse files Browse the repository at this point in the history
  • Loading branch information
byrdware committed Aug 30, 2019
1 parent 2b154ac commit cea5d96
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion test/rester-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,34 @@ describe('Rester', function() {
done();
});

it('should gracefully handle empty or missing vars during substitution', function(done) {
const values = [':num',':str',':obj',':foo'];
const replaced = app._substitute(null, values);
expect(replaced[0]).to.equal(':num');
expect(replaced[1]).to.equal(':str');
expect(replaced[2]).to.equal(':obj');
expect(replaced[3]).to.equal(':foo');
done();
});

it('should gracefully handle empty or missing values during substitution', function(done) {
const vars = { num: 1, str: 'hello world', obj: { foo: 'bar' } };
const replaced = app._substitute(vars, null);
expect(replaced).to.be.an('array').and.to.be.empty;
done();
});

it('should gracefully handle partial matches during substitution', function(done) {
const vars = { num: 1, obj: { foo: 'bar' } };
const values = [':num',':str',':obj',':foo'];
const replaced = app._substitute(vars, values);
expect(replaced[0]).to.equal('1');
expect(replaced[1]).to.equal(':str');
expect(replaced[2]).to.equal('[object Object]');
expect(replaced[3]).to.equal(':foo');
done();
});

it('should retrieve a variables object', function(done) {
var vars = [{
key: 'numResults',
Expand All @@ -61,9 +89,10 @@ describe('Rester', function() {
type: 'text'
},{
key: 'x-access-token',
value: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7ImVtYWlsIjoiY25AcGxhY2UuY29tIiwiZmlyc3ROYW1lIjoiQ2hhcmxlcyIsImxhc3ROYW1lIjoiTmVtb3kifSwiaWF0IjoxNTY2NTczMjAyLCJleHAiOjE1NjY1NzY4MDJ9.X81vTt4DsO5xtbxuMlY9QbtIJFbiTSBYR85_4ux3jjg',
value: null,
type: 'text'
}];
app._xAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7ImVtYWlsIjoiY25AcGxhY2UuY29tIiwiZmlyc3ROYW1lIjoiQ2hhcmxlcyIsImxhc3ROYW1lIjoiTmVtb3kifSwiaWF0IjoxNTY2NTczMjAyLCJleHAiOjE1NjY1NzY4MDJ9.X81vTt4DsO5xtbxuMlY9QbtIJFbiTSBYR85_4ux3jjg';
const headers = app._getHeaders(hdrs);
expect(headers['Content-Type']).to.equal('application/json');
expect(headers['x-access-token']).to.equal('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7ImVtYWlsIjoiY25AcGxhY2UuY29tIiwiZmlyc3ROYW1lIjoiQ2hhcmxlcyIsImxhc3ROYW1lIjoiTmVtb3kifSwiaWF0IjoxNTY2NTczMjAyLCJleHAiOjE1NjY1NzY4MDJ9.X81vTt4DsO5xtbxuMlY9QbtIJFbiTSBYR85_4ux3jjg');
Expand Down Expand Up @@ -99,6 +128,16 @@ describe('Rester', function() {
done();
});

it('should gracefully recover from malformed body objects', function(done) {
var body = app._getBody('foo');
expect(body).to.be.empty;
body = app._getBody(undefined);
expect(body).to.be.empty;
body = app._getBody(this);
expect(body).to.be.empty;
done();
});

it('should run a single test', function(done) {
var test = {
name: 'Test test',
Expand Down

0 comments on commit cea5d96

Please sign in to comment.