1 | 'use strict';
|
2 |
|
3 | const _ = require('lodash');
|
4 | const fs = require('fs');
|
5 | const expect = require('chai').expect;
|
6 | const connect = require('../index').connect;
|
7 | const validateId = require('./util').validateId;
|
8 | const Foo = require('./cyclic/foo');
|
9 | const Bar = require('./cyclic/bar');
|
10 |
|
11 | describe('Cyclic', function() {
|
12 |
|
13 |
|
14 | const url = 'nedb://memory';
|
15 |
|
16 | let database = null;
|
17 |
|
18 | before(function(done) {
|
19 | connect(url).then(function(db) {
|
20 | database = db;
|
21 | return database.dropDatabase();
|
22 | }).then(function() {
|
23 | return done();
|
24 | });
|
25 | });
|
26 |
|
27 | beforeEach(function(done) {
|
28 | done();
|
29 | });
|
30 |
|
31 | afterEach(function(done) {
|
32 | database.dropDatabase().then(function() {}).then(done, done);
|
33 | });
|
34 |
|
35 | after(function(done) {
|
36 | database.dropDatabase().then(function() {}).then(done, done);
|
37 | });
|
38 |
|
39 | describe('schema', function() {
|
40 | it('should allow cyclic dependencies', function(done) {
|
41 | let f = Foo.create();
|
42 | f.num = 26;
|
43 | let b = Bar.create();
|
44 | b.num = 99;
|
45 |
|
46 | f.save().then(function(foo) {
|
47 | b.foo = foo;
|
48 | return b.save();
|
49 | }).then(function(bar) {
|
50 | f.bar = b;
|
51 | return f.save();
|
52 | }).then(function(foo) {
|
53 | return Foo.findOne({ num: 26 });
|
54 | }).then(function(foo) {
|
55 | validateId(foo);
|
56 | validateId(foo.bar);
|
57 | expect(foo.num).to.be.equal(26);
|
58 | expect(foo.bar.num).to.be.equal(99);
|
59 | return Bar.findOne({ num: 99 });
|
60 | }).then(function(bar) {
|
61 | validateId(bar);
|
62 | validateId(bar.foo);
|
63 | expect(bar.num).to.be.equal(99);
|
64 | expect(bar.foo.num).to.be.equal(26);
|
65 | }).then(done, done);
|
66 |
|
67 | });
|
68 | });
|
69 | }); |
\ | No newline at end of file |