Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
209 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Get-Process *node* | Stop-Process | ||
Get-Process *phant* | stop-process |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,87 @@ | ||
var assert = require("assert"); | ||
var expect = require("expect.js"); | ||
|
||
var setup = require("../test/setup"); | ||
var config = require("../server/config"); | ||
var login = require("../test/login.js"); | ||
|
||
var waitUntil = require("../test/waitUntil.js"); | ||
|
||
var username = "SomeUsername"; | ||
var password = "SomePassword"; | ||
|
||
var context = setup.usingPhantomPage(setup.whenRunningTheServer(exports)); | ||
|
||
|
||
function doLoginFromPage(page, url) { | ||
|
||
return page.promise.open(url) | ||
.then(function() { | ||
console.log("1"); | ||
return page.promise.clickElement(login.selectors.loginButton, true); | ||
}) | ||
.then(function() { | ||
return waitUntil("login page loads", function() { | ||
return page.promise.evaluate(function(selectors) { | ||
return document.querySelector(selectors.loginUsername) !== null; | ||
}, login.selectors); | ||
}); | ||
}) | ||
.then(function() { | ||
console.log("2"); | ||
return page.promise.evaluate(function(selectors, u,p) { | ||
|
||
document.querySelector(selectors.loginUsername).value = u; | ||
document.querySelector(selectors.loginPassword).value = p; | ||
}, login.selectors, username, password); | ||
}) | ||
.then(function() { | ||
console.log("3"); | ||
return page.promise.clickElement(login.selectors.loginLocalSubmit); | ||
}); | ||
} | ||
|
||
setup.qtest(context, "should show user message for invalid username/password", function() { | ||
|
||
var page = this.page; | ||
|
||
return doLoginFromPage(page, config.urlFor("/")) | ||
.then(function() { | ||
return waitUntil("login completes", function() { | ||
return page.promise.evaluate(function() { | ||
return document.querySelector('span.info') !== null; | ||
}); | ||
}); | ||
}) | ||
.then(function() { | ||
return page.promise.evaluate(function() { | ||
return document.querySelector('span.info').textContent; | ||
}); | ||
}) | ||
.then(function(textContent) { | ||
expect(textContent).to.contain('Incorrect username or password'); | ||
}); | ||
}); | ||
|
||
function check_login_from(startPage) { | ||
|
||
setup.qtest(context, "can log in with local account from " + startPage, function() { | ||
|
||
var page = this.page; | ||
|
||
return page.promise.open(startPage) | ||
.then(function() { | ||
console.log("1"); | ||
return page.promise.clickElement(login.selectors.loginButton, true); | ||
}) | ||
.then(function() { | ||
console.log("2"); | ||
return page.promise.evaluate(function(selectors, u,p) { | ||
|
||
document.querySelector(selectors.loginUsername).value = u; | ||
document.querySelector(selectors.loginPassword).value = p; | ||
}, login.selectors, username, password); | ||
}) | ||
.then(function() { | ||
console.log("3"); | ||
return page.promise.clickElement(login.selectors.loginLocalSubmit); | ||
}) | ||
.then(function() { | ||
console.log("4"); | ||
return page.promise.evaluate(function() { | ||
return window.location.toString(); | ||
}); | ||
}) | ||
.then(function(location) { | ||
console.log("5"); | ||
assert.equal(location, startPage); | ||
return doLoginFromPage(page, startPage) | ||
.then(function() { | ||
console.log("4"); | ||
return page.promise.evaluate(function() { | ||
return window.location.toString(); | ||
}); | ||
}) | ||
.then(function(location) { | ||
console.log("5"); | ||
assert.equal(location, startPage); | ||
}); | ||
}); | ||
} | ||
|
||
/* | ||
check_login_from(config.urlFor("/feeds")); | ||
check_login_from(config.urlFor("/status")); | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
var Q = require("q"); | ||
|
||
var database = require('../database.js'); | ||
|
||
|
||
exports.findOrCreateUserByGoogleIdentifier = function(identifier, profile, callback) { | ||
|
||
var connection = database.getConnection(); | ||
|
||
var query = Q.nbind(connection.query, connection); | ||
|
||
query("SELECT users.id, users.friendlyName FROM users JOIN googleProfiles ON googleProfiles.userId = users.id WHERE googleProfiles.id = ?", identifier) | ||
.then(function(result) { | ||
|
||
if (result[0].length > 0) { | ||
var firstResult = result[0][0]; | ||
|
||
callback(null, { | ||
id: firstResult.id, | ||
friendlyName: firstResult.friendlyName | ||
}); | ||
} else { | ||
return query("INSERT INTO users SET ?", { | ||
friendlyName: profile.displayName | ||
}) | ||
.then(function(result) { | ||
|
||
var userId = result[0].insertId; | ||
|
||
return query("INSERT INTO googleProfiles SET ?", { | ||
id: identifier, | ||
userId: userId, | ||
profile: JSON.stringify(profile) | ||
}) | ||
.then(function() { | ||
callback(null, { | ||
id: userId, | ||
friendlyName: profile.displayName | ||
}); | ||
}); | ||
}); | ||
} | ||
}) | ||
.fin(function() { | ||
connection.end(); | ||
}) | ||
.fail(function(err) { | ||
callback(err); | ||
}); | ||
}; | ||
|
||
|
84 changes: 42 additions & 42 deletions
84
src/server/database.test.js → src/server/data/users.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,42 @@ | ||
var Q = require("q"); | ||
var uuid = require('node-uuid'); | ||
var expect = require("expect.js"); | ||
var assert = require("assert"); | ||
|
||
var setup = require("../test/setup"); | ||
var database = require("./database"); | ||
|
||
var findOrCreateUserByGoogleIdentifier = Q.nbind(database.findOrCreateUserByGoogleIdentifier); | ||
|
||
setup.qtest(exports, "findOrCreateUserByGoogleIdentifier can save and load users", function() { | ||
|
||
var firstGoogleIdentifier = uuid.v4(); | ||
var firstGoogleProfile = setup.getGoogleProfile("First"); | ||
|
||
var secondGoogleIdentifier = uuid.v4(); | ||
var secondGoogleProfile = setup.getGoogleProfile("Second"); | ||
|
||
// Load the first user | ||
return findOrCreateUserByGoogleIdentifier(firstGoogleIdentifier, firstGoogleProfile) | ||
.then(function(firstUser) { | ||
expect(firstUser.id).to.be.a('number'); | ||
expect(firstUser.friendlyName).to.equal("displayNameFirst"); | ||
|
||
// Load the second user | ||
return findOrCreateUserByGoogleIdentifier(secondGoogleIdentifier, secondGoogleProfile) | ||
.then(function(secondUser) { | ||
expect(secondUser.id).to.be.a('number'); | ||
expect(secondUser.id).not.to.equal(firstUser.id); | ||
expect(secondUser.friendlyName).to.equal("displayNameSecond"); | ||
}) | ||
.then(function() { | ||
|
||
// Reload the first user | ||
return findOrCreateUserByGoogleIdentifier(firstGoogleIdentifier, firstGoogleProfile) | ||
.then(function(reloadedUser) { | ||
expect(reloadedUser.id).to.equal(firstUser.id); | ||
expect(reloadedUser.friendlyName).to.equal("displayNameFirst"); | ||
}); | ||
}); | ||
}); | ||
}); | ||
var Q = require("q"); | ||
var uuid = require('node-uuid'); | ||
var expect = require("expect.js"); | ||
var assert = require("assert"); | ||
|
||
var setup = require("../../test/setup.js"); | ||
var users = require("./users.js"); | ||
|
||
var findOrCreateUserByGoogleIdentifier = Q.nbind(users.findOrCreateUserByGoogleIdentifier); | ||
|
||
setup.qtest(exports, "findOrCreateUserByGoogleIdentifier can save and load users", function() { | ||
|
||
var firstGoogleIdentifier = uuid.v4(); | ||
var firstGoogleProfile = setup.getGoogleProfile("First"); | ||
|
||
var secondGoogleIdentifier = uuid.v4(); | ||
var secondGoogleProfile = setup.getGoogleProfile("Second"); | ||
|
||
// Load the first user | ||
return findOrCreateUserByGoogleIdentifier(firstGoogleIdentifier, firstGoogleProfile) | ||
.then(function(firstUser) { | ||
expect(firstUser.id).to.be.a('number'); | ||
expect(firstUser.friendlyName).to.equal("displayNameFirst"); | ||
|
||
// Load the second user | ||
return findOrCreateUserByGoogleIdentifier(secondGoogleIdentifier, secondGoogleProfile) | ||
.then(function(secondUser) { | ||
expect(secondUser.id).to.be.a('number'); | ||
expect(secondUser.id).not.to.equal(firstUser.id); | ||
expect(secondUser.friendlyName).to.equal("displayNameSecond"); | ||
}) | ||
.then(function() { | ||
|
||
// Reload the first user | ||
return findOrCreateUserByGoogleIdentifier(firstGoogleIdentifier, firstGoogleProfile) | ||
.then(function(reloadedUser) { | ||
expect(reloadedUser.id).to.equal(firstUser.id); | ||
expect(reloadedUser.friendlyName).to.equal("displayNameFirst"); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters