usage.js
1.29 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
/*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 account, contact;
before(function (done) {
testDB.generate(1, { resetConfig: true, nolog: true, output: path.join(__dirname, 'model') }, done);
});
before(function(done) {
var orm = require('./model');
orm.setup(testDB.dbConfig.database, testDB.dbConfig.user, testDB.dbConfig.password, { host: testDB.dbConfig.host, logging: false});
var sequelize = orm.sequelize;
account = orm.model('public.account'); // Can be configured without schema.
contact = orm.model('public.contact'); // Can be configured without schema.
done();
});
after(function (done) {
fs.removeSync(path.join(__dirname, 'model'));
testDB.dropDB(done);
});
describe('public.account', function () {
// Test one-to-many
it('should have many primary contacts.', function (done) {
account.findAll({ include: [ { model: contact, as: "primaryContacts" } ] }).then(function(data) {
assert.equal(data[0].primaryContacts[0].name, "Özüm");
done();
});
});
});