Skip to content

Commit 743e6c6

Browse files
committed
Add NotEmpty tests
1 parent 734ea5d commit 743e6c6

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

test/specs/validation.spec.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {Model} from "../../lib/models/Model";
1414
import {Table} from "../../lib/annotations/Table";
1515
import {Column} from "../../lib/annotations/Column";
1616
import {Length} from "../../lib/annotations/validation/Length";
17+
import {NotEmpty} from "../../lib/annotations/validation/NotEmpty";
1718

1819
use(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

Comments
 (0)