@dhyasama/totem-models 12.9.0 → 12.10.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/lib/Organization.js +4 -3
- package/package.json +1 -1
- package/test/Organization.js +81 -0
package/lib/Organization.js
CHANGED
|
@@ -639,10 +639,11 @@ module.exports = function(mongoose, config) {
|
|
|
639
639
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
640
640
|
|
|
641
641
|
Organization.virtual('address.primary').get(function () {
|
|
642
|
-
var
|
|
643
|
-
|
|
642
|
+
var addresses = this && this.contact && this.contact.address ? this.contact.address : [];
|
|
643
|
+
var primary = _.find(addresses, function(address) {
|
|
644
|
+
return address && address.primary;
|
|
644
645
|
});
|
|
645
|
-
return primary
|
|
646
|
+
return primary || null;
|
|
646
647
|
});
|
|
647
648
|
|
|
648
649
|
Organization.virtual('board.all').get(function () {
|
package/package.json
CHANGED
package/test/Organization.js
CHANGED
|
@@ -1127,6 +1127,87 @@ describe('Organization', function() {
|
|
|
1127
1127
|
});
|
|
1128
1128
|
});
|
|
1129
1129
|
|
|
1130
|
+
it('finds the primary address for an org', function(done) {
|
|
1131
|
+
|
|
1132
|
+
var o = new Organization();
|
|
1133
|
+
o.name = 'Addressable';
|
|
1134
|
+
o.slug = 'addressable';
|
|
1135
|
+
o.website = 'addressable.org';
|
|
1136
|
+
|
|
1137
|
+
o.contact.address = [];
|
|
1138
|
+
o.contact.address.push({
|
|
1139
|
+
street: '1 Main Street',
|
|
1140
|
+
city: 'Portland',
|
|
1141
|
+
state: 'ME',
|
|
1142
|
+
country: 'USA',
|
|
1143
|
+
postalCode: '04101',
|
|
1144
|
+
primary: false
|
|
1145
|
+
});
|
|
1146
|
+
o.contact.address.push({
|
|
1147
|
+
street: '2 Center Street',
|
|
1148
|
+
city: 'Bangor',
|
|
1149
|
+
state: 'ME',
|
|
1150
|
+
country: 'USA',
|
|
1151
|
+
postalCode: '04412',
|
|
1152
|
+
primary: true
|
|
1153
|
+
});
|
|
1154
|
+
|
|
1155
|
+
Organization.upsert(o, 'test-user', function(err, org) {
|
|
1156
|
+
|
|
1157
|
+
should.not.exist(err);
|
|
1158
|
+
should.exist(org);
|
|
1159
|
+
|
|
1160
|
+
Organization.findById(org._id).lean({ virtuals: true })
|
|
1161
|
+
.then(function(result) {
|
|
1162
|
+
should.exist(result);
|
|
1163
|
+
should.exist(result.address);
|
|
1164
|
+
should.exist(result.address.primary);
|
|
1165
|
+
result.address.primary.postalCode.should.equal('04412');
|
|
1166
|
+
done();
|
|
1167
|
+
})
|
|
1168
|
+
.catch(done);
|
|
1169
|
+
|
|
1170
|
+
});
|
|
1171
|
+
|
|
1172
|
+
});
|
|
1173
|
+
|
|
1174
|
+
it('does not throw when contact is omitted from a lean projection', function(done) {
|
|
1175
|
+
|
|
1176
|
+
var o = new Organization();
|
|
1177
|
+
o.name = 'Projected';
|
|
1178
|
+
o.slug = 'projected';
|
|
1179
|
+
o.website = 'projected.org';
|
|
1180
|
+
|
|
1181
|
+
o.contact.address = [];
|
|
1182
|
+
o.contact.address.push({
|
|
1183
|
+
street: '10 Broad Street',
|
|
1184
|
+
city: 'New York',
|
|
1185
|
+
state: 'NY',
|
|
1186
|
+
country: 'USA',
|
|
1187
|
+
postalCode: '10004',
|
|
1188
|
+
primary: true
|
|
1189
|
+
});
|
|
1190
|
+
|
|
1191
|
+
Organization.upsert(o, 'test-user', function(err, org) {
|
|
1192
|
+
|
|
1193
|
+
should.not.exist(err);
|
|
1194
|
+
should.exist(org);
|
|
1195
|
+
|
|
1196
|
+
Organization.findById(org._id)
|
|
1197
|
+
.select('name')
|
|
1198
|
+
.lean({ virtuals: true })
|
|
1199
|
+
.then(function(result) {
|
|
1200
|
+
should.exist(result);
|
|
1201
|
+
should.exist(result.address);
|
|
1202
|
+
should.equal(result.address.primary, null);
|
|
1203
|
+
done();
|
|
1204
|
+
})
|
|
1205
|
+
.catch(done);
|
|
1206
|
+
|
|
1207
|
+
});
|
|
1208
|
+
|
|
1209
|
+
});
|
|
1210
|
+
|
|
1130
1211
|
it('cleans people', function (done) {
|
|
1131
1212
|
|
|
1132
1213
|
var littleDirtyOrg = new Organization();
|