summaryrefslogtreecommitdiff
path: root/test/collection_json.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/collection_json.test.js')
-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() {