Skip to content

Instantly share code, notes, and snippets.

@nherment
Created April 23, 2012 17:25
Show Gist options
  • Save nherment/2472488 to your computer and use it in GitHub Desktop.
Save nherment/2472488 to your computer and use it in GitHub Desktop.
mn-mock
/** ******************************************************* **/
/** * Imports & Utils * **/
/** ******************************************************* **/
var mncore = require("mn-core");
var ConfigManager = mncore.ConfigManager;
var confMgr = new ConfigManager();
var authParams = {
username: confMgr.getConfig("app.username"),
password: confMgr.getConfig("app.password")
};
function getMnCore(callback) {
return new mncore.CMnAuthCore(authParams, function(err, result) {
if(err) {
throw err;
}
callback()
});
}
/** ******************************************************* **/
/** * Node definitions * **/
/** ******************************************************* **/
// Root node
var CN1 = {
_def: "CatalogNode",
name: "catalog node 1 ("+now+")"
};
// child of root with no attributes
var CN2 = {
_def: "CatalogNode",
name: "catalog node 2 ("+now+")",
parents: [
{
_def: "parents",
ref: {
_def: "CatalogNode",
_id: 0
}
}
]
};
// child of root with 1 attribute
var CN3 = {
_def: "CatalogNode",
name: "catalog node 3 ("+now+")",
parents: [
{
_def: "parents",
ref: {
_def: "CatalogNode",
_id: 0
}
}
],
attributes: [
{
_def: "CatalogAttribute",
inherited: false,
type: "double",
name: "price("+now+")",
doubleValue: 12
}
]
};
// child of CN3 with 1 attribute
var CN4 = {
_def: "CatalogNode",
name: "catalog node 4 ("+now+")",
parents: [
{
_def: "parents",
ref: {
_def: "CatalogNode",
_id: 0
}
}
],
attributes: [
{
_def: "CatalogAttribute",
inherited: false,
type: "double",
name: "CN4.attr1("+now+")",
doubleValue: 12
},
{
_def: "CatalogAttribute",
inherited: false,
type: "string",
name: "CN4.attr2("+now+")",
stringValue: "foobar"
}
]
};
// child of CN4 and CN2 with 1 attribute
var CN5 = {
_def: "CatalogNode",
name: "catalog node 5 ("+now+")",
parents: [
{
_def: "parents",
ref: {
_def: "CatalogNode",
_id: 0
}
},
{
_def: "parents",
ref: {
_def: "CatalogNode",
_id: 0
}
}
],
attributes: [
{
_def: "CatalogAttribute",
inherited: false,
type: "double",
name: "CN5.attr1("+now+")",
doubleValue: 12
},
{
_def: "CatalogAttribute",
inherited: false,
type: "string",
name: "CN5.attr2("+now+")",
stringValue: "foobar"
}
]
};
mncore = getMnCore(function() {
console.info("Saving CN1");
mncore.save(CN1, function(err, CN1Saved) {
if(err) { throw err; }
CN1 = CN1Saved;
CN2.parents[0].ref._id = CN1._id;
console.info("Saving CN2");
mncore.save(CN2, function(err, CN2Saved) {
if(err) { throw err; }
CN2 = CN2Saved;
CN3.parents[0].ref._id = CN1._id;
console.info("Saving CN3");
mncore.save(CN3, function(err, CN3Saved) {
if(err) { throw err; }
CN3 = CN3Saved;
CN4.parents[0].ref._id = CN3._id;
console.info("Saving CN4");
mncore.save(CN4, function(err, CN4Saved) {
if(err) { throw err; }
CN4 = CN4Saved;
CN5.parents[0].ref._id = CN4._id;
CN5.parents[1].ref._id = CN2._id;
console.info("Saving CN5");
mncore.save(CN5, function(err, CN5Saved) {
if(err) { throw err; }
CN5 = CN5Saved;
done();
});
});
});
});
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment