diff --git a/lib/db/json.js b/lib/db/json.js index 3dace705a623342685f9ea58195da9a55856241e..4af6a54536730b1eb8d1291dcdd9b64b1af0e6f3 100644 --- a/lib/db/json.js +++ b/lib/db/json.js @@ -130,7 +130,7 @@ exports.emailKnown = function(email, cb) { exports.emailType = function(email, cb) { sync(); var m = jsel.match(".emails ." + ESC(email), db.users); - process.nextTick(function() { cb(m.length ? m.type : undefined); }); + process.nextTick(function() { cb(m.length ? m[0].type : undefined); }); }; exports.isStaged = function(email, cb) { diff --git a/lib/db/mysql.js b/lib/db/mysql.js index ac93d50f4ecb5743164e1d65c6408b9c36844eb0..7c46cd64b795aa25a9e442ccc2f6c4a7adf0065d 100644 --- a/lib/db/mysql.js +++ b/lib/db/mysql.js @@ -239,7 +239,7 @@ exports.emailType = function(email, cb) { "SELECT type FROM email WHERE address = ?", [ email ], function(err, rows) { if (err) logUnexpectedError(err); - cb((rows && rows.length > 0) ? rows[0].type : null); + cb((rows && rows.length > 0) ? rows[0].type : undefined); } ); } @@ -368,7 +368,6 @@ exports.createUserWithPrimaryEmail = function(email, cb) { client.query( "INSERT INTO user() VALUES()", function(err, info) { - console.log(info.insertId); if (err) { logUnexpectedError(err); cb(err); return; } client.query( "INSERT INTO email(user, address, type) VALUES(?, ?, ?)", diff --git a/tests/db-test.js b/tests/db-test.js index 3fdba7a344b6b1bf1a15bbed3322c5aa18cc7ff5..f917c67b7622ded99c930948f712956eae033194 100755 --- a/tests/db-test.js +++ b/tests/db-test.js @@ -245,6 +245,34 @@ suite.addBatch({ } }); + +suite.addBatch({ + "emailType of lloyd@anywhe.re": { + topic: function() { + db.emailType('lloyd@anywhe.re', this.callback); + }, + "is null": function (r) { + assert.isUndefined(r); + } + }, + "emailType of lloyd@somewhe.re": { + topic: function() { + db.emailType('lloyd@somewhe.re', this.callback); + }, + "is 'secondary'": function (r) { + assert.strictEqual(r, 'secondary'); + } + }, + "emailType of lloyd@nowhe.re": { + topic: function() { + db.emailType('lloyd@nowhe.re', this.callback); + }, + "is 'secondary'": function (r) { + assert.strictEqual(r, 'secondary'); + } + } +}); + suite.addBatch({ "removing an existing email": { topic: function() { @@ -283,6 +311,33 @@ suite.addBatch({ } }); +suite.addBatch({ + "creating a primary account": { + topic: function() { + db.createUserWithPrimaryEmail("lloyd@primary.domain", this.callback); + }, + "returns no error": function(r) { + assert.isUndefined(r); + }, + "causes emailKnown": { + topic: function() { + db.emailKnown('lloyd@primary.domain', this.callback); + }, + "to return true": function (r) { + assert.strictEqual(r, true); + } + }, + "causes emailType": { + topic: function() { + db.emailType('lloyd@primary.domain', this.callback); + }, + "to return 'primary'": function (r) { + assert.strictEqual(r, 'primary'); + } + } + } +}); + suite.addBatch({ "closing the database": { topic: function() {