var assert = require('assert');

var msg = require('../msg.js');
var subController = require('../controller.js');
var testAdapter = require('./testAdapter.js');
var events = require('../../../events.js');

var controller = subController(testAdapter);

//-----------------------------------------------------------------------------
// Registration Controller Tests

describe('===> Testing Register subscriber controller: \n', function(){

  it('Register Subscriber success', function(done){
		var testId = 'testerID';
    var data = {email: 'test@test.com', password: 'tester10'};

		events.Emitter.once(testId, function(result){
		assert.equal(JSON.stringify(result), JSON.stringify({value:{},tunnel:{}}));
		done();
		});
  controller.module.noauth.register('POST', {}, data, '127.0.0.1', testId);
	});

  it('Missing Email Test', function(done){
		var testId = 'testerID1';
    var data = {email: '', password: 'tester'};

		events.Emitter.once(testId, function(result){
		assert.equal(JSON.stringify(result), JSON.stringify(msg.missingEmail()));
		done();
		});
  controller.module.noauth.register('POST', {}, data, '127.0.0.1', testId);
	});

  it('Bad Email Test', function(done){
		var testId = 'testerID2';
    var data = {email: 'a_terrible_email', password: 'tester'};

		events.Emitter.once(testId, function(result){
		assert.equal(JSON.stringify(result), 
								 JSON.stringify(msg.badEmail(data.email)));
		done();
		});
  controller.module.noauth.register('POST', {}, data, '127.0.0.1', testId);
	});


  it('Missing Password Test', function(done){
		var testId = 'testerID3';
    var data = {email: 'test@hello.com', password: ''};

		events.Emitter.once(testId, function(result){
		assert.equal(JSON.stringify(result), 
								 JSON.stringify(msg.missingPwd()));
		done();
		});
  controller.module.noauth.register('POST', {}, data, '127.0.0.1', testId);
	});


  it('Bad Password Test', function(done){
		var testId = 'testerID4';
    var data = {email: 'test@hello.com', password: '2short'};

		events.Emitter.once(testId, function(result){
		assert.equal(JSON.stringify(result), 
								 JSON.stringify(msg.badPwd()));
		done();
		});
  controller.module.noauth.register('POST', {}, data, '127.0.0.1', testId);
	});
});

// ----------------------------------------------------------------------------
// Verification Test
describe('===> Testing Verify subscriber controller: \n', function(){
	
	it('Bad Token Test', function(done){
		var testId = 'testerID1';
	    	var data = {};
	    	var params = ['doesnt_matter_only_looking_for_params1', 'an_invalid_token'];
		events.Emitter.once(testId, function(result){
		assert.equal(JSON.stringify(result),
		JSON.stringify(msg.badVerificationToken()));
		done();
		});
	  controller.module.noauth.verify('POST', params, data, '127.0.0.1', testId);
	});
	
	it('Missing Token Test', function(done){
		var testId = 'testerID2';
	    	var data = {};
	    	var params = ['doesnt_matter_only_looking_for_params1', ''];
		events.Emitter.once(testId, function(result){
		assert.equal(JSON.stringify(result),
		JSON.stringify(msg.missingVerificationToken()));
		done();
		});
	  controller.module.noauth.verify('POST', params, data, '127.0.0.1', testId);
	});
});

// --------------------------------------------------------------------------------
// Login Test
//describe('===> Testing Login subscriber controller: \n', function(){
	
//}

@@ -3315,18 +3315,16 @@
 in Test%0A
-//
 describe
@@ -3385,13 +3385,862 @@
 ion()%7B%0A%09
-%0A//
+it('Missing Email Test', function(done)%7B%0A        %09var testId = 'testerID1';%0A   %09%09var data = %7Bemail: '', password: 'tester'%7D;%0A                events.Emitter.once(testId, function(result)%7B%0A               %09%09 assert.equal(JSON.stringify(result), JSON.stringify(msg.missingEmail()));%0A               %09%09 done();%0A               %09%09 %7D);%0A %09 controller.module.noauth.login('POST', %7B%7D, data, '127.0.0.1', testId);%0A       %09 %7D);%0A%0A %09 it('Bad Email Test', function(done)%7B%0A                var testId = 'testerID2';%0A   %09%09var data = %7Bemail: 'a_terrible_email', password: 'tester'%7D;%0A                events.Emitter.once(testId, function(result)%7B%0A                assert.equal(JSON.stringify(result), JSON.stringify(msg.badEmail(data.email)));%0A                done();%0A                %7D);%0A %09 controller.module.noauth.login('POST', %7B%7D, data, '127.0.0.1', testId);%0A        %7D);%0A%09%0A
 %7D%0A

update controllerTest