summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-07-14 00:41:25 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2012-07-14 00:41:25 +0200
commit3f310615b388d428c68bbf3b773505c868e90db6 (patch)
tree4d41a94836d5aaf5c4c93b293092a1501a28ab36 /test
parent63214f5e9e69c640701e6d92dc4a9bee9ec91cba (diff)
downloadcollection_json.js-3f310615b388d428c68bbf3b773505c868e90db6.tar.gz
collection_json.js-3f310615b388d428c68bbf3b773505c868e90db6.tar.bz2
collection_json.js-3f310615b388d428c68bbf3b773505c868e90db6.tar.xz
collection_json.js-3f310615b388d428c68bbf3b773505c868e90db6.zip
o More tests.
Diffstat (limited to 'test')
-rw-r--r--test/collection_json.test.js36
1 files changed, 35 insertions, 1 deletions
diff --git a/test/collection_json.test.js b/test/collection_json.test.js
index 0cd003e..e1c4297 100644
--- a/test/collection_json.test.js
+++ b/test/collection_json.test.js
@@ -22,8 +22,17 @@ function collection1() {
}});
}
+function template1() {
+ return collection_json.fromObject({template: {
+ data: [
+ { name: 'field-1', value: 'value-1', zap: 'zoot' },
+ { name: 'field-2' }
+ ]
+ }});
+}
+
describe('fromObject', function() {
- it('Has basic fields', function() {
+ it('Has basic fields on a collection', function() {
var collection = collection_json.fromObject({}).collection;
assert.deepEqual(collection.items, []);
assert.deepEqual(collection.links, []);
@@ -31,6 +40,15 @@ describe('fromObject', function() {
assert.equal(collection.template, undefined);
});
+ // Assert what a template object should look like
+ it('Has basic fields on a template', function() {
+ var template = collection_json.fromObject({template: {}}).template;
+ assert.equal(template.items, undefined);
+ assert.equal(template.links, undefined);
+ assert.equal(template.queries, undefined);
+ assert.equal(typeof template.data, 'object');
+ });
+
it('Can map data field in items', function() {
assert.deepEqual(collection1().mapItems(identity),
[{"field-1": "1", "field-2": "2"}
@@ -38,6 +56,22 @@ describe('fromObject', function() {
function f(map) { return parseInt(map["field-1"]) + parseInt(map["field-2"]); }
assert.deepEqual(collection1().mapItems(f), [3, 7]);
});
+ /*
+ */
+
+ it('Knows the difference between silly objects, collections and templates', function() {
+ var silly = collection_json.fromObject({});
+ var collection = collection_json.fromObject(collection1());
+ var template = collection_json.fromObject(template1());
+
+ assert.equal(template.isCollection(), false);
+ assert.equal(template.isTemplate(), true);
+
+ assert.equal(silly.isCollection(), true);
+ assert.equal(silly.isTemplate(), false);
+ assert.equal(collection.isCollection(), true);
+ assert.equal(collection.isTemplate(), false);
+ });
});
describe('collection object', function() {