Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
695 lines (629 sloc) 16.1 KB

TOC

# express ## index page should respond with home page.
reqOptions.path = '/';
			var req = http.request(reqOptions, function (res) {
				// debugger;
				res.statusCode.should.equal(200);
				done();
			});
			req.on('error', function(err) {
				done(err);
			});
			req.end();
## admin page should redirect to login page.
reqOptions.path = '/admin';
			var req = http.request(reqOptions, function (res) {
				// debugger;
				var location = url.parse(res.headers.location, true, true);
				res.statusCode.should.equal(302);
				location.pathname.should.equal('/login');
				done();
			});
			req.on('error', function(err) {
				done(err);
			});
			req.end();
## login page should remember entered values.
var req = http.request(reqOptions, function (res) {
				// debugger;
				res.on('data', function (chunk) {
					// debugger;
					// chunk is Buffer
					var html = chunk.toString('utf8');
					html.match(/<input.*name="username" value="user".*>/gi)
					.should.be.ok;
					html.match(/<input.*name="password" value="asd".*>/gi)
					.should.be.ok;
					done();
				});
			});
			req.on('error', function(err) {
				done(err);
			});
			req.write('username=user&password=asd', 'utf8');
			req.end();

should return validation error on non valid username.

var req = http.request(reqOptions, function (res) {
				// debugger;
				res.on('data', function (chunk) {
					// debugger;
					// chunk is Buffer
					var html = chunk.toString('utf8');
					html.indexOf('Validation Error!').should.not.equal(-1);
					done();
				});
			});
			req.on('error', function(err) {
				done(err);
			});
			req.write('username=&password=pass1', 'utf8');
			req.end();

should return validation error on non valid password.

var req = http.request(reqOptions, function (res) {
				// debugger;
				res.on('data', function (chunk) {
					// debugger;
					// chunk is Buffer
					var html = chunk.toString('utf8');
					html.indexOf('Validation Error!').should.not.equal(-1);
					done();
				});
			});
			req.on('error', function(err) {
				done(err);
			});
			req.write('username=admin1&password=', 'utf8');
			req.end();

should return authentication error on wrong username.

var req = http.request(reqOptions, function (res) {
				// debugger;
				res.on('data', function (chunk) {
					// debugger;
					// chunk is Buffer
					var html = chunk.toString('utf8');
					html.indexOf('Authentication Error!').should.not.equal(-1);
					done();
				});
			});
			req.on('error', function(err) {
				done(err);
			});
			req.write('username=liolio&password=pass1', 'utf8');
			req.end();

should return authentication error on wrong password.

var req = http.request(reqOptions, function (res) {
				// debugger;
				res.on('data', function (chunk) {
					// debugger;
					// chunk is Buffer
					var html = chunk.toString('utf8');
					html.indexOf('Authentication Error!').should.not.equal(-1);
					done();
				});
			});
			req.on('error', function(err) {
				done(err);
			});
			req.write('username=admin1&password=blq', 'utf8');
			req.end();

should redirect to admin page on right credentials.

var req = http.request(reqOptions, function (res) {
				// debugger;
				var location = url.parse(res.headers.location, true, true);
				res.statusCode.should.equal(302);
				location.pathname.should.equal('/admin');
				cookie = res.headers['set-cookie'][0];
				done();
			});
			req.on('error', function(err) {
				done(err);
			});
			req.write('username=admin1&password=pass1', 'utf8');
			req.end();
## admin should be logged in.
reqOptions.path = '/admin';
			reqOptions.method = 'GET';
			reqOptions.headers = {
				cookie: cookie
			}
			var req = http.request(reqOptions, function (res) {
				// debugger;
				res.statusCode.should.equal(200);
				done();
			});
			req.on('error', function(err) {
				done(err);
			});
			req.end();
### member page should remember entered values.
var req = http.request(reqOptions, function (res) {
					// debugger;
					res.on('data', function (chunk) {
						// debugger;
						// chunk is Buffer
						var html = chunk.toString('utf8');
						html.match(/<input.*name="membername" value="EAST".*>/gi)
						.should.be.ok;
						done();
					});
				});
				req.on('error', function(err) {
					done(err);
				});
				req.write('membername=EAST', 'utf8');
				req.end();

should return validation error on non valid member name.

var req = http.request(reqOptions, function (res) {
					// debugger;
					res.on('data', function (chunk) {
						// debugger;
						// chunk is Buffer
						var html = chunk.toString('utf8');
						html.indexOf('Validation Error!').should.not.equal(-1);
						done();
					});
				});
				req.on('error', function(err) {
					done(err);
				});
				req.write('membername=', 'utf8');
				req.end();

should return database error on duplicate member name.

