var demand = require('must');
var DateType = require('../DateType');

exports.initList = function (List) {
	List.add({
		date: DateType,
	});
};

exports.testFieldType = function (List) {
	var testItem = new List.model();

	it('should parse date input and return a moment object', function () {
		var m = List.fields.date.parse('2016-02-27');
		demand(m.format('YYYY-MM-DD')).equal('2016-02-27');
	});

	it('should format the date value using moment', function () {
		testItem.date = new Date(2013, 11, 4);
		demand(testItem._.date.format()).equal('4th Dec 2013');
		demand(testItem._.date.format('YYYYMMDD')).equal('20131204');
	});

	it('should return a moment object set to the field value', function () {
		testItem.date = new Date(2013, 11, 4);
		demand(testItem._.date.moment()._isAMomentObject);
		demand(testItem._.date.moment().format('YYYYMMDD')).equal('20131204');
	});

	it('should validate input present', function (done) {
		List.fields.date.validateRequiredInput(this, { date: 'a' }, function (result) {
			demand(result).be(true);
			done();
		});
	});

	it('should invalidate input not present', function (done) {
		List.fields.date.validateRequiredInput(this, { date: '' }, function (result) {
			demand(result).be(false);
			done();
		});
	});
};

@@ -185,43 +185,8 @@
 ) %7B%0A
-%09var testItem = new List.model();%0A%0A
 %09it(
@@ -416,32 +416,67 @@
 , function () %7B%0A
+%09%09var testItem = new List.model();%0A
 %09%09testItem.date 
@@ -702,16 +702,51 @@
 on () %7B%0A
+%09%09var testItem = new List.model();%0A
 %09%09testIt
@@ -902,32 +902,82 @@
 131204');%0A%09%7D);%0A%0A
+%09describe('validateRequiredInput', function () %7B%0A%09
 %09it('should vali
@@ -1007,32 +1007,69 @@
 nction (done) %7B%0A
+%09%09%09var testItem = new List.model();%0A%09
 %09%09List.fields.da
@@ -1086,35 +1086,39 @@
 eRequiredInput(t
-his
+estItem
 , %7B date: 'a' %7D,
@@ -1130,32 +1130,33 @@
 tion (result) %7B%0A
+%09
 %09%09%09demand(result
@@ -1166,32 +1166,33 @@
 e(true);%0A%09%09%09
+%09
 done();%0A
 %09%09%7D);%0A%09%7D);%0A%0A
@@ -1183,20 +1183,23 @@
 ();%0A
+%09
 %09%09%7D);%0A
+%09
 %09%7D);%0A%0A
+%09
 %09it(
@@ -1221,91 +1221,588 @@
 ate 
-input not present', function (done) %7B%0A%09%09List.fields.date.validateRequiredInput(this
+empty string', function (done) %7B%0A%09%09%09var testItem = new List.model();%0A%09%09%09List.fields.date.validateRequiredInput(testItem, %7B date: '' %7D, function (result) %7B%0A%09%09%09%09demand(result).be(false);%0A%09%09%09%09done();%0A%09%09%09%7D);%0A%09%09%7D);%0A%0A%09%09it('should invalidate null', function (done) %7B%0A%09%09%09var testItem = new List.model();%0A%09%09%09List.fields.date.validateRequiredInput(testItem, %7B date: null %7D, function (result) %7B%0A%09%09%09%09demand(result).be(false);%0A%09%09%09%09done();%0A%09%09%09%7D);%0A%09%09%7D);%0A%0A%09%09it('should invalidate undefined', function (done) %7B%0A%09%09%09var testItem = new List.model();%0A%09%09%09List.fields.date.validateRequiredInput(testItem
 , %7B 
@@ -1799,34 +1799,41 @@
 stItem, %7B date: 
-''
+undefined
  %7D, function (re
@@ -1843,16 +1843,17 @@
 t) %7B%0A%09%09%09
+%09
 demand(r
@@ -1873,24 +1873,25 @@
 se);%0A%09%09%09
+%09
 done();%0A
 %09%09%7D);%0A%09%7D
@@ -1882,16 +1882,23 @@
 done();%0A
+%09%09%09%7D);%0A
 %09%09%7D);%0A%09%7D

Structure and add missing tests to date field