Jump To …

user.js

test/
var request = require('supertest')
, assert = require("assert")
, mysql = require("mysql")
, clientPool = require("../lib/mysql").clientPool
, should = require("should")
, request = request('http://localhost:3000');

var Cookies ;
describe("user",function() {

before(function(done) { clientPool.acquire(function(err,mysql) { mysql.query("DELETE FROM user WHERE email = 'zan09@hampshire.edu' LIMIT 1 ;",function(err,result) { clientPool.releaseConnection(mysql); done(); }); }); });

  describe("signup",function() {
    it("should only accept hampshire emails",function(done) {
      request.post("/user/new")
      .send({
        name:"bob",
        pronoun:"asdf",
        email:"bob@gmail.com",
        points:500,
        div:4,
        age:33,
        subFree:1,
        password:"foo"
      })
      .expect(400,done);
    });
    it("should have the correct fields",function(done) {
      request.post('/user/new')
      .send({foo:"bar"})
      .expect(400,done);
    });
    it("should create a new user with a good request",function(done) {
      request.post("/user/new")
      .send({
        name:"bob",
        pronoun:"asdf",
        email:"zan09@hampshire.edu",
        points:500,
        div:4,
        age:33,
        subFree:1,
        password:"foo"
      })
      .expect(302,done);
    });

it("should have the new user in the database",function() { clientPool.acquire(function(err,mysql) {

    mysql.query("SELECT * FROM `user` WHERE `email` = 'zan09@hampshire.edu' LIMIT 1 ;",function(err,result) {
        if(err){
            return false;
        }
        clientPool.releaseConnection(mysql);
        result.length.should.equal(1);
    });
});

});

  });

  describe("login",function() {
    it("should return error without username or password",function(done) {
      request
        .post("/login")
        .send({foo:"bar"})
        .set("Accept","application/json")
        .expect(400,done);
    });

    it("should recognize a bad user",function(done) {
      request.post("/login")
      .send({email:"asdf",password:"dfdfdf"})
      .expect(401,done);
    });

    it("should recognize a real user with a bad pass",function(done) {
      request.post("/login")
      .send({email:'zan09@hampshire.edu',password:"blob"})
      .expect(401,done);
    });

    it("should recognize a real user with good password",function(done) {
      request.post("/login")
      .send({email:'zan09@hampshire.edu',password:"foo"})
      .expect(301)
      .end(function(err,res) {
        Cookies = res.headers['set-cookie'].pop().split(';')[0];
        done();
      });
    });
  });

  describe("view",function() {
    it("should still have the cookie and render /me",function(done) {
      var req = request.get("/user/me");
      req.cookies = Cookies;
      req.set('Accept', 'test/html')
      .expect(200,done);
    });

    it("should have a 404 for a bad id",function(done) {
      var req = request.get("/user/fuckyou");
      req.cookies = Cookies;
      req.set('Accept', 'test/html')
      .expect(404,done);
    });


  });

  describe("search",function() {
    it("should be able to make a search",function(done) {
      var req = request.get("/user/search/yas");
      req.cookies = Cookies;
      req.set("Accept","text/json")
      .expect(200,done);
    });
    it("should ignore searches with no query",function(done) {
      var req = request.get("/user/search/");
      req.cookies = Cookies;

      req.expect(400,done);
    });
  });

  describe("uploadPic",function() {
    it("should get a 400 if pic is not provided",function(done) {
      var req = request.post("/user/uploadPic");
      req.cookies = Cookies;

      req.send({foo:"abr"}).expect(400,done);
    });
    it("should return 200 if you provide a pic",function(done) {
      var req = request.post("/user/uploadPic");
      req.cookies = Cookies;

      req.send({pic:"abr"}).expect(200,done);
    });
  });

still need edit update index logout

});

describe("questionResponse",function() {
  describe("create",function() {
    it("should reject bad requests");
    it("should give 200 with the proper fields");
  });
  describe("delete",function() {
    it("should reject if there's no questionResponseID, 400");
    it("should return 200 with proper field");
    it("should return 404 not found if there are no record matching the ID for the user");
  });
});

generated Tue Apr 30 2013 17:31:04 GMT-0400 (EDT)
Modfinder