var req = http.request(reqOptions, function (res) {
					// debugger;
					res.on('data', function (chunk) {
						// debugger;
						// chunk is Buffer
						var html = chunk.toString('utf8');
						html.indexOf('Database Error!').should.not.equal(-1);
						done();
					});
				});
				req.on('error', function(err) {
					done(err);
				});
				req.write('membername=EAST', 'utf8');
				req.end();

should insert new member into database.

var req = http.request(reqOptions, function (res) {
					// debugger;
					res.on('data', function (chunk) {
						// debugger;
						// chunk is Buffer
						var html = chunk.toString('utf8');
						html.indexOf('Database Success!').should.not.equal(-1);
						done();
					});
				});
				req.on('error', function(err) {
					done(err);
				});
				req.write('membername=Peshooo', 'utf8');
				req.end();
### expense page should remember entered values.
var req = http.request(reqOptions, function (res) {
					// debugger;
					res.on('data', function (chunk) {
						// debugger;
						// chunk is Buffer
						var html = chunk.toString('utf8');
						html.match(/<input.*name="expensename" value="Бира".*>/gi)
						.should.be.ok;
						done();
					});
				});
				req.on('error', function(err) {
					done(err);
				});
				req.write('expensename=Бира', 'utf8');
				req.end();

should return validation error on non valid expense name.

var req = http.request(reqOptions, function (res) {
					// debugger;
					res.on('data', function (chunk) {
						// debugger;
						// chunk is Buffer
						var html = chunk.toString('utf8');
						html.indexOf('Validation Error!').should.not.equal(-1);
						done();
					});
				});
				req.on('error', function(err) {
					done(err);
				});
				req.write('expensename=', 'utf8');
				req.end();

should return database error on duplicate expense name.

var req = http.request(reqOptions, function (res) {
					// debugger;
					res.on('data', function (chunk) {
						// debugger;
						// chunk is Buffer
						var html = chunk.toString('utf8');
						html.indexOf('Database Error!').should.not.equal(-1);
						done();
					});
				});
				req.on('error', function(err) {
					done(err);
				});
				req.write('expensename=Бира', 'utf8');
				req.end();

should insert new expense into database.

var req = http.request(reqOptions, function (res) {
					// debugger;
					res.on('data', function (chunk) {
						// debugger;
						// chunk is Buffer
						var html = chunk.toString('utf8');
						html.indexOf('Database Success!').should.not.equal(-1);
						done();
					});
				});
				req.on('error', function(err) {
					done(err);
				});
				req.write('expensename=Бирааа', 'utf8');
				req.end();
### income page should get all members.
reqOptions.method = 'GET';
				reqOptions.headers = {
					cookie: cookie,
				};
				var req = http.request(reqOptions, function (res) {
					// debugger;
					res.statusCode.should.equal(200);
					res.on('data', function (chunk) {
						// chunk is Buffer
						var html = chunk.toString('utf8');
						html.match(/<option value=/gi).length.should.not.equal(1);
						done();
					});
				});
				req.on('error', function (err) {
					done(err);
				});
				req.end();

should remember entered values.

var req = http.request(reqOptions, function (res) {
					res.on('data', function (chunk) {
						// chunk is Buffer
						var html = chunk.toString('utf8');
						html.match(/<option value="22" selected="selected">/gi)
						.should.be.ok;
						html.match(/<input.*name="cache" value="".*>/gi)
						.should.be.ok;
						html.match(/<input.*name="date" value="2012-05-07".*>/gi)
						.should.be.ok;
						done();
					});
				});
				req.on('error', function(err) {
					done(err);
				});
				req.write('member=22&cache=&date=2012-05-07', 'utf8');
				req.end();

should insert new income into database.

var req = http.request(reqOptions, function (res) {
					// debugger;
					res.on('data', function (chunk) {
						// debugger;
						// chunk is Buffer
						var html = chunk.toString('utf8');
						html.indexOf('Database Success!').should.not.equal(-1);
						done();
					});
				});
				req.on('error', function(err) {
					done(err);
				});
				req.write('member=22&cache=200&date=2020-01-01', 'utf8');
				req.end();
#### should return validation error on not chosen member name.
var req = http.request(reqOptions, function (res) {
						// debugger;
						res.on('data', function (chunk) {
							// chunk is Buffer
							var html = chunk.toString('utf8');
							html.match(
								/<.*name="member".*data-error="Validation Error!".*>/gi)
								.should.be.ok;
							done();
						});
					});
					req.on('error', function (err) {
						done(err);
					});
					req.write('member=-1', 'utf8');
					req.end();

on non valid cache value.

var req = http.request(reqOptions, function (res) {
						// debugger;
						res.on('data', function (chunk) {
							// chunk is Buffer
							var html = chunk.toString('utf8');
							html.match(/<.*name="cache".*data-error="Validation Error!".*>/gi)
								.should.be.ok;
							done();
						});
					});
					req.on('error', function(err) {
						done(err);
					});
					req.write('cache=', 'utf8');
					req.end();

