<commit_before>var demand = require('must');

var keystone = require('../').init(),
	Types = keystone.Field.Types;

/** Test List and Fields */

// use nocreate to allow required fields without tripping `initial` validation
var Test = keystone.List('Test', { nocreate: true }),
	testItem;

before(function() {
	
	// Create a Test List with all the field types that will be tested
	Test.add({
		text: Types.Text,
		string_nested: {
			string: String
		},
		date: Types.Date,
		datetime: Types.Datetime,
		bool: Types.Boolean,
		location: {
			basic: Types.Location,
			customRequired: { type: Types.Location, required: ['state', 'country'] }
		}
	});
	Test.register();
	
	// Create a new Test Item to run tests against
	testItem = new Test.model();
	
});

/** Tests */

describe('Fields', function() {
	
	/** FieldType: Date */
	describe('Date', function() {
		
		it('should parse without error via underscore date', function() {
			testItem._.date.parse('20131204', 'YYYYMMDD');
		});
		
		it('should be the date we expect', function() {
			testItem.date = new Date(2013, 11, 4);
			demand(testItem._.date.format()).to.equal('4th Dec 2013');
			demand(testItem._.date.format('YYYYMMDD')).to.equal('20131204');<commit_msg>Adding Text field tests<commit_after>var demand = require('must');

var keystone = require('../').init(),
	Types = keystone.Field.Types;

/** Test List and Fields */

// use nocreate to allow required fields without tripping `initial` validation
var Test = keystone.List('Test', { nocreate: true }),
	testItem;

before(function() {
	
	// Create a Test List with all the field types that will be tested
	Test.add({
		text: Types.Text,
		bool: Types.Boolean,
		nested: {
			text: String,
			bool: Boolean,
		},
		date: Types.Date,
		datetime: Types.Datetime,
		location: {
			basic: Types.Location,
			customRequired: { type: Types.Location, required: ['state', 'country'] }
		}
	});
	Test.register();
	
	// Create a new Test Item to run tests against
	testItem = new Test.model();
	
});

/** Tests */

describe('Fields', function() {
	
	/** FieldType: Text (String) */
	describe('Text', function() {
		it('should update top level fields', function() {
			Test.fields.text.updateItem(testItem, {
				text: 'value'
			});
			demand(testItem.text).be('value');
			testItem.text = undefined;
		});
		it('should update nested fields', function() {
			Test.fields['nested.text'].updateItem(testItem, {
				nested: {
					text: 'value'
				}
			});
			demand(testItem.nested.text).be('value');
			testItem.nested.text = undefined;
		});
		it('should update nested fields with flat paths', function() {
			Test.fields['nested.text'].updateItem(testItem, {
				'nested.text': 'value'
			});
			demand(testItem.nested.text).be('value');
			testItem.nested.text = undefined;
		});
	});
	
	/** FieldType: Date */
	describe('Date', function() {
		
		it('should parse without error via underscore date', function() {
			testItem._.date.parse('20131204', 'YYYYMMDD');
		});
		
		it('should be the date we expect', function() {
			testItem.date = new Date(2013, 11, 4);
			demand(testItem._.date.format()).to.equal('4th Dec 2013');
			demand(testItem._.date.format('YYYYMMDD')).to.equal('20131204');
{'fraction_non_alphanumeric': 0.16827973774586324, 'fraction_numerical': 0.017483609116453323, 'mean_word_length': 3.711764705882353, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3165878', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1010, 'n_words': 265}