@dhyasama/totem-models 2.6.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.npmignore +14 -0
- package/lib/Interaction.js +14 -0
- package/lib/Organization.js +9 -9
- package/package-lock.json +1163 -0
- package/package.json +1 -1
- package/test/Interaction.js +162 -0
package/package.json
CHANGED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var
|
|
4
|
+
|
|
5
|
+
should = require("should"),
|
|
6
|
+
_ = require('underscore'),
|
|
7
|
+
config = require('./config')['test'],
|
|
8
|
+
mongoose = require('mongoose'),
|
|
9
|
+
moment = require('moment'),
|
|
10
|
+
clearDB = require('mocha-mongoose')(config.db.uri, {noClear: true}),
|
|
11
|
+
Interaction = mongoose.model('Interaction');
|
|
12
|
+
|
|
13
|
+
var totemCustomerId1 = new mongoose.Types.ObjectId();
|
|
14
|
+
var totemCustomerId2 = new mongoose.Types.ObjectId();
|
|
15
|
+
var externalAttendee1 = new mongoose.Types.ObjectId();
|
|
16
|
+
var externalAttendee2 = new mongoose.Types.ObjectId();
|
|
17
|
+
|
|
18
|
+
describe.only('Interaction', function() {
|
|
19
|
+
|
|
20
|
+
before(function(done) {
|
|
21
|
+
if (mongoose.connection.db) return done();
|
|
22
|
+
mongoose.connect(config.db.uri, done);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
before(function(done) {
|
|
26
|
+
clearDB(done);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// calendarEventId: { type: Schema.ObjectId, ref: 'CalendarEvent', required: true }, // the event from the original pull
|
|
30
|
+
// providerEventId: { type: String, required: true, index: true, trim: true }, // unique id from the calendar provider
|
|
31
|
+
// totemCustomerId: { type: Schema.ObjectId, ref: 'Organization', index: true, required: true },
|
|
32
|
+
// summary: { type: String, required: true, trim: true },
|
|
33
|
+
// startTime: { type: Date, index: true },
|
|
34
|
+
// recurring: { type: Boolean, default: false },
|
|
35
|
+
// attendees: {
|
|
36
|
+
// internal: [{ type: Schema.ObjectId, ref: 'Person', index: true }], // people from customer
|
|
37
|
+
// external: [{ type: Schema.ObjectId, ref: 'Person', index: true }] // everyone else
|
|
38
|
+
// },
|
|
39
|
+
// notes: [ { type: Schema.ObjectId, ref: 'Note' } ]
|
|
40
|
+
|
|
41
|
+
it('creates an interaction', function(done) {
|
|
42
|
+
|
|
43
|
+
var interaction = new Interaction({
|
|
44
|
+
calendarEventId: new mongoose.Types.ObjectId(),
|
|
45
|
+
providerEventId: 'abc124',
|
|
46
|
+
totemCustomerId: totemCustomerId1,
|
|
47
|
+
startTime: new Date(),
|
|
48
|
+
summary: 'test 1',
|
|
49
|
+
attendees: {
|
|
50
|
+
external: [externalAttendee1]
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
Interaction.upsert(interaction, function(err, result) {
|
|
55
|
+
should.not.exist(err);
|
|
56
|
+
should.exist(result);
|
|
57
|
+
done();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('creates another interaction', function(done) {
|
|
63
|
+
|
|
64
|
+
var interaction = new Interaction({
|
|
65
|
+
calendarEventId: new mongoose.Types.ObjectId(),
|
|
66
|
+
providerEventId: 'abc124',
|
|
67
|
+
totemCustomerId: totemCustomerId2,
|
|
68
|
+
startTime: new Date(),
|
|
69
|
+
summary: 'test 2',
|
|
70
|
+
attendees: {
|
|
71
|
+
external: [externalAttendee2]
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
Interaction.upsert(interaction, function(err, result) {
|
|
76
|
+
should.not.exist(err);
|
|
77
|
+
should.exist(result);
|
|
78
|
+
done();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('gets interactions for a person', function(done) {
|
|
84
|
+
|
|
85
|
+
config.CUSTOMER_ID = totemCustomerId1;
|
|
86
|
+
|
|
87
|
+
Interaction.getForPeople([externalAttendee1], { before: moment().add(1, 'hour').toISOString()}, function(err, result) {
|
|
88
|
+
should.not.exist(err);
|
|
89
|
+
should.exist(result);
|
|
90
|
+
result.length.should.equal(1);
|
|
91
|
+
result[0].summary.should.equal('test 1');
|
|
92
|
+
done();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('tries to get interactions for a person as an admin process', function(done) {
|
|
98
|
+
|
|
99
|
+
config.CUSTOMER_ID = 'GLOBAL_PROCESS';
|
|
100
|
+
|
|
101
|
+
Interaction.getForPeople([externalAttendee1], { before: moment().add(1, 'hour').toISOString()}, function(err, result) {
|
|
102
|
+
should.exist(err);
|
|
103
|
+
should.not.exist(result);
|
|
104
|
+
done();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('gets interactions for a person as an admin process', function(done) {
|
|
110
|
+
|
|
111
|
+
config.CUSTOMER_ID = totemCustomerId2;
|
|
112
|
+
|
|
113
|
+
Interaction.getForPeople([externalAttendee2], { before: moment().add(1, 'hour').toISOString()}, function(err, result) {
|
|
114
|
+
should.not.exist(err);
|
|
115
|
+
should.exist(result);
|
|
116
|
+
result.length.should.equal(1);
|
|
117
|
+
result[0].summary.should.equal('test 2');
|
|
118
|
+
done();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('gets interactions for a customer', function(done) {
|
|
124
|
+
|
|
125
|
+
config.CUSTOMER_ID = totemCustomerId2;
|
|
126
|
+
|
|
127
|
+
var interaction = new Interaction({
|
|
128
|
+
calendarEventId: new mongoose.Types.ObjectId(),
|
|
129
|
+
providerEventId: 'abc124',
|
|
130
|
+
totemCustomerId: totemCustomerId2,
|
|
131
|
+
startTime: new Date(),
|
|
132
|
+
summary: 'test 3',
|
|
133
|
+
attendees: {
|
|
134
|
+
external: [new mongoose.Types.ObjectId()]
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
Interaction.upsert(interaction, function(err, result) {
|
|
139
|
+
|
|
140
|
+
should.not.exist(err);
|
|
141
|
+
should.exist(result);
|
|
142
|
+
|
|
143
|
+
Interaction.getForCustomer(totemCustomerId2, null, function(err, result) {
|
|
144
|
+
|
|
145
|
+
should.not.exist(err);
|
|
146
|
+
should.exist(result);
|
|
147
|
+
result.length.should.equal(2);
|
|
148
|
+
|
|
149
|
+
Interaction.getForCustomer(totemCustomerId1, null, function(err, result) {
|
|
150
|
+
should.not.exist(err);
|
|
151
|
+
should.exist(result);
|
|
152
|
+
result.length.should.equal(1);
|
|
153
|
+
done();
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
});
|