on non valid date value.

var req = http.request(reqOptions, function (res) {
						// debugger;
						res.on('data', function (chunk) {
							// chunk is Buffer
							var html = chunk.toString('utf8');
							html.match(/<.*name="date".*data-error="Validation Error!".*>/gi)
								.should.be.ok;
							done();
						});
					});
					req.on('error', function(err) {
						done(err);
					});
					req.write('date=', 'utf8');
					req.end();
### spend page should get all expenses.
reqOptions.method = 'GET';
				reqOptions.headers = {
					cookie: cookie
				};
				var req = http.request(reqOptions, function (res) {
					// debugger;
					res.statusCode.should.equal(200);
					res.on('data', function (chunk) {
						// chunk is Buffer
						var html = chunk.toString('utf8');
						html.match(/<option value=/gi).length.should.not.equal(1);
						done();
					});
				});
				req.on('error', function (err) {
					done(err);
				});
				req.end();

should remember entered values.

var req = http.request(reqOptions, function (res) {
					res.on('data', function (chunk) {
						// chunk is Buffer
						var html = chunk.toString('utf8');
						html.match(/<option value="18" selected="selected">/gi)
						.should.be.ok;
						html.match(/<input.*name="cache" value="".*>/gi)
						.should.be.ok;
						html.match(/<input.*name="date" value="2012-05-07".*>/gi)
						.should.be.ok;
						done();
					});
				});
				req.on('error', function(err) {
					done(err);
				});
				req.write('expense=18&cache=&date=2012-05-07', 'utf8');
				req.end();

should insert new spend into database.

var req = http.request(reqOptions, function (res) {
					// debugger;
					res.on('data', function (chunk) {
						// debugger;
						// chunk is Buffer
						var html = chunk.toString('utf8');
						html.indexOf('Database Success!').should.not.equal(-1);
						done();
					});
				});
				req.on('error', function(err) {
					done(err);
				});
				req.write('expense=18&cache=100&date=2020-01-01', 'utf8');
				req.end();
#### should return validation error on not chosen expense name.
var req = http.request(reqOptions, function (res) {
						// debugger;
						res.on('data', function (chunk) {
							// chunk is Buffer
							var html = chunk.toString('utf8');
							html.match(
								/<.*name="expense".*data-error="Validation Error!".*>/gi)
								.should.be.ok;
							done();
						});
					});
					req.on('error', function (err) {
						done(err);
					});
					req.write('expense=-1', 'utf8');
					req.end();

on non valid cache value.

var req = http.request(reqOptions, function (res) {
						// debugger;
						res.on('data', function (chunk) {
							// chunk is Buffer
							var html = chunk.toString('utf8');
							html.match(/<.*name="cache".*data-error="Validation Error!".*>/gi)
								.should.be.ok;
							done();
						});
					});
					req.on('error', function(err) {
						done(err);
					});
					req.write('cache=', 'utf8');
					req.end();

on non valid date value.

var req = http.request(reqOptions, function (res) {
						// debugger;
						res.on('data', function (chunk) {
							// chunk is Buffer
							var html = chunk.toString('utf8');
							html.match(/<.*name="date".*data-error="Validation Error!".*>/gi)
								.should.be.ok;
							done();
						});
					});
					req.on('error', function(err) {
						done(err);
					});
					req.write('date=', 'utf8');
					req.end();
## logout page it should redirect to login page.
reqOptions.path = '/logout';
			reqOptions.method = 'GET';
			reqOptions.headers = {
				cookie: cookie
			}
			var req = http.request(reqOptions, function (res) {
				// debugger;
				var location = url.parse(res.headers.location, true, true);
				res.statusCode.should.equal(302);
				location.pathname.should.equal('/login');
				done();
			});
			req.on('error', function(err) {
				done(err);
			});
			req.end();
## admin page should redirect to login page.
reqOptions.path = '/admin';
			reqOptions.method = 'GET';
			reqOptions.headers = {
				cookie: cookie
			}
			var req = http.request(reqOptions, function (res) {
				// debugger;
				var location = url.parse(res.headers.location, true, true);
				res.statusCode.should.equal(302);
				location.pathname.should.equal('/login');
				done();
			});
			req.on('error', function(err) {
				done(err);
			});
			req.end();
## filter page should remember entered values.
var req = http.request(reqOptions, function (res) {
				res.on('data', function (chunk) {
					// chunk is Buffer
					var html = chunk.toString('utf8');
					html.match(/<input.*name="from" value="2012-04-01".*>/gi)
					.should.be.ok;
					html.match(/<input.*name="to" value="2012-09-30".*>/gi)
					.should.be.ok;
					done();
				});
			});
			req.on('error', function(err) {
				done(err);
			});
			req.end();