<commit_before>'use strict';


var dynamoose = require('../');
dynamoose.AWS.config.update({
  accessKeyId: 'AKID',
  secretAccessKey: 'SECRET',
  region: 'us-east-1'
});

dynamoose.local();

var should = require('should');
var CatsFixture = require('./fixtures/Cats');

var Cats = {};

var ONE_YEAR = 365*24*60*60; // 1 years in seconds
var NINE_YEARS = 9*ONE_YEAR; // 9 years in seconds

describe('Model', function (){
  this.timeout(15000);
  before(function(done) {
    this.timeout(12000);
    dynamoose.setDefaults({ prefix: 'test-', suffix: '-db' });
    Cats = CatsFixture(dynamoose);
    done();
  });

  after(function (done) {

    delete dynamoose.models['test-Cat-db'];
    done();
  });

  it('Create simple model', function (done) {
    this.timeout(12000);


    Cats.Cat.should.have.property('$__');

    Cats.Cat.should.have.property('name');
    // Older node doesn't support Function.name changes
    if (Object.getOwnPropertyDescriptor(Function, 'name').configurable) {
      Cats.Cat.name.should.eql('Model-test-Cat-db');
    }

    Cats.Cat.$__.name.should.eql('test-Cat-db');
    Cats.Cat.$__.options.should.have.property('create', true);

    var schema = Cats.Cat.$__.schema;

    should.exist(schema);

    schema.attributes.id.type.name.should.eql('number');
    should(schema.attributes.id.isSet).not.be.ok;
    should.not.exist(schema.attributes.id.default);
    should.exist(schema.attributes.id.validator);
    should(schema.attributes.id.required).not.be.ok;

    schema.attributes.name.type.name.should.eql('string');
    schema.attributes.name.isSet.should.not.be.ok;
    should.not.exist(schema.attributes.name.default);
    should.not.exist(schema.attributes.name.validator);
    should(schema.attributes.name.required).not.be.ok;

    schema.hashKey.should.equal(schema.attributes.id); // should be same object
    should.not.exist(schema.rangeKey);

    var kitten = new Cats.Cat(
      {
        id: 1,
        name: 'Fluffy',
        vet:{name:'theVet', address:'12 somewhere'},
        ears:[{name:'left'}, {name:'right'}],
        legs: ['front right', 'front left', 'back right', 'back left'],
        more: {fovorites: {food: 'fish'}},
        array: [{one: '1'}],
        validated: 'valid'
      }
    );

    kitten.id.should.eql(1);
    kitten.name.should.eql('Fluffy');

    var dynamoObj = schema.toDynamo(kitten);

    dynamoObj.should.eql(
      {
        ears: {
          L: [
            { M: { name: { S: 'left' } } },
            { M: { name: { S: 'right' } } }
          ]
        },
        id: { N: '1' },
        name: { S: 'Fluffy' },
        vet: { M: { address: { S: '12 somewhere' }, name: { S: 'theVet' } } },
        legs: { SS: ['front right', 'front left', 'back right', 'back left']},
        more: { S: '{"fovorites":{"food":"fish"}}' },
        array: { S: '[{"one":"1"}]' },
        validated: { S: 'valid' }
      });

    kitten.save(done);


  });
  
  it('Should fail', function() {
    throw "ERROR";
  });

  it('Create simple model with range key', function () {

    Cats.Cat2.should.have.property('name');
    // Older node doesn't support Function.name changes
    if (Object.getOwnPropertyDescriptor(Function, 'name').configurable) {
      Cats.Cat2.name.should.eql('Model-test-Cat2-db');
    }

    Cats.Cat2.should.have.property('$__');

    Cats.Cat2.$__.name.should.eql('test-Cat2-db');
    Cats.Cat2.$__.options.should.have.property('create', true);

    var schema = Cats.Cat2.$__.schema;

    should.exist(schema);

    schema.attributes.ownerId.type.name.should.eql('number');
    should(schema.attributes.ownerId.isSet).not.be.ok;
    should.not.exist(schema.attributes.ownerId.default);
    should.not.exist(schema.attributes.ownerId.validator);
    should(schema.attributes.ownerId.required).not.be.ok;

    schema.attributes.name.type.name.should.eql('string');
    schema.attributes.name.isSet.should.not.be.ok;
    should.not.exist(schema.attributes.name.default);<commit_msg>Revert "Adding failing test"<commit_after>'use strict';


var dynamoose = require('../');
dynamoose.AWS.config.update({
  accessKeyId: 'AKID',
  secretAccessKey: 'SECRET',
  region: 'us-east-1'
});

dynamoose.local();

var should = require('should');
var CatsFixture = require('./fixtures/Cats');

var Cats = {};

var ONE_YEAR = 365*24*60*60; // 1 years in seconds
var NINE_YEARS = 9*ONE_YEAR; // 9 years in seconds

describe('Model', function (){
  this.timeout(15000);
  before(function(done) {
    this.timeout(12000);
    dynamoose.setDefaults({ prefix: 'test-', suffix: '-db' });
    Cats = CatsFixture(dynamoose);
    done();
  });

  after(function (done) {

    delete dynamoose.models['test-Cat-db'];
    done();
  });

  it('Create simple model', function (done) {
    this.timeout(12000);


    Cats.Cat.should.have.property('$__');

    Cats.Cat.should.have.property('name');
    // Older node doesn't support Function.name changes
    if (Object.getOwnPropertyDescriptor(Function, 'name').configurable) {
      Cats.Cat.name.should.eql('Model-test-Cat-db');
    }

    Cats.Cat.$__.name.should.eql('test-Cat-db');
    Cats.Cat.$__.options.should.have.property('create', true);

    var schema = Cats.Cat.$__.schema;

    should.exist(schema);

    schema.attributes.id.type.name.should.eql('number');
    should(schema.attributes.id.isSet).not.be.ok;
    should.not.exist(schema.attributes.id.default);
    should.exist(schema.attributes.id.validator);
    should(schema.attributes.id.required).not.be.ok;

    schema.attributes.name.type.name.should.eql('string');
    schema.attributes.name.isSet.should.not.be.ok;
    should.not.exist(schema.attributes.name.default);
    should.not.exist(schema.attributes.name.validator);
    should(schema.attributes.name.required).not.be.ok;

    schema.hashKey.should.equal(schema.attributes.id); // should be same object
    should.not.exist(schema.rangeKey);

    var kitten = new Cats.Cat(
      {
        id: 1,
        name: 'Fluffy',
        vet:{name:'theVet', address:'12 somewhere'},
        ears:[{name:'left'}, {name:'right'}],
        legs: ['front right', 'front left', 'back right', 'back left'],
        more: {fovorites: {food: 'fish'}},
        array: [{one: '1'}],
        validated: 'valid'
      }
    );

    kitten.id.should.eql(1);
    kitten.name.should.eql('Fluffy');

    var dynamoObj = schema.toDynamo(kitten);

    dynamoObj.should.eql(
      {
        ears: {
          L: [
            { M: { name: { S: 'left' } } },
            { M: { name: { S: 'right' } } }
          ]
        },
        id: { N: '1' },
        name: { S: 'Fluffy' },
        vet: { M: { address: { S: '12 somewhere' }, name: { S: 'theVet' } } },
        legs: { SS: ['front right', 'front left', 'back right', 'back left']},
        more: { S: '{"fovorites":{"food":"fish"}}' },
        array: { S: '[{"one":"1"}]' },
        validated: { S: 'valid' }
      });

    kitten.save(done);


  });

  it('Create simple model with range key', function () {

    Cats.Cat2.should.have.property('name');
    // Older node doesn't support Function.name changes
    if (Object.getOwnPropertyDescriptor(Function, 'name').configurable) {
      Cats.Cat2.name.should.eql('Model-test-Cat2-db');
    }

    Cats.Cat2.should.have.property('$__');

    Cats.Cat2.$__.name.should.eql('test-Cat2-db');
    Cats.Cat2.$__.options.should.have.property('create', true);

    var schema = Cats.Cat2.$__.schema;

    should.exist(schema);

    schema.attributes.ownerId.type.name.should.eql('number');
    should(schema.attributes.ownerId.isSet).not.be.ok;
    should.not.exist(schema.attributes.ownerId.default);
    should.not.exist(schema.attributes.ownerId.validator);
    should(schema.attributes.ownerId.required).not.be.ok;

    schema.attributes.name.type.name.should.eql('string');
    schema.attributes.name.isSet.should.not.be.ok;
    should.not.exist(schema.attributes.name.default);
{'fraction_non_alphanumeric': 0.18484311740890688, 'fraction_numerical': 0.01138663967611336, 'mean_word_length': 2.97635814889336, 'pattern_counts': {'":': 6, '<': 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': '5645452', 'n_tokens_mistral': 2796, 'n_tokens_neox': 2708, 'n_words': 427}