Change first character of all end-of-line comments to upper case
This commit is contained in:
		@@ -7,7 +7,7 @@ import IdValidate from '../routes/validate/id';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
export default class TestHelper {
 | 
			
		||||
	public static auth = {  // test user credentials
 | 
			
		||||
	public static auth = {  // Test user credentials
 | 
			
		||||
		admin: {pass: 'Abc123!#', key: '000000000000000000001003', id: '000000000000000000000003'},
 | 
			
		||||
		janedoe: {pass: 'Xyz890*)', key: '000000000000000000001002', id: '000000000000000000000002'},
 | 
			
		||||
		user: {pass: 'Xyz890*)', key: '000000000000000000001001', id: '000000000000000000000001'},
 | 
			
		||||
@@ -15,7 +15,7 @@ export default class TestHelper {
 | 
			
		||||
		customer: {pass: 'Xyz890*)', key: '000000000000000000001005', id: '000000000000000000000005'}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static res = {  // default responses
 | 
			
		||||
	public static res = {  // Default responses
 | 
			
		||||
		400: {status: 'Bad request'},
 | 
			
		||||
		401: {status: 'Unauthorized'},
 | 
			
		||||
		403: {status: 'Forbidden'},
 | 
			
		||||
@@ -30,27 +30,27 @@ export default class TestHelper {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	static beforeEach (server, done) {
 | 
			
		||||
		// delete cached server code except models as these are needed in the testing files as well
 | 
			
		||||
		// Delete cached server code except models as these are needed in the testing files as well
 | 
			
		||||
		Object.keys(require.cache).filter(e => /API\\dist\\(?!(models|db|test))/.test(e)).forEach(key => {
 | 
			
		||||
			delete require.cache[key];  // prevent loading from cache
 | 
			
		||||
			delete require.cache[key];  // Prevent loading from cache
 | 
			
		||||
		});
 | 
			
		||||
		server = require('../index');
 | 
			
		||||
		db.drop(err => {  // reset database
 | 
			
		||||
		db.drop(err => {  // Reset database
 | 
			
		||||
			if (err) return done(err);
 | 
			
		||||
			db.loadJson(require('./db.json'), done);
 | 
			
		||||
		});
 | 
			
		||||
		return server
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// options in form: {method, url, contentType, auth: {key/basic: 'name' or 'key'/{name, pass}}, httpStatus, req, res,
 | 
			
		||||
	// default (set to false if you want to dismiss default .end handling)}
 | 
			
		||||
	// Options in form: {method, url, contentType, auth: {key/basic: 'name' or 'key'/{name, pass}}, httpStatus, req, res,
 | 
			
		||||
	// Default (set to false if you want to dismiss default .end handling)}
 | 
			
		||||
	static request (server, done, options) {
 | 
			
		||||
		let st = supertest(server);
 | 
			
		||||
		if (options.hasOwnProperty('auth') && options.auth.hasOwnProperty('key')) {  // resolve API key
 | 
			
		||||
		if (options.hasOwnProperty('auth') && options.auth.hasOwnProperty('key')) {  // Resolve API key
 | 
			
		||||
			options.url += '?key=' +
 | 
			
		||||
				(this.auth.hasOwnProperty(options.auth.key)? this.auth[options.auth.key].key : options.auth.key);
 | 
			
		||||
		}
 | 
			
		||||
		switch (options.method) {  // http method
 | 
			
		||||
		switch (options.method) {  // Http method
 | 
			
		||||
			case 'get':
 | 
			
		||||
				st = st.get(options.url)
 | 
			
		||||
			break;
 | 
			
		||||
@@ -64,16 +64,16 @@ export default class TestHelper {
 | 
			
		||||
				st = st.delete(options.url)
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
		if (options.hasOwnProperty('reqType')) {  // request body
 | 
			
		||||
		if (options.hasOwnProperty('reqType')) {  // Request body
 | 
			
		||||
			st = st.type(options.reqType);
 | 
			
		||||
		}
 | 
			
		||||
		if (options.hasOwnProperty('req')) {  // request body
 | 
			
		||||
		if (options.hasOwnProperty('req')) {  // Request body
 | 
			
		||||
			st = st.send(options.req);
 | 
			
		||||
		}
 | 
			
		||||
		if (options.hasOwnProperty('reqContentType')) {  // request body
 | 
			
		||||
		if (options.hasOwnProperty('reqContentType')) {  // Request body
 | 
			
		||||
			st = st.set('Content-Type', options.reqContentType);
 | 
			
		||||
		}
 | 
			
		||||
		if (options.hasOwnProperty('auth') && options.auth.hasOwnProperty('basic')) {  // resolve basic auth
 | 
			
		||||
		if (options.hasOwnProperty('auth') && options.auth.hasOwnProperty('basic')) {  // Resolve basic auth
 | 
			
		||||
			if (this.auth.hasOwnProperty(options.auth.basic)) {
 | 
			
		||||
				st = st.auth(options.auth.basic, this.auth[options.auth.basic].pass)
 | 
			
		||||
			}
 | 
			
		||||
@@ -87,26 +87,26 @@ export default class TestHelper {
 | 
			
		||||
		else {
 | 
			
		||||
			st = st.expect('Content-type', /json/).expect(options.httpStatus);
 | 
			
		||||
		}
 | 
			
		||||
		if (options.hasOwnProperty('res')) {  // evaluate result
 | 
			
		||||
		if (options.hasOwnProperty('res')) {  // Evaluate result
 | 
			
		||||
			return st.end((err, res) => {
 | 
			
		||||
				if (err) return done (err);
 | 
			
		||||
				should(res.body).be.eql(options.res);
 | 
			
		||||
				done();
 | 
			
		||||
			});
 | 
			
		||||
		}
 | 
			
		||||
		else if (this.res.hasOwnProperty(options.httpStatus) && options.default !== false) {  // evaluate default results
 | 
			
		||||
		else if (this.res.hasOwnProperty(options.httpStatus) && options.default !== false) {  // Evaluate default results
 | 
			
		||||
			return st.end((err, res) => {
 | 
			
		||||
				if (err) return done (err);
 | 
			
		||||
				should(res.body).be.eql(this.res[options.httpStatus]);
 | 
			
		||||
				done();
 | 
			
		||||
			});
 | 
			
		||||
		}
 | 
			
		||||
		// check changelog, takes log: {collection, skip, data/(dataAdd, dataIgn)}
 | 
			
		||||
		// Check changelog, takes log: {collection, skip, data/(dataAdd, dataIgn)}
 | 
			
		||||
		else if (options.hasOwnProperty('log')) {
 | 
			
		||||
			return st.end(err => {
 | 
			
		||||
				if (err) return done (err);
 | 
			
		||||
				ChangelogModel.findOne({}).sort({_id: -1}).skip(options.log.skip? options.log.skip : 0)
 | 
			
		||||
				.lean().exec((err, data) => {  // latest entry
 | 
			
		||||
				.lean().exec((err, data) => {  // Latest entry
 | 
			
		||||
					if (err) return done(err);
 | 
			
		||||
					should(data).have.only.keys('_id', 'action', 'collection_name', 'conditions', 'data', 'user_id', '__v');
 | 
			
		||||
					should(data).have.property('action', options.method.toUpperCase() + ' ' + options.url);
 | 
			
		||||
@@ -132,7 +132,7 @@ export default class TestHelper {
 | 
			
		||||
				});
 | 
			
		||||
			});
 | 
			
		||||
		}
 | 
			
		||||
		else {  // return object to do .end() manually
 | 
			
		||||
		else {  // Return object to do .end() manually
 | 
			
		||||
			return st;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +1,10 @@
 | 
			
		||||
import db from '../db';
 | 
			
		||||
 | 
			
		||||
// script to load test db into dev db for a clean start
 | 
			
		||||
// Script to load test db into dev db for a clean start
 | 
			
		||||
 | 
			
		||||
db.connect('dev', () => {
 | 
			
		||||
	console.info('dropping data...');
 | 
			
		||||
	db.drop(() => {  // reset database
 | 
			
		||||
	db.drop(() => {  // Reset database
 | 
			
		||||
		console.info('loading data...');
 | 
			
		||||
		db.loadJson(require('./db.json'), () => {
 | 
			
		||||
			console.info('done');
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user