define([
    'bitbucket/internal/model/person'
], function(
    Person
    ) {
    'use strict';

    module('model-person');

    var name = 'hello';
    var email = 'hello@example.com';

    var testPerson = new Person({
        emailAddress: email,
        name: name
    });

    test('Properties', function(){

        equal(testPerson.getEmailAddress(), email, 'Can get the email address');
        equal(testPerson.getName(), name, 'Can get the name');
        equal(testPerson.getId(), name, 'ID is set to the name');
        equal(testPerson.attributes.name, name, 'Accessing the raw `name` attribute returns the name');

        // undefined methods should throw an error
        throws(function() { testPerson.getSomeUndefinedProperty(); }, TypeError, 'Using getter for undefined properties throws a TypeError');

    });

    test('Empty Person', function() {

        var emptyPerson = new Person();

        equal(emptyPerson.getEmailAddress(), undefined, 'Email is undefined');
        equal(emptyPerson.getName(), undefined, 'Name is undefined');
        equal(emptyPerson.getId(), undefined, 'ID is undefined');
        equal(emptyPerson.attributes.name,  undefined, 'Accessing the raw `name` attribute returns undefined');

    });

    test('Invalid Person', function() {

        // Test the model not accepting properties that were not defined as named attributes
        throws(
            function() { new Person({someUndefinedProperty:'hello' }); },
            /Attribute 'someUndefinedProperty' does not exist/,
            'Creating a new Person with non-existing properties throws an error'
        );

        // Test the model only accepting attributes of the correct type
        throws(
            function() { new Person({name: 1}); },
            /expected it to be string/,
            'Creating a new Person with invalid attributes throws an error'
        );

    });

    test('Exporting', function() {

       deepEqual(testPerson.toJSON(), { emailAddress: email, name: name, id: name }, 'toJSON method exports a correct represenation of the model');

    });


});