-
Notifications
You must be signed in to change notification settings - Fork 42
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 #88 from aydrian/ISSUE-79
Modified toApiFormat spec test file to fit standard naming convention. Added tests for code coverage.
- Loading branch information
Showing
3 changed files
with
155 additions
and
82 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
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
'use strict'; | ||
|
||
var chai = require('chai') | ||
, sinon = require('sinon') | ||
, sinonChai = require('sinon-chai') | ||
, toApiFormat = require('../../lib/toApiFormat') | ||
, expect = chai.expect | ||
, _ = require('lodash') | ||
; | ||
|
||
chai.use(sinonChai); | ||
|
||
describe('toApiFormat', function() { | ||
it('should recursively convert complex object keys to snake_case', function(done) { | ||
var testObj = { | ||
simpleString: "foo" | ||
, boolVal: true | ||
, numBers: 201 | ||
, bangObj: { | ||
strTwo: "bar" | ||
, string_three: "skip" | ||
} | ||
, recipients: [ | ||
{name: 'John Doe', address: '[email protected]'} | ||
, {name: 'Sam Jones', address: '[email protected]'} | ||
] | ||
, fizzArr: [ | ||
{ | ||
buzzInga: "buzz" | ||
, bang: { | ||
bellHop: "bell" | ||
} | ||
} | ||
, { | ||
bilBo: "baggins" | ||
, alias: { | ||
misTer: "underhill" | ||
} | ||
} | ||
] | ||
, good_name: null | ||
}; | ||
|
||
var validationObj = { | ||
simple_string: "foo" | ||
, bool_val: true | ||
, num_bers: 201 | ||
, bang_obj: { | ||
str_two: "bar" | ||
, string_three: "skip" | ||
} | ||
, recipients: [ | ||
{name: 'John Doe', address: '[email protected]'} | ||
, {name: 'Sam Jones', address: '[email protected]'} | ||
] | ||
, fizz_arr: [ | ||
{ | ||
buzz_inga: "buzz" | ||
, bang: { | ||
bell_hop: "bell" | ||
} | ||
} | ||
, { | ||
bil_bo: "baggins" | ||
, alias: { | ||
mis_ter: "underhill" | ||
} | ||
} | ||
] | ||
, good_name: null | ||
}; | ||
|
||
var out = toApiFormat(testObj); | ||
|
||
expect(out).to.deep.equal(validationObj); | ||
|
||
done(); | ||
}); | ||
|
||
it('should throw an error if it encounters one', function(done) { | ||
var stub = sinon.stub(_, 'snakeCase').throws(); | ||
|
||
var testObj = { | ||
simpleString: "foo" | ||
, substitution_data: { | ||
key1: 'value1', | ||
key_2: 'value_2' | ||
} | ||
, sampleArray: [ | ||
'oneTag', | ||
'two_tag', | ||
'substitution_data', | ||
'tags' | ||
] | ||
}; | ||
|
||
try { | ||
var out = toApiFormat(testObj); | ||
} catch(e) { | ||
expect(e).to.not.be.null; | ||
} | ||
|
||
stub.restore(); | ||
done(); | ||
}); | ||
|
||
it('should ignore sub-properties of properties on exclude list', function(done) { | ||
var testObj = { | ||
simpleString: "foo" | ||
, substitution_data: { | ||
key1: 'value1', | ||
key_2: 'value_2' | ||
} | ||
, sampleArray: [ | ||
{ | ||
goodValue: 'hello', | ||
tags: [ | ||
'oneTag', | ||
'two_tag', | ||
'substitution_data', | ||
'tags' | ||
] | ||
} | ||
] | ||
}; | ||
|
||
var validationObj = { | ||
simple_string: "foo" | ||
, substitution_data: { | ||
key1: 'value1', | ||
key_2: 'value_2' | ||
} | ||
, sample_array: [ | ||
{ | ||
good_value: 'hello', | ||
tags: [ | ||
'oneTag', | ||
'two_tag', | ||
'substitution_data', | ||
'tags' | ||
] | ||
} | ||
] | ||
}; | ||
|
||
var out = toApiFormat(testObj); | ||
|
||
expect(out).to.deep.equal(validationObj); | ||
|
||
done(); | ||
}); | ||
}); |