Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
tests w/ zombie, expect, mocha in coffeescript: you will need npm i -g zombie npm i -g mocha, gl
mongoose = require "mongoose"
paginate = require('paginate')({
mongoose: mongoose
});
mongoose.set "debug", true
# connection sharing thanks to [connection-sharing mongoose examples](https://github.com/LearnBoost/mongoose/tree/master/examples/express/connection-sharing)
db = global.db = mongoose.createConnection(conf.db.mongoUrl);
db.on "error", console.error.bind console, "connection error:"
(function() {
var conf, db, mongoose, paginate;
mongoose = require("mongoose");
conf = require("../../../conf");
paginate = require('paginate')({
mongoose: mongoose
});
if (conf.debug.mongo === true) {
mongoose.set("debug", true);
}
db = global.db = mongoose.createConnection(conf.db.mongoUrl);
db.on("error", console.error.bind(console, "connection error:"));
}).call(this);
Browser = require "zombie"
assert = require "assert"
c = require "colors"
db = require "../app/models/db"
App = require "../app/models/applications"
browser = new Browser debug: false, loadCSS: true, runScripts: true
browser.site = "http://localhost:3001"
s =
login:
username: "admin"
pass: process.env.NODE_PASS
create:
username: "test-user"
password: process.env.NODE_PASS
email: "test@null.nodejitsu.com"
first_name: "Sample"
last_name: "Test"
zip: "90210"
phone: "9092879899"
app:
title: "Test Application title 324"
store: "12345"
slug: "test-application-title-324"
describe "test login", () ->
it "should login as admin", (done) ->
browser.visit "/login", () ->
browser
.fill("[name=username]", s.login.username)
.fill("[name=password]", s.login.pass)
.pressButton "#login", ->
return done() if browser.success == true
describe "add and remove test app", () ->
it "should add the test app", (done) ->
browser.visit "/apps/add", () ->
browser
.fill("#appTitle", s.app.title)
.fill("#AppStoreId", s.app.store)
.fill("#appSlug", s.app.slug)
.pressButton "#appSave", ->
return done() if browser.success == true
it "should remove the app we added", (done) ->
browser.visit "/apps/#{s.app.slug}/remove", ->
return done() if browser.success == true
describe "add and remove user", () ->
it "should add a user", (done) ->
browser.visit "/users/add", () ->
browser
.fill("[name=username]", s.create.username)
.fill("[name=password]", s.create.password)
.fill("[name=email]", s.create.email)
.fill("[name=first_name]", s.create.first_name)
.fill("[name=last_name]", s.create.last_name)
.fill("[name=zip]", s.create.zip)
.fill("[name=phone]", s.create.phone)
.check("[name=is_admin]")
.pressButton "#signupUser", ->
return done() if browser.success == true
it "should log out so we can test this new user", (done) ->
browser.visit "/logout", () ->
return done() if browser.success == true
describe "update and edit #{s.create.username}", () ->
it "should log into the new account we've created", (done) ->
browser.visit "/login", () ->
browser
.fill("[name=username]", s.create.username)
.fill("[name=password]", s.create.password)
.pressButton "#login", ->
return done() if browser.success == true
it "should edit itself", (done) ->
browser.visit "/users/#{s.create.username}/edit", () ->
browser
.fill("[name=first_name]", s.create.first_name + "-editing")
.fill("[name=last_name]", s.create.last_name + "-editing")
.fill("[name=zip]", s.create.zip + "-000")
.fill("[name=phone]", s.create.phone + "-000")
.check("[name=is_editor]")
.pressButton "#signupUser", ->
return done() if browser.success == true
it "should log out of #{s.create.username}", (done) ->
browser.visit "/logout", () ->
return done() if browser.success == true
describe "should login to admin account and remove #{s.create.username}", () ->
it "should login as admin", (done) ->
browser.visit "/login", () ->
browser
.fill("[name=username]", s.login.username)
.fill("[name=password]", s.login.pass)
.pressButton "#login", ->
return done() if browser.success == true
it "should delete #{s.create.username}", (done) ->
browser.visit "/users/#{s.create.username}/remove", () ->
return done() if browser.success == true
describe "logout when we're done", () ->
it "should log out", (done) ->
browser.visit "/logout", () ->
return done() if browser.success == true
(function() {
var App, Browser, assert, browser, c, conf, db, expect, s;
Browser = require("zombie");
assert = require("assert");
expect = require("expect.js");
c = require("colors");
conf = require("../helpers/config");
db = require("../app/models/db");
App = require("../app/models/applications");
browser = new Browser({
debug: false,
loadCSS: true,
runScripts: true
});
browser.site = conf.app.host;
s = {
login: {
username: "admin",
pass: process.env.NODE_PASS
},
create: {
username: "test-user",
password: process.env.NODE_PASS,
email: "test@null.nodejitsu.com",
first_name: "Sample",
last_name: "Test",
zip: "90210",
phone: "9092879899"
},
app: {
title: "Test Application title 324",
store: "12345",
slug: "test-application-title-324"
}
};
describe("test login", function() {
return it("should login as admin", function(done) {
return browser.visit("/login", function() {
return browser.fill("[name=username]", s.login.username).fill("[name=password]", s.login.pass).pressButton("#login", function() {
if (browser.success === true) {
return done();
}
});
});
});
});
describe("add and remove test app", function() {
it("should add the test app", function(done) {
return browser.visit("/apps/add", function() {
return browser.fill("#appTitle", s.app.title).fill("#AppStoreId", s.app.store).fill("#appSlug", s.app.slug).pressButton("#appSave", function() {
if (browser.success === true) {
return done();
}
});
});
});
return it("should remove the app we added", function(done) {
return browser.visit("/apps/" + s.app.slug + "/remove", function() {
if (browser.success === true) {
return done();
}
});
});
});
describe("add and remove user", function() {
it("should add a user", function(done) {
return browser.visit("/users/add", function() {
return browser.fill("[name=username]", s.create.username).fill("[name=password]", s.create.password).fill("[name=email]", s.create.email).fill("[name=first_name]", s.create.first_name).fill("[name=last_name]", s.create.last_name).fill("[name=zip]", s.create.zip).fill("[name=phone]", s.create.phone).check("[name=is_admin]").pressButton("#signupUser", function() {
if (browser.success === true) {
return done();
}
});
});
});
return it("should log out so we can test this new user", function(done) {
return browser.visit("/logout", function() {
if (browser.success === true) {
return done();
}
});
});
});
describe("update and edit " + s.create.username, function() {
it("should log into the new account we've created", function(done) {
return browser.visit("/login", function() {
return browser.fill("[name=username]", s.create.username).fill("[name=password]", s.create.password).pressButton("#login", function() {
if (browser.success === true) {
return done();
}
});
});
});
it("should edit itself", function(done) {
return browser.visit("/users/" + s.create.username + "/edit", function() {
return browser.fill("[name=first_name]", s.create.first_name + "-editing").fill("[name=last_name]", s.create.last_name + "-editing").fill("[name=zip]", s.create.zip + "-000").fill("[name=phone]", s.create.phone + "-000").check("[name=is_editor]").pressButton("#signupUser", function() {
if (browser.success === true) {
return done();
}
});
});
});
return it("should log out of " + s.create.username, function(done) {
return browser.visit("/logout", function() {
if (browser.success === true) {
return done();
}
});
});
});
describe("should login to admin account and remove " + s.create.username, function() {
it("should login as admin", function(done) {
return browser.visit("/login", function() {
return browser.fill("[name=username]", s.login.username).fill("[name=password]", s.login.pass).pressButton("#login", function() {
if (browser.success === true) {
return done();
}
});
});
});
return it("should delete " + s.create.username, function(done) {
return browser.visit("/users/" + s.create.username + "/remove", function() {
if (browser.success === true) {
return done();
}
});
});
});
describe("logout when we're done", function() {
return it("should log out", function(done) {
return browser.visit("/logout", function() {
if (browser.success === true) {
return done();
}
});
});
});
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment