* Fixes #1417

* Cleanup

* Perf improvement

* Hoist constant array

* Improve tests
This commit is contained in:
Drew
2016-04-08 16:06:52 -07:00
committed by Florent Vilmart
parent b433fb9b4e
commit 281568edd2
2 changed files with 49 additions and 15 deletions

View File

@@ -1,6 +1,8 @@
// These tests are unit tests designed to only test transform.js.
"use strict";
var transform = require('../src/transform');
let transform = require('../src/transform');
let dd = require('deep-diff');
var dummySchema = {
data: {},
@@ -150,14 +152,30 @@ describe('untransformObject', () => {
done();
});
it('nested array', (done) => {
var input = {arr: [{_testKey: 'testValue' }]};
var output = transform.untransformObject(dummySchema, null, input);
expect(Array.isArray(output.arr)).toEqual(true);
expect(output.arr).toEqual([{ _testKey: 'testValue'}]);
done();
});
it('nested array', (done) => {
var input = {arr: [{_testKey: 'testValue' }]};
var output = transform.untransformObject(dummySchema, null, input);
expect(Array.isArray(output.arr)).toEqual(true);
expect(output.arr).toEqual([{ _testKey: 'testValue'}]);
done();
});
it('untransforms objects containing nested special keys', done => {
let input = {array: [{
_id: "Test ID",
_hashed_password: "I Don't know why you would name a key this, but if you do it should work",
_tombstone: {
_updated_at: "I'm sure people will nest keys like this",
_acl: 7,
_id: { someString: "str", someNumber: 7},
regularKey: { moreContents: [1, 2, 3] },
},
regularKey: "some data",
}]}
let output = transform.untransformObject(dummySchema, null, input);
expect(dd(output, input)).toEqual(undefined);
done();
});
});
describe('transformKey', () => {