cheddargetter
Advanced tools
Comparing version 0.0.4 to 0.1.1
@@ -42,3 +42,11 @@ var https = require("https"); | ||
var xml = new xml2js.Parser(); | ||
xml.parseString(data, callback); | ||
xml.parseString(data, function (err, xml) { | ||
var type = Object.keys(xml)[0]; | ||
if (type == "#") { | ||
callback(new Error(xml["#"])); | ||
} else { | ||
callback(null, xml[type]); | ||
} | ||
}); | ||
}); | ||
@@ -45,0 +53,0 @@ }); |
{ | ||
"name": "cheddargetter", | ||
"version": "0.0.4", | ||
"version": "0.1.1", | ||
"author": "Kevin Smith", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -28,8 +28,8 @@ var fs = require("fs"); | ||
}, function (result, cb) { | ||
test.equal(typeof(result.plan),"object", "getAllPricingPlans should return a plan array"); | ||
test.ok(result.plan.length > 0, "There should be more than 0 plans"); | ||
test.equal(typeof(result),"object", "getAllPricingPlans should return a plan array"); | ||
test.ok(result.length > 0, "There should be more than 0 plans"); | ||
cg.getPricingPlan(result.plan[0]["@"].code, cb); | ||
cg.getPricingPlan(result[0]["@"].code, cb); | ||
}, function (result, cb) { | ||
test.equal(typeof(result.plan), "object", "getPricingPlan should return a plan object"); | ||
test.equal(typeof(result), "object", "getPricingPlan should return a plan object"); | ||
@@ -43,2 +43,12 @@ cb(); | ||
module.exports.PlanError = function (test) { | ||
var cg = new CheddarGetter(config.user, config.pass, config.productCode); | ||
cg.getPricingPlan("Bad Plan Code", function (err, customer) { | ||
test.notEqual(err, null); | ||
test.equal(customer, null); | ||
test.done(); | ||
}); | ||
}; | ||
module.exports.Customers = function (test) { | ||
@@ -64,10 +74,28 @@ var cg = new CheddarGetter(config.user, config.pass, config.productCode); | ||
}, function (result, cb) { | ||
cg.createCustomer({ | ||
code: "test1", | ||
firstName: "FName2", | ||
lastName: "LName2", | ||
email: "test2@test.com", | ||
subscription: { | ||
planCode: config.planCode, | ||
method: "cc", | ||
ccNumber: "4111111111111111", | ||
ccExpiration: "12/2012", | ||
ccCardCode: "123", | ||
ccFirstName: "FName2", | ||
ccLastName:"LName2", | ||
ccZip: "95123" | ||
} | ||
}, cb); | ||
}, function (result, cb) { | ||
cg.getAllCustomers(cb); | ||
}, function (result, cb) { | ||
test.equal(typeof(result.customer), "object", "getAllCustomers should return a customer array"); | ||
test.equal(typeof(result), "object", "getAllCustomers should return a customer array"); | ||
test.equal(result.length, 2, "getAllCustomers should return 2 customers"); | ||
test.equal(result[0]["@"].code, "test", "first customer should be 'test'"); | ||
cg.getCustomer(result.customer["@"].code || result.customer[0]["@"].code, cb); | ||
cg.getCustomer("test", cb); | ||
}, function (result, cb) { | ||
test.equal(typeof(result.customer), "object", "getCustomer should return a customer object"); | ||
//cg.deleteCustomer("test", cb); | ||
test.equal(typeof(result), "object", "getCustomer should return a customer object"); | ||
cb(); | ||
@@ -80,2 +108,12 @@ }], function (err) { | ||
module.exports.CustomerError = function (test) { | ||
var cg = new CheddarGetter(config.user, config.pass, config.productCode); | ||
cg.getCustomer("Bad Customer Code", function (err, customer) { | ||
test.notEqual(err, null); | ||
test.equal(customer, null); | ||
test.done(); | ||
}); | ||
}; | ||
module.exports.Items = function (test) { | ||
@@ -89,3 +127,3 @@ var cg = new CheddarGetter(config.user, config.pass, config.productCode); | ||
}, function (result, cb) { | ||
test.equal(parseInt(result.customer.subscriptions.subscription.items.item[0].quantity, 10), 5); | ||
test.equal(parseInt(result.subscriptions.subscription.items.item[0].quantity, 10), 5); | ||
cb(null, {}); | ||
@@ -97,3 +135,3 @@ }, function (result, cb) { | ||
}, function (result, cb) { | ||
test.equal(parseInt(result.customer.subscriptions.subscription.items.item[0].quantity, 10), 5 + 2); | ||
test.equal(parseInt(result.subscriptions.subscription.items.item[0].quantity, 10), 5 + 2); | ||
cb(null, {}); | ||
@@ -105,3 +143,3 @@ }, function (result, cb) { | ||
}, function (result, cb) { | ||
test.equal(parseInt(result.customer.subscriptions.subscription.items.item[0].quantity, 10), 5 + 2 + 1); | ||
test.equal(parseInt(result.subscriptions.subscription.items.item[0].quantity, 10), 5 + 2 + 1); | ||
cb(null, {}); | ||
@@ -113,3 +151,3 @@ }, function (result, cb) { | ||
}, function (result, cb) { | ||
test.equal(parseInt(result.customer.subscriptions.subscription.items.item[0].quantity, 10), 5 + 2 + 1 - 2); | ||
test.equal(parseInt(result.subscriptions.subscription.items.item[0].quantity, 10), 5 + 2 + 1 - 2); | ||
cb(null, {}); | ||
@@ -121,6 +159,8 @@ }, function (result, cb) { | ||
}, function (result, cb) { | ||
test.equal(parseInt(result.customer.subscriptions.subscription.items.item[0].quantity, 10), 5 + 2 + 1 - 2 - 1); | ||
test.equal(parseInt(result.subscriptions.subscription.items.item[0].quantity, 10), 5 + 2 + 1 - 2 - 1); | ||
cb(null, {}); | ||
}, function (result, cb) { | ||
cg.deleteCustomer("test", cb); | ||
}, function (result, cb) { | ||
cg.deleteCustomer("test1", cb); | ||
}], function (err) { | ||
@@ -127,0 +167,0 @@ test.ifError(err); |
259
10850
7