-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest-collection-names.js
More file actions
114 lines (100 loc) · 3.66 KB
/
Copy pathtest-collection-names.js
File metadata and controls
114 lines (100 loc) · 3.66 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
describe("Mongo Collection Naming", function() {
"use strict";
var should = require('should');
var util = require('util');
var async = require('async');
var SIS = require("../util/constants");
var TestUtil = require('./fixtures/util');
var LocalTest = new TestUtil.LocalTest();
var schemaManager = null;
before(function(done) {
LocalTest.start(function(err, mongoose) {
schemaManager = require("../util/schema-manager")(mongoose, { auth : true });
done(err);
});
});
after(function(done) {
LocalTest.stop(done);
});
describe("Schemas with plural and non plural", function() {
var schemas = [
{
name : "name_test_site",
owner : ["sistest"],
definition : {
name : "String",
short_name : "String"
}
},
{
name : "name_test_sites",
owner : ["sistest"],
definition : {
name : "String",
short_name : "String"
}
}
];
var entityManagers = { };
before(function() {
var opts = { };
opts[SIS.OPT_SCHEMA_MGR] = schemaManager;
opts[SIS.OPT_ID_FIELD] = '_id';
opts[SIS.OPT_USE_AUTH] = false;
schemas.forEach(function(schema) {
var model = schemaManager.getEntityModel(schema);
should.exist(model);
entityManagers[schema.name] = require('../util/entity-manager')(model, schema, opts);
});
});
it("should add 5 entities to each", function(done) {
var items = [1, 2, 3, 4, 5];
var tasks = schemas.map(function(s) {
var em = entityManagers[s.name];
var objs = items.map(function(num) {
return {
name : s.name + "_" + num,
short_name : s.name + "_short_" + num
};
});
return function(cb) {
async.map(objs, function(obj, ocb) {
em.add(obj).nodeify(ocb);
}, cb);
};
});
async.parallel(tasks, done);
});
it("should only have 5 entities in each", function(done) {
var tasks = schemas.map(function(s) {
var em = entityManagers[s.name];
return function(cb) {
em.model.find({}, function(err, res) {
should.not.exist(err);
res.length.should.eql(5);
cb(null, res);
});
};
});
async.parallel(tasks, done);
});
it("should have 2 different mongo collections with 5 items each", function(done) {
var mongoose = schemaManager.mongoose;
var db = mongoose.connection.db;
var tasks = schemas.map(function(s) {
return function(cb) {
db.collection(s.name, { strict : true }, function(err, collection) {
should.not.exist(err);
should.exist(collection);
collection.find().toArray(function(err, res) {
should.not.exist(err);
res.length.should.eql(5);
cb(null);
});
});
};
});
async.series(tasks, done);
});
});
});