diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2012-05-04 16:57:31 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2012-05-04 16:57:31 +0200 |
commit | 3a7e65ca638bfcd615dcd24d4ee800596621be8b (patch) | |
tree | 76121f6812dbe0ae4867477828c570e330f561de /node_modules/collection_json/test | |
parent | a55635dd4da622a82a091b13c533388e0d8a28cb (diff) | |
download | bitraf-bot-3a7e65ca638bfcd615dcd24d4ee800596621be8b.tar.gz bitraf-bot-3a7e65ca638bfcd615dcd24d4ee800596621be8b.tar.bz2 bitraf-bot-3a7e65ca638bfcd615dcd24d4ee800596621be8b.tar.xz bitraf-bot-3a7e65ca638bfcd615dcd24d4ee800596621be8b.zip |
o Adding a small module to process application/vnd.collection+json documents.
Diffstat (limited to 'node_modules/collection_json/test')
-rw-r--r-- | node_modules/collection_json/test/collection_json.test.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/node_modules/collection_json/test/collection_json.test.js b/node_modules/collection_json/test/collection_json.test.js new file mode 100644 index 0000000..b74d99b --- /dev/null +++ b/node_modules/collection_json/test/collection_json.test.js @@ -0,0 +1,39 @@ +var assert = require('assert') + , collection_json = require('../'); + +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" }, + ] + } + ] +}}; + +describe('fromObject', function() { + it('Has basic fields', function() { + var collection = collection_json.fromObject({}); + assert.deepEqual([], collection.items); + assert.deepEqual([], collection.links); + assert.deepEqual([], collection.queries); + assert.deepEqual([], collection.templates); + }); + + it('Can map data field in items', function() { + assert.deepEqual(collection_json.fromObject(collection1).mapItemData(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]); + }); +}); |