Permalink
Browse files

Added tests for password module.

  • Loading branch information...
1 parent 0b1bda6 commit 8dc9c41a227a479339c5e2224cc7d48d076f12a7 @bnoguchi committed Jul 1, 2011
Showing with 92 additions and 4 deletions.
  1. +8 −0 README.md
  2. +1 −1 example/server.js
  3. +1 −1 example/views/login.jade
  4. +1 −1 example/views/register.jade
  5. +2 −1 package.json
  6. +1 −0 test/app.js
  7. +78 −0 test/password.test.js
View
8 README.md
@@ -100,6 +100,14 @@ associated with 'local.host'. So inside your /etc/hosts file, one of the lines w
Then point your browser to [http://local.host:3000](http://local.host:3000)
+## Tests
+
+First, spin up the example server (See last section "Example Application").
+
+Then,
+
+ $ make test
+
## Logging Out
If you integrate `everyauth` with `connect`, then `everyauth` automatically
View
2 example/server.js
@@ -36,7 +36,7 @@ var usersByReadabilityId = {};
var usersByBoxId = {};
var usersByOpenId = {};
var usersByLogin = {
- 'brian': addUser({ login: 'brian', password: 'password'})
+ 'brian@example.com': addUser({ login: 'brian@example.com', password: 'password'})
};
everyauth.everymodule
View
2 example/views/login.jade
@@ -2,7 +2,7 @@
ul#errors
- each error in errors
li.error= error
-form(action='/login', method='POST')
+form(action='/login', method='post')
#login
label(for=everyauth.password.loginFormFieldName) Login
input(type='text', name=everyauth.password.loginFormFieldName, value=email)
View
2 example/views/register.jade
@@ -3,7 +3,7 @@ h2 Register
ul#errors
- each error in errors
li.error= error
-form(action='/register', method='POST')
+form(action='/register', method='post')
#login
label(for=everyauth.password.loginFormFieldName) Login
input(type='text', name=everyauth.password.loginFormFieldName, value=userParams[everyauth.password.loginFormFieldName])
View
3 package.json
@@ -22,7 +22,8 @@
},
"devDependencies": {
"express": ">=2.3.10",
- "jade": ">=0.12.1"
+ "jade": ">=0.12.1",
+ "tobi": ">=0.2.2"
},
"engines": {
"node": ">=0.4.x"
View
1 test/app.js
View
78 test/password.test.js
@@ -0,0 +1,78 @@
+var tobi = require('tobi')
+ , should = require('should')
+ , browser = tobi.createBrowser(3000, 'local.host');
+
+// Test a successful registration
+browser.get('/register', function (res, $) {
+ $('form')
+ .fill({ email: 'newuser@example.com', password: 'pass' })
+ .submit( function (res, $) {
+ res.should.have.status(200);
+ $('h2').should.have.text('Authenticated');
+ $('h2').should.not.have.text('Not Authenticated');
+ });
+});
+
+// Test failed registrations
+browser.get('/register', function (res, $) {
+ $('form')
+ .fill({ email: '', password: '' })
+ .submit( function (res, $) {
+ res.should.have.status(200);
+ $('#errors li:first').should.have.text('Missing email');
+ $('#errors li:eq(1)').should.have.text('Missing password');
+ });
+ $('form')
+ .fill({ email: 'newuser', password: 'pass' })
+ .submit( function (res, $) {
+ res.should.have.status(200);
+ $('#errors').should.have.text('Please correct your email.');
+ });
+ $('form')
+ .fill({ email: 'newuser', password: '' })
+ .submit( function (res, $) {
+ res.should.have.status(200);
+ $('#errors li:first').should.have.text('Please correct your email.');
+ $('#errors li:eq(1)').should.have.text('Missing password');
+ });
+ $('form')
+ .fill({ email: 'abc@example.com', password: '' })
+ .submit( function (res, $) {
+ res.should.have.status(200);
+ $('#errors').should.have.text('Missing password');
+ });
+
+ // TODO Add case of person trying to take an existing login
+});
+
+// Test a successful login
+browser.get('/login', function (res, $) {
+ $('form')
+ .fill({ email: 'brian@example.com', password: 'password' })
+ .submit( function (res, $) {
+ res.should.have.status(200);
+ $('h2').should.have.text('Authenticated');
+ $('h2').should.not.have.text('Not Authenticated');
+ });
+});
+
+// Test failed logins
+browser.get('/login', function (res, $) {
+ $('form')
+ .fill({ email: 'brian@example.com', password: 'wrongpassword' })
+ .submit( function (res, $) {
+ res.should.have.status(200);
+ $('#errors').should.have.text('Login failed');
+ });
+ $('form')
+ .fill({ email: 'brian@example.com', password: '' })
+ .submit( function (res, $) {
+ $('#errors').should.have.text('Missing password');
+ });
+ $('form')
+ .fill({ email: '', password: '' })
+ .submit( function (res, $) {
+ $('#errors li:first').should.have.text('Missing login');
+ $('#errors li:eq(1)').should.have.text('Missing password');
+ });
+});

0 comments on commit 8dc9c41

Please sign in to comment.