-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmodel_test.js
More file actions
90 lines (80 loc) · 2.59 KB
/
model_test.js
File metadata and controls
90 lines (80 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* global describe, it */
var Sequelize = require('sequelize'),
sequelize = require('./environment'),
assert = require('assert');
describe('Models', function () {
'use strict';
describe('.fixtures', function () {
it('should generate fixture base on define of Model', function () {
var Foo = sequelize.define('Foo', {
title: Sequelize.STRING(64),
string: Sequelize.STRING,
text: Sequelize.TEXT,
bool: Sequelize.BOOLEAN,
num: Sequelize.INTEGER,
bignum: Sequelize.BIGINT,
float: Sequelize.FLOAT,
date: Sequelize.DATE,
uuid: Sequelize.UUID,
});
var fixture = Foo.fixtures();
assert.ok(fixture.title);
assert.ok(fixture.string);
assert.ok(fixture.text);
assert.equal(typeof fixture.bool, 'boolean');
assert.ok(fixture.num);
assert.ok(fixture.bignum);
assert.ok(fixture.float);
assert.ok(fixture.date);
assert.ok(fixture.uuid);
});
it('should not generate autoIncrement keys', function () {
var Foo = sequelize.define('Foo', {});
var fixture = Foo.fixtures();
assert.equal(fixture.id, null);
});
it('should generate autoIncrement keys when user want', function () {
var Foo = sequelize.define('Foo', {});
var fixture = Foo.fixtures({gen_auto_increment: true});
assert.ok(fixture.id);
});
it('should generate url when user defined it in sequelize', function () {
var Foo = sequelize.define('Foo', {
url: {
type: Sequelize.STRING,
validate: {
isUrl: true
}
}
});
var fixture = Foo.fixtures();
assert.equal(fixture.url.substr(0,4).toLowerCase(), 'http');
});
it('should generate email when user defined it in sequelize', function () {
var Foo = sequelize.define('Foo', {
email: {
type: Sequelize.STRING,
validate: {
isEmail: true
}
}
});
var fixture = Foo.fixtures();
assert.ok(fixture.email.indexOf('@') > 0);
});
});
describe('multi data generate', function () {
it('should generate multi datas when user want', function () {
var Foo = sequelize.define('Foo', { });
var fixture = Foo.fixtures({num: 10});
assert.ok(fixture instanceof Array);
assert.equal(fixture.length, 10);
});
it('should work when optons is a num', function () {
var Foo = sequelize.define('Foo', { });
var fixture = Foo.fixtures(10);
assert.ok(fixture instanceof Array);
assert.equal(fixture.length, 10);
});
});
});