Beispiel #1
0
            .end(function(err, res)
            {
                if (err)
                    return done(err);

                res.body.should.have.property('contact').and.be.instanceof(Object);

                var obj = res.body;

                if (obj.contact.messages.length != records){
                    helper.warnings.push('WARNING: expected ' + records + ' messages, received ' + obj.contact.messages.length +
                        ' - make sure at least ' + records + ' messages exist for this contact');
                }

                model = models.ContactMessagesOutput;

                var modelKeysArray = Object.keys(model.properties);

                if (model && model.properties){
                    for (var i = 0, j = modelKeysArray.length; i < j; i++){
                        var modelName = helper.getModelName(model, modelKeysArray[i]);
                        validate.validateData(obj[modelKeysArray[i]], models, modelName);
                    }
                }

                return done();
            });
Beispiel #2
0
            .end(function(err, res)
            {
                if (err)
                    return done(err);

                res.body.should.have.property('contact').and.be.instanceof(Object);

                var obj = res.body;

                // we just created 3 notes, so they'd better be here
                if (obj.contact.notes.length < 3){
                    helper.warnings.push('WARNING: expected 3 notes, received ' + obj.contact.notes.length);
                } else {
                    noteIds = obj.contact.notes;
                }

                model = models.ContactNotesOutput;

                var modelKeysArray = Object.keys(model.properties);

                if (model && model.properties){
                    for (var i = 0, j = modelKeysArray.length; i < j; i++){
                        var modelName = helper.getModelName(model, modelKeysArray[i]);
                        validate.validateData(obj[modelKeysArray[i]], models, modelName);
                    }
                }

                return done();
            });
Beispiel #3
0
            .end(function(err, res)
            {
                if (err)
                    return done(err);

                res.body.should.have.property('account').and.be.instanceof(Object);

                var obj = res.body;

                var warning = null;

                if (obj.account.contacts){
                    if (obj.account.contacts.length > 0){
                        contact = obj.account.contacts[0];
                    } else {
                        helper.warnings.push('WARNING: no contacts found for ' + contactName);
                    }
                } else {
                    helper.warnings.push('WARNING: contacts property is missing');
                }

                model = models.AccountContactsOutput;

                var modelKeysArray = Object.keys(model.properties);

                if (model && model.properties){
                    for (var i = 0, j = modelKeysArray.length; i < j; i++){
                        var modelName = helper.getModelName(model, modelKeysArray[i]);
                        validate.validateData(obj[modelKeysArray[i]], models, modelName);
                    }
                }

                return done();
            });
Beispiel #4
0
            .end(function(err, res)
            {
                if (err)
                    return done(err);

                res.body.should.have.property('contact').and.be.instanceof(Object);

                var obj = res.body;

                if (ids.length > 0 && obj.contact.messages.length != 1){
                    helper.warnings.push('WARNING: conversation was not grouped');
                }

                model = models.ContactMessagesOutput;

                var modelKeysArray = Object.keys(model.properties);

                if (model && model.properties){
                    for (var i = 0, j = modelKeysArray.length; i < j; i++){
                        var modelName = helper.getModelName(model, modelKeysArray[i]);
                        validate.validateData(obj[modelKeysArray[i]], models, modelName);
                    }
                }

                return done();
            });
Beispiel #5
0
            .end(function(err, res)
            {
                if (err)
                    return done(err);

                res.body.should.have.property('contact').and.be.instanceof(Object);

                var obj = res.body;

                // let's take 2 ids for now.. don't think we have too many
                if (obj.contact.messages.length > 0){
                    ids[0] = obj.contact.messages[0].id;
                    if (obj.contact.messages[1]){
                        ids[1] = obj.contact.messages[1].id;
                    }
                }

                model = models.ContactMessagesOutput;

                var modelKeysArray = Object.keys(model.properties);

                if (model && model.properties){
                    for (var i = 0, j = modelKeysArray.length; i < j; i++){
                        var modelName = helper.getModelName(model, modelKeysArray[i]);
                        validate.validateData(obj[modelKeysArray[i]], models, modelName);
                    }
                }

                return done();
            });
Beispiel #6
0
            .end(function(err, res)
            {
                if (err)
                    return done(err);

                res.body.should.have.property('contact').and.be.instanceof(Object);

                var obj = res.body;

                // we don't have at least 10 messages for now.. when we will we'll use != 10
                if (obj.contact.messages.length > 10){
                    helper.warnings.push('WARNING: expected maximum 10 messages, received ' + obj.contact.messages.length);
                }

                model = models.ContactMessagesOutput;

                var modelKeysArray = Object.keys(model.properties);

                if (model && model.properties){
                    for (var i = 0, j = modelKeysArray.length; i < j; i++){
                        var modelName = helper.getModelName(model, modelKeysArray[i]);
                        validate.validateData(obj[modelKeysArray[i]], models, modelName);
                    }
                }

                return done();
            });
Beispiel #7
0
            .end(function(err, res)
            {
                if (err)
                    return done(err);

                res.body.should.have.property('note').and.be.instanceof(Object);

                var obj = res.body;

                model = models.NoteOutput;

                var modelKeysArray = Object.keys(model.properties);

                if (model && model.properties){
                    for (var i = 0, j = modelKeysArray.length; i < j; i++){
                        var modelName = helper.getModelName(model, modelKeysArray[i]);
                        validate.validateData(obj[modelKeysArray[i]], models, modelName);
                    }
                }

                return done();
            });
exports.validateData = function(obj, models, modelName){

    if (modelName){
        var model = models[modelName];
        /*
         * testing purposes
         */
        //console.log('------obj------');
        //console.log(obj);
        //console.log('------model------');
        //console.log(model);

        var modelKeysArray = Object.keys(model.properties);

        /*
         * testing purposes
         */
        //console.log('------modelKeysArray------');
        //console.log(modelKeysArray);

        // if existing model has any properties to check..
        if (modelKeysArray.length > 0){

            // check each model property..
            for (var i = 0, j = modelKeysArray.length; i < j; i++){

                // the response object might not contain this property, so we check this first
                if (obj && obj[modelKeysArray[i]]){

                    // if this property object has a type, then we're dealing with a straight value or an array of items
                    if (model.properties[modelKeysArray[i]].type){

                        // if types match, carry on..
                        if (Object.prototype.toString.call(obj[modelKeysArray[i]]) == this.types[model.properties[modelKeysArray[i]].type]){

                            // parse arrays
                            if (Object.prototype.toString.call(obj[modelKeysArray[i]]) == this.types.array){
                                for (var k = 0, l = obj[modelKeysArray[i]].length; k < l; k++){
                                    var name = helper.getModelName(model, modelKeysArray[i]);
                                    this.validateData(obj[modelKeysArray[i]][k], models, name);
                                }
                            } else {
                                /*
                                 * testing purposes
                                 */
                                //console.log('OK - ' + modelName + ': ' + modelKeysArray[i]);
                            }
                        } else {
                            helper.warnings.push(
                                'WARNING: types don\'t match in ' + model.id +
                                    ': required ' + this.types[model.properties[modelKeysArray[i]].type] +
                                    ' but got ' + Object.prototype.toString.call(obj[modelKeysArray[i]])
                            );
                        }
                    // ..else, there's an object in there (direct $ref)
                    } else {
                        var name = helper.getModelName(model, modelKeysArray[i]);
                        this.validateData(obj[modelKeysArray[i]], models, name);
                    }
                }
            }
        } else {
            // .. there's something wrong with swagger data
            helper.warnings.push('WARNING: no properties for ' + model.id);
        }
    }
};