@@ -14,6 +14,7 @@ import {Model} from "../../lib/models/Model";
1414import { Table } from "../../lib/annotations/Table" ;
1515import { Column } from "../../lib/annotations/Column" ;
1616import { Length } from "../../lib/annotations/validation/Length" ;
17+ import { NotEmpty } from "../../lib/annotations/validation/NotEmpty" ;
1718
1819use ( chaiAsPromised ) ;
1920
@@ -317,6 +318,73 @@ describe('validation', () => {
317318
318319 } ) ;
319320
321+ describe ( 'NotEmpty' , ( ) => {
322+
323+ it ( 'should not produce an error' , ( ) => {
324+ @Table
325+ class User extends Model < User > {
326+ @NotEmpty @Column name : string ;
327+ }
328+ const sequelizeValidationOnly = createSequelizeValidationOnly ( false ) ;
329+ sequelizeValidationOnly . addModels ( [ User ] ) ;
330+ const user = new User ( { name : 'elisa' } ) ;
331+
332+ if ( majorVersion === 3 ) {
333+ return user . validate ( ) . then ( err => expect ( err ) . to . be . not . an ( 'object' ) ) ;
334+ } else if ( majorVersion === 4 ) {
335+ return expect ( user . validate ( ) ) . to . be . not . rejected ;
336+ }
337+ } ) ;
338+
339+ it ( 'should produce an error' , ( ) => {
340+ @Table
341+ class User extends Model < User > {
342+ @NotEmpty @Column name : string ;
343+ }
344+ const sequelizeValidationOnly = createSequelizeValidationOnly ( false ) ;
345+ sequelizeValidationOnly . addModels ( [ User ] ) ;
346+ const user = new User ( { name : '' } ) ;
347+
348+ if ( majorVersion === 3 ) {
349+ return user . validate ( ) . then ( err => expect ( err ) . to . be . an ( 'object' ) ) ;
350+ } else if ( majorVersion === 4 ) {
351+ return expect ( user . validate ( ) ) . to . be . rejected ;
352+ }
353+ } ) ;
354+
355+ it ( 'should not produce an error (with msg)' , ( ) => {
356+ @Table
357+ class User extends Model < User > {
358+ @NotEmpty ( { msg : 'NotEmpty' } ) @Column name : string ;
359+ }
360+ const sequelizeValidationOnly = createSequelizeValidationOnly ( false ) ;
361+ sequelizeValidationOnly . addModels ( [ User ] ) ;
362+ const user = new User ( { name : 'elisa' } ) ;
363+
364+ if ( majorVersion === 3 ) {
365+ return user . validate ( ) . then ( err => expect ( err ) . to . be . not . an ( 'object' ) ) ;
366+ } else if ( majorVersion === 4 ) {
367+ return expect ( user . validate ( ) ) . to . be . not . rejected ;
368+ }
369+ } ) ;
370+
371+ it ( 'should produce an error (with msg)' , ( ) => {
372+ @Table
373+ class User extends Model < User > {
374+ @NotEmpty ( { msg : 'NotEmpty' } ) @Column name : string ;
375+ }
376+ const sequelizeValidationOnly = createSequelizeValidationOnly ( false ) ;
377+ sequelizeValidationOnly . addModels ( [ User ] ) ;
378+ const user = new User ( { name : '' } ) ;
379+
380+ if ( majorVersion === 3 ) {
381+ return user . validate ( ) . then ( err => expect ( err . errors [ 0 ] . message ) . to . eq ( 'NotEmpty' ) ) ;
382+ } else if ( majorVersion === 4 ) {
383+ return expect ( user . validate ( ) ) . to . be . rejected ;
384+ }
385+ } ) ;
386+ } ) ;
387+
320388 } ) ;
321389
322390 describe ( 'only' , ( ) => {
0 commit comments