bookshelf-modelbase
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -20,4 +20,4 @@ var _ = require('lodash'); | ||
var validation = Joi.validate(this.attributes, this.validation); | ||
if (validation.errors) { | ||
throw new Error(validation.errors); | ||
if (validation.error) { | ||
throw new Error(validation.error); | ||
} else { | ||
@@ -24,0 +24,0 @@ return validation.value; |
{ | ||
"name": "bookshelf-modelbase", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Extensible ModelBase for bookshelf-based model layers", | ||
@@ -5,0 +5,0 @@ "main": "./lib", |
@@ -1,2 +0,2 @@ | ||
ModelBase ![Build Status](https://travis-ci.org/bsiddiqui/bookshelf-modelbase.svg?branch=master) [![Code Climate](https://codeclimate.com/github/bsiddiqui/bookshelf-modelbase/badges/gpa.svg)](https://codeclimate.com/github/bsiddiqui/bookshelf-modelbase) [![Test Coverage](https://codeclimate.com/github/bsiddiqui/bookshelf-modelbase/badges/coverage.svg)](https://codeclimate.com/github/bsiddiqui/bookshelf-modelbase) [![npm version](https://badge.fury.io/js/bookshelf-modelbase.svg)](http://badge.fury.io/js/bookshelf-modelbase) | ||
ModelBase [![Build Status](https://travis-ci.org/bsiddiqui/bookshelf-modelbase.svg?branch=master)](https://travis-ci.org/bsiddiqui/bookshelf-modelbase) [![Code Climate](https://codeclimate.com/github/bsiddiqui/bookshelf-modelbase/badges/gpa.svg)](https://codeclimate.com/github/bsiddiqui/bookshelf-modelbase) [![Test Coverage](https://codeclimate.com/github/bsiddiqui/bookshelf-modelbase/badges/coverage.svg)](https://codeclimate.com/github/bsiddiqui/bookshelf-modelbase) [![npm version](https://badge.fury.io/js/bookshelf-modelbase.svg)](http://badge.fury.io/js/bookshelf-modelbase) | ||
========== | ||
@@ -3,0 +3,0 @@ |
var Joi = require('joi'); | ||
var sinon = require('sinon'); | ||
var mocha = require('mocha'); | ||
var chai = require('chai'), | ||
expect = chai.expect; | ||
var chai = require('chai'); | ||
var expect = chai.expect; | ||
var db = require('./db'); | ||
bookshelf = require('bookshelf')(db); | ||
ModelBase = require('../lib/index')(bookshelf); | ||
var bookshelf = require('bookshelf')(db); | ||
var ModelBase = require('../lib/index')(bookshelf); | ||
describe('model base', function () { | ||
describe('modelBase', function () { | ||
var specimen; | ||
beforeEach(function () { | ||
var specimenClass = ModelBase.extend({}, { | ||
validation: { | ||
a: Joi.string().valid('test') | ||
} | ||
}); | ||
specimen = new ModelBase({ name: 'hello' }, { | ||
specimenClass = ModelBase.extend({ | ||
validation: { name: Joi.string().valid('hello') } | ||
}); | ||
specimen = new specimenClass({ name: 'hello' }); | ||
}); | ||
describe('initialize', function () { | ||
it('should error if not passed bookshelf object', function () { | ||
expect(function () { | ||
require('../lib/index')(); | ||
}).to.throw(/Must pass an initialized bookshelf instance/); | ||
}); | ||
it('should default to any validation', function () { | ||
specimen = new ModelBase(); | ||
expect(specimen.validation.isJoi).to.eql(true); | ||
expect(specimen.validation._type).to.eql('any'); | ||
}); | ||
}) | ||
describe('parse', function () { | ||
@@ -43,5 +53,9 @@ it('should convert snake case to camel case', function () { | ||
}); | ||
}); | ||
it('should error on invalid attributes', function () { | ||
specimen.set('name', 1); | ||
return expect(specimen.validateSave).to.throw() | ||
expect(function () { | ||
specimen.validateSave(); | ||
}).to.throw(/ValidationError/); | ||
}); | ||
@@ -48,0 +62,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
8516
114
0