var Datify = require('./');

var Lab = require('lab');
var Chai = require('chai');

Chai.should();
var it = Lab.test;

Lab.experiment('datify', function(){
	it('should convert an ISO Date string to the right date', function(done){
		Datify('2011-09-13T17:09:30.909Z').should.eql(new Date('2011-09-13T17:09:30.909Z'));
		Datify('2011-09-13T17:09:30.909Z').toISOString().should.eql('2011-09-13T17:09:30.909Z');
		Datify('2011-09-13T17:09:30.909Z').constructor.toString().should.contain('function Date');
		done();
	}),

	it('should keep the string "a message" unchanged', function(done){
		Datify('a message').should.eql("a message");
		done();
	}),

	it('should keep a js Date unchanged', function(done){
		Datify(new Date('2011-09-13T17:09:30.909Z')).should.eql(new Date('2011-09-13T17:09:30.909Z'));
		Datify(new Date('2011-09-13T17:09:30.909Z')).toISOString().should.eql('2011-09-13T17:09:30.909Z');
		done();
	}),

	it('should convert an object with an ISO date string to an object with Date', function(done){
		var anObject = {
			content: { },
			createdAt: '2011-09-13T17:12:30.909Z'
		}
		Datify(anObject).should.eql({
			content: { },
			createdAt: new Date('2011-09-13T17:12:30.909Z')
		});

		done();
	}),

	it('should return a different object then the one it was converting', function(done){
		var anObject = {
			content: { },
			createdAt: '2011-09-13T17:12:30.909Z'
		}
		Datify(anObject).should.not.equal(anObject);

		done();
	}),

	it('should convert an object with nested ISO date strings to an object with Dates', function(done){
		var anObject = {
			number: 3441,
			date: new Date(),
			content: { createdAt: '2011-10-13T17:12:30.909Z', i: {am: {losing: {it: '2011-10-13T17:12:30.929Z', yep: "i am"}}}},
			createdAt: '2011-09-13T17:12:30.909Z'
		}
		Datify(anObject).should.eql({
			number: 3441,
			date: anObject.date,
			content: { createdAt: new Date('2011-10-13T17:12:30.909Z'), i: {am: {losing: {it: new Date('2011-10-13T17:12:30.929Z'), yep: "i am"}}}},
			createdAt: new Date('2011-09-13T17:12:30.909Z')
		});

		done();
	});
});
@@ -2028,32 +2028,370 @@
 0.909Z')%0A%09%09%7D);%0A%0A
+%09%09done();%0A%09%7D),%0A%0A%09it('should convert an array of Dates', function(done)%7B%0A%09%09var anArrayOfDates = %5B'2011-10-13T17:12:30.909Z', '2011-10-13T17:12:30.909Z', '2012-10-13T17:12:30.909Z'%5D%0A%09%09Datify(anArrayOfDates).should.eql(%5Bnew Date('2011-10-13T17:12:30.909Z'), %0A%09%09%09new Date('2011-10-13T17:12:30.909Z'), new Date('2012-10-13T17:12:30.909Z')%5D);%0A%0A
 %09%09done();%0A%09%7D);%0A%7D

test for array of dates