Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[fix] Make tests use id (public api)

  • Loading branch information...
commit a3b8260ace7072e450acb0b7826b2201e433803b 1 parent 3639fae
@pksunkara pksunkara authored Marak committed
Showing with 58 additions and 72 deletions.
  1. +33 −41 test/engines-test.js
  2. +25 −31 test/relationship-test.js
View
74 test/engines-test.js
@@ -37,9 +37,9 @@ engines.forEach(function (e) {
assert.isNull(err);
assert.isArray(obj);
assert.equal(obj.length, 3);
- assert.equal(obj[0].key, 'bob');
- assert.equal(obj[1].key, 'mat');
- assert.equal(obj[2].key, 'tim');
+ assert.equal(obj[0].id, 'bob');
+ assert.equal(obj[1].id, 'mat');
+ assert.equal(obj[2].id, 'tim');
}
}
}
@@ -61,7 +61,7 @@ engines.forEach(function (e) {
},
"should respond with the right object": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'bob');
+ assert.equal(obj.id, 'bob');
assert.equal(obj.age, 35);
assert.equal(obj.hair, 'black');
assert.equal(obj.resource, 'Author');
@@ -89,15 +89,13 @@ engines.forEach(function (e) {
},
"a Resource.create() request": {
topic: function () {
- var o = {age: 30, hair: 'red'};
- o[resources[e].Author.key] = 'han';
- resources[e].Author.create(o, this.callback);
+ resources[e].Author.create({id: 'han', age: 30, hair: 'red'}, this.callback);
},
"should return the newly created object": function (err, obj) {
assert.isNull(err);
assert.strictEqual(obj.constructor, resources[e].Author);
assert.instanceOf(obj, resources[e].Author);
- assert.equal(obj.key, 'han');
+ assert.equal(obj.id, 'han');
assert.equal(obj.age, 30);
assert.equal(obj.hair, 'red');
assert.equal(obj.resource, 'Author');
@@ -118,7 +116,7 @@ engines.forEach(function (e) {
},
"should respond with the right object": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'han');
+ assert.equal(obj.id, 'han');
assert.equal(obj.age, 30);
assert.equal(obj.hair, 'red');
assert.equal(obj.resource, 'Author');
@@ -137,15 +135,13 @@ engines.forEach(function (e) {
},
"a diffirent Resource.create() request with the same id": {
topic: function () {
- var o = {};
- o[resources[e].Creature.key] = 'han';
- resources[e].Creature.create(o, this.callback);
+ resources[e].Creature.create({id: 'han'}, this.callback);
},
"should return the newly created object": function (err, obj) {
assert.isNull(err);
assert.strictEqual(obj.constructor, resources[e].Creature);
assert.instanceOf(obj, resources[e].Creature);
- assert.equal(obj.key, 'han');
+ assert.equal(obj.id, 'han');
assert.equal(obj.resource, 'Creature');
},
"should not be a new record": function (err, obj) {
@@ -164,7 +160,7 @@ engines.forEach(function (e) {
},
"should respond with the right object": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'han');
+ assert.equal(obj.id, 'han');
assert.equal(obj.resource, 'Creature');
},
"should not be a new record": function (err, obj) {
@@ -200,9 +196,7 @@ engines.forEach(function (e) {
}).addBatch({
"Instantiating a new instance": {
topic: function () {
- var o = {age: 30, hair: 'red'};
- o[resources[e].Author.key] = 'han';
- return resources[e].Author.new(o);
+ return resources[e].Author.new({id: 'han', age: 30, hair: 'red'});
},
"should be a new record": function (obj) {
assert.isTrue(obj.isNewRecord);
@@ -220,9 +214,7 @@ engines.forEach(function (e) {
}).addBatch({
"Instantiating a new instance": {
topic: function () {
- var o = {age: 30, hair: 'red'};
- o[resources[e].Author.key] = 'han';
- return resources[e].Author.new(o);
+ return resources[e].Author.new({id: 'han', age: 30, hair: 'red'});
},
"should be a new record": function (obj) {
assert.isTrue(obj.isNewRecord);
@@ -239,7 +231,7 @@ engines.forEach(function (e) {
},
"should respond with the right object": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'han');
+ assert.equal(obj.id, 'han');
assert.equal(obj.age, 30);
assert.equal(obj.hair, 'red');
assert.equal(obj.resource, 'Author');
@@ -260,7 +252,7 @@ engines.forEach(function (e) {
},
"should respond with the right object": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'han');
+ assert.equal(obj.id, 'han');
assert.equal(obj.age, 30);
assert.equal(obj.hair, 'red');
assert.equal(obj.resource, 'Author');
@@ -291,11 +283,11 @@ engines.forEach(function (e) {
assert.isArray(obj);
assert.instanceOf(obj[0], resourceful.Resource);
assert.instanceOf(obj[1], resourceful.Resource);
- assert.equal(obj[0].key, 'bob');
+ assert.equal(obj[0].id, 'bob');
assert.equal(obj[0].age, 35);
assert.equal(obj[0].hair, 'black');
assert.equal(obj[0].resource, 'Author');
- assert.equal(obj[1].key, 'mat');
+ assert.equal(obj[1].id, 'mat');
assert.equal(obj[1].age, 29);
assert.equal(obj[1].hair, 'black');
assert.equal(obj[1].resource, 'Author');
@@ -325,7 +317,7 @@ engines.forEach(function (e) {
},
"it should have 'bob' object": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'bob');
+ assert.equal(obj.id, 'bob');
assert.equal(obj.age, 35);
assert.equal(obj.hair, 'black');
assert.equal(obj.resource, 'Author');
@@ -346,7 +338,7 @@ engines.forEach(function (e) {
},
"should respond with the right object": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'bob');
+ assert.equal(obj.id, 'bob');
assert.equal(obj.age, 31);
assert.equal(obj.hair, 'black');
assert.equal(obj.resource, 'Author');
@@ -367,7 +359,7 @@ engines.forEach(function (e) {
},
"should respond with the right object": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'bob');
+ assert.equal(obj.id, 'bob');
assert.equal(obj.age, 31);
assert.equal(obj.hair, 'black');
assert.equal(obj.resource, 'Author');
@@ -386,7 +378,7 @@ engines.forEach(function (e) {
},
"it should have 'bob' object": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'bob');
+ assert.equal(obj.id, 'bob');
assert.equal(obj.age, 31);
assert.equal(obj.hair, 'black');
assert.equal(obj.resource, 'Author');
@@ -408,7 +400,7 @@ engines.forEach(function (e) {
},
"should respond with the right object": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'bob');
+ assert.equal(obj.id, 'bob');
assert.equal(obj.age, 35);
assert.equal(obj.hair, 'black');
assert.equal(obj.resource, 'Author');
@@ -429,7 +421,7 @@ engines.forEach(function (e) {
},
"should respond with the right object": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'bob');
+ assert.equal(obj.id, 'bob');
assert.equal(obj.age, 35);
assert.equal(obj.hair, 'black');
assert.equal(obj.resource, 'Author');
@@ -448,7 +440,7 @@ engines.forEach(function (e) {
},
"it should have 'bob' object": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'bob');
+ assert.equal(obj.id, 'bob');
assert.equal(obj.age, 35);
assert.equal(obj.hair, 'black');
assert.equal(obj.resource, 'Author');
@@ -471,7 +463,7 @@ engines.forEach(function (e) {
},
"should respond with the right object": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'bob');
+ assert.equal(obj.id, 'bob');
assert.equal(obj.age, 31);
assert.equal(obj.hair, 'red');
assert.equal(obj.resource, 'Author');
@@ -492,7 +484,7 @@ engines.forEach(function (e) {
},
"should respond with the right object": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'bob');
+ assert.equal(obj.id, 'bob');
assert.equal(obj.age, 31);
assert.equal(obj.hair, 'red');
assert.equal(obj.resource, 'Author');
@@ -511,7 +503,7 @@ engines.forEach(function (e) {
},
"it should have 'bob' object": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'bob');
+ assert.equal(obj.id, 'bob');
assert.equal(obj.age, 31);
assert.equal(obj.hair, 'red');
assert.equal(obj.resource, 'Author');
@@ -532,7 +524,7 @@ engines.forEach(function (e) {
},
"should respond with the right object": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'bob');
+ assert.equal(obj.id, 'bob');
assert.equal(obj.age, 35);
assert.equal(obj.hair, 'black');
assert.equal(obj.resource, 'Author');
@@ -553,7 +545,7 @@ engines.forEach(function (e) {
},
"should respond with the right object": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'bob');
+ assert.equal(obj.id, 'bob');
assert.equal(obj.age, 35);
assert.equal(obj.hair, 'black');
assert.equal(obj.resource, 'Author');
@@ -604,7 +596,7 @@ engines.forEach(function (e) {
},
"should respond with the right object": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'bob');
+ assert.equal(obj.id, 'bob');
assert.equal(obj.age, 35);
assert.equal(obj.hair, 'black');
assert.equal(obj.resource, 'Author');
@@ -622,7 +614,7 @@ engines.forEach(function (e) {
},
"should be successful": function (err, obj) {
assert.isNull(err);
- assert.notEqual(obj.key, undefined);
+ assert.notEqual(obj.id, undefined);
assert.equal(obj.age, 51);
assert.equal(obj.hair, 'white');
assert.equal(obj.resource, 'Author');
@@ -641,9 +633,9 @@ function multipleGet(e) {
"should be successful": function (err, obj) {
assert.isNull(err);
assert.equal(obj.length, 3);
- assert.equal(obj[0].key, 'bob');
- assert.equal(obj[1], null);
- assert.equal(obj[2].key, 'tim');
+ assert.equal(obj[0].id, 'bob');
+ assert.equal(obj[1] || null, null);
+ assert.equal(obj[2].id, 'tim');
}
}
};
View
56 test/relationship-test.js
@@ -35,7 +35,7 @@ engines.forEach(function (e) {
},
"should be successful": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'pavan');
+ assert.equal(obj.id, 'pavan');
assert.equal(obj.name, 'pavan');
assert.equal(obj.resource, 'User');
},
@@ -56,9 +56,9 @@ engines.forEach(function (e) {
"should return them": function (err, obj) {
assert.isNull(err);
assert.lengthOf(obj, 2);
- assert.equal(obj[0].key, 'user/pavan/bullet');
+ assert.equal(obj[0].id, 'user/pavan/bullet');
assert.equal(obj[0].name, 'bullet');
- assert.equal(obj[1].key, 'user/pavan/octonode');
+ assert.equal(obj[1].id, 'user/pavan/octonode');
assert.equal(obj[1].name, 'octonode');
},
"should be of proper resource type": function (err, obj) {
@@ -79,9 +79,9 @@ engines.forEach(function (e) {
"should return them": function (err, obj) {
assert.isNull(err);
assert.lengthOf(obj, 2);
- assert.equal(obj[0].key, 'user/pavan/bullet');
+ assert.equal(obj[0].id, 'user/pavan/bullet');
assert.equal(obj[0].name, 'bullet');
- assert.equal(obj[1].key, 'user/pavan/octonode');
+ assert.equal(obj[1].id, 'user/pavan/octonode');
assert.equal(obj[1].name, 'octonode');
},
"should be of proper resource type": function (err, obj) {
@@ -110,7 +110,7 @@ engines.forEach(function (e) {
},
"should be successful": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'christian');
+ assert.equal(obj.id, 'christian');
assert.equal(obj.name, 'christian');
assert.equal(obj.resource, 'User');
assert.lengthOf(obj.repository_ids, 2);
@@ -118,13 +118,11 @@ engines.forEach(function (e) {
"and when 'Parent.prototype.createChild()' is used": {
"successfully": {
topic: function (obj) {
- var o = {name: 'issues'};
- o[resources[e].Repository.key] = 'issues';
- obj.createRepository(o, this.callback);
+ obj.createRepository({id: 'issues', name: 'issues'}, this.callback);
},
"should return the newly created object": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'user/christian/issues');
+ assert.equal(obj.id, 'user/christian/issues');
assert.equal(obj.name, 'issues');
assert.equal(obj.resource, 'Repository');
},
@@ -138,7 +136,7 @@ engines.forEach(function (e) {
},
"should be successful": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'christian');
+ assert.equal(obj.id, 'christian');
assert.equal(obj.name, 'christian');
assert.equal(obj.resource, 'User');
},
@@ -154,7 +152,7 @@ engines.forEach(function (e) {
},
"should respond with the right object": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'user/christian/issues');
+ assert.equal(obj.id, 'user/christian/issues');
assert.equal(obj.name, 'issues');
assert.equal(obj.user_id, 'christian');
}
@@ -174,7 +172,7 @@ engines.forEach(function (e) {
},
"should be successful": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'marak');
+ assert.equal(obj.id, 'marak');
assert.equal(obj.name, 'marak');
assert.equal(obj.resource, 'User');
assert.lengthOf(obj.repository_ids, 2);
@@ -183,13 +181,11 @@ engines.forEach(function (e) {
"and when 'Parent.createChild()' is used": {
"successfully": {
topic: function (obj) {
- var o = {name: 'haibu'};
- o[resources[e].User.key] = 'haibu';
- resources[e].User.createRepository('marak', o, this.callback);
+ resources[e].User.createRepository('marak', {id: 'haibu', name: 'haibu'}, this.callback);
},
"should return the newly created object": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'user/marak/haibu');
+ assert.equal(obj.id, 'user/marak/haibu');
assert.equal(obj.name, 'haibu');
assert.equal(obj.resource, 'Repository');
},
@@ -203,7 +199,7 @@ engines.forEach(function (e) {
},
"should be successful": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'marak');
+ assert.equal(obj.id, 'marak');
assert.equal(obj.name, 'marak');
assert.equal(obj.resource, 'User');
},
@@ -219,7 +215,7 @@ engines.forEach(function (e) {
},
"should respond with the right object": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'user/marak/haibu');
+ assert.equal(obj.id, 'user/marak/haibu');
assert.equal(obj.name, 'haibu');
assert.equal(obj.user_id, 'marak');
}
@@ -239,7 +235,7 @@ engines.forEach(function (e) {
},
"should be successful": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'user/pavan/bullet');
+ assert.equal(obj.id, 'user/pavan/bullet');
assert.equal(obj.name, 'bullet');
assert.equal(obj.resource, 'Repository');
},
@@ -253,7 +249,7 @@ engines.forEach(function (e) {
},
"should return the parent": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'pavan');
+ assert.equal(obj.id, 'pavan');
assert.equal(obj.name, 'pavan');
},
"should be of proper resource type": function (err, obj) {
@@ -278,7 +274,7 @@ engines.forEach(function (e) {
},
"should be successful": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'pavan');
+ assert.equal(obj.id, 'pavan');
assert.equal(obj.name, 'pavan');
assert.equal(obj.resource, 'User');
},
@@ -292,9 +288,9 @@ engines.forEach(function (e) {
},
"should return the children": function (err, obj) {
assert.isNull(err);
- assert.equal(obj[0].key, 'user/pavan/bullet');
+ assert.equal(obj[0].id, 'user/pavan/bullet');
assert.equal(obj[0].name, 'bullet');
- assert.equal(obj[1].key, 'user/pavan/octonode');
+ assert.equal(obj[1].id, 'user/pavan/octonode');
assert.equal(obj[1].name, 'octonode');
},
"should be of proper resource type": function (err, obj) {
@@ -321,7 +317,7 @@ engines.forEach(function (e) {
},
"should be successful": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'user/christian/issues');
+ assert.equal(obj.id, 'user/christian/issues');
assert.equal(obj.name, 'issues');
assert.equal(obj.resource, 'Repository');
},
@@ -335,7 +331,7 @@ engines.forEach(function (e) {
},
"should be successful": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'christian');
+ assert.equal(obj.id, 'christian');
assert.equal(obj.name, 'christian');
assert.equal(obj.resource, 'User');
assert.include(obj.repository_ids, 'issues');
@@ -372,7 +368,7 @@ engines.forEach(function (e) {
},
"should be successful": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'christian');
+ assert.equal(obj.id, 'christian');
assert.equal(obj.name, 'christian');
assert.equal(obj.resource, 'User');
assert.lengthOf(obj.repository_ids, 2);
@@ -496,13 +492,11 @@ engines.forEach(function (e) {
},
"when Parent.prototype.createChild() is called": {
topic: function (p) {
- var o = {name: 'haibu'};
- o[resources[e].Forum.key] = 'haibu';
- p.createForum(o, this.callback);
+ p.createForum({id: 'haibu', name: 'haibu'}, this.callback);
},
"should be successful": function (err, obj) {
assert.isNull(err);
- assert.equal(obj.key, 'forum/forum/develop/nodejitsu/haibu');
+ assert.equal(obj.id, 'forum/forum/develop/nodejitsu/haibu');
assert.equal(obj.name, 'haibu');
assert.equal(obj.resource, 'Forum');
assert.equal(obj.forum_id, 'forum/develop/nodejitsu');
Please sign in to comment.
Something went wrong with that request. Please try again.