summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-07-13 23:32:20 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2012-07-13 23:32:20 +0200
commit63214f5e9e69c640701e6d92dc4a9bee9ec91cba (patch)
tree4a430481e5c2c3019fcdc8896554da23173e735a /test
parent4f4ef10a6bbbcc68ab89d81291faddf57b650928 (diff)
downloadcollection_json.js-63214f5e9e69c640701e6d92dc4a9bee9ec91cba.tar.gz
collection_json.js-63214f5e9e69c640701e6d92dc4a9bee9ec91cba.tar.bz2
collection_json.js-63214f5e9e69c640701e6d92dc4a9bee9ec91cba.tar.xz
collection_json.js-63214f5e9e69c640701e6d92dc4a9bee9ec91cba.zip
o Adding toObject on each item.
Diffstat (limited to 'test')
-rw-r--r--test/collection_json.test.js55
1 files changed, 33 insertions, 22 deletions
diff --git a/test/collection_json.test.js b/test/collection_json.test.js
index 24f69e4..0cd003e 100644
--- a/test/collection_json.test.js
+++ b/test/collection_json.test.js
@@ -3,37 +3,48 @@ var assert = require('assert')
function identity(x) { return x; }
-var collection1 = {collection: {
- items: [
- { href: "http://example.com/1", links: [],
- data: [
- { prompt: "prompt1", name: "field-1", value: "1", baz: "woot" },
- { prompt: "prompt2", name: "field-2", value: "2", foz: "asdf" },
- ]
- },
- { href: "http://example.com/2", links: [],
- data: [
- { prompt: "prompt1", name: "field-1", value: "3" },
- { prompt: "prompt2", name: "field-2", value: "4" },
- ]
- }
- ]
-}};
+function collection1() {
+ return collection_json.fromObject({collection: {
+ items: [
+ { href: "http://example.com/1", links: [],
+ data: [
+ { prompt: "prompt1", name: "field-1", value: "1", baz: "woot" },
+ { prompt: "prompt2", name: "field-2", value: "2", foz: "asdf" },
+ ]
+ },
+ { href: "http://example.com/2", links: [],
+ data: [
+ { prompt: "prompt1", name: "field-1", value: "3" },
+ { prompt: "prompt2", name: "field-2", value: "4" },
+ ]
+ }
+ ]
+ }});
+}
describe('fromObject', function() {
it('Has basic fields', function() {
var collection = collection_json.fromObject({}).collection;
- assert.deepEqual([], collection.items);
- assert.deepEqual([], collection.links);
- assert.deepEqual([], collection.queries);
- assert.deepEqual([], collection.templates);
+ assert.deepEqual(collection.items, []);
+ assert.deepEqual(collection.links, []);
+ assert.deepEqual(collection.queries, []);
+ assert.equal(collection.template, undefined);
});
it('Can map data field in items', function() {
- assert.deepEqual(collection_json.fromObject(collection1).mapItemData(identity),
+ assert.deepEqual(collection1().mapItems(identity),
[{"field-1": "1", "field-2": "2"}
,{"field-1": "3", "field-2": "4"}]);
function f(map) { return parseInt(map["field-1"]) + parseInt(map["field-2"]); }
- assert.deepEqual(collection_json.fromObject(collection1).mapItemData(f), [3, 7]);
+ assert.deepEqual(collection1().mapItems(f), [3, 7]);
+ });
+});
+
+describe('collection object', function() {
+ it('Can create objects from items', function() {
+ assert.deepEqual(collection1().collection.items[0].toObject(), {
+ "field-1": "1",
+ "field-2": "2"
+ });
});
});