generate.js
1.61 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
/*jslint node: true, stupid: true, nomen:true */
/*global describe, it, before, beforeEach, after, afterEach */
"use strict";
var assert = require('chai').assert;
var testDB = require('./util/db.js');
var path = require('path');
var fs = require('fs-extra');
var cart, account;
before(function (done) {
testDB.generate(1, { resetConfig: true, nolog: true, output: path.join(__dirname, 'model') }, done);
});
before(function(done) {
cart = require('./model/definition-files/public_cart.js');
account = require('./model/definition-files/public_account.js');
done();
});
after(function (done) {
fs.removeSync(path.join(__dirname, 'model'));
testDB.dropDB(done);
});
describe('public.cart', function () {
it('should have model file.', function () {
assert.isTrue(fs.existsSync(path.join(__dirname, 'model', 'definition-files', 'public_cart.js')));
});
it('should have model name.', function () {
assert.equal(cart.modelName, 'public.cart');
});
it('should have createdAt attribute.', function () {
assert.equal(cart.attributes.createdAt.field, 'created_at');
});
it('should have relations.', function () {
assert.equal(cart.relations.length, 3);
});
});
describe('public.account', function () {
it('should have relation to other_schema.', function () {
var found = false;
account.relations.forEach(function (relation) {
if (relation.model === 'otherSchema.otherSchemaTable') {
found = true;
}
assert.isTrue(found);
});
});
});