@dhyasama/totem-models 12.28.0 → 12.29.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.
@@ -218,7 +218,8 @@ module.exports = function(mongoose, config) {
218
218
  },
219
219
 
220
220
  inbound: {
221
- active: { type: Boolean, default: false }
221
+ active: { type: Boolean, default: false },
222
+ forward: [{ type: String, trim: true, lowercase: true }]
222
223
  },
223
224
 
224
225
  carta: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "12.28.0",
3
+ "version": "12.29.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",
@@ -130,6 +130,39 @@ describe('Financials', function() {
130
130
 
131
131
  });
132
132
 
133
+ it('getOrCreateByOrg returns one document under concurrent calls', async function() {
134
+
135
+ var customer = new mongoose.Types.ObjectId();
136
+ var org = new mongoose.Types.ObjectId();
137
+
138
+ // mirror production's unique index so the losing writer of a race can never insert a duplicate
139
+ await Financials.collection.createIndex({ customer: 1, organization: 1 }, { unique: true });
140
+
141
+ var results = await Promise.all(
142
+ Array.from({ length: 10 }, function() { return Financials.getOrCreateByOrg(customer, org); })
143
+ );
144
+
145
+ var ids = new Set(results.map(function(r) { return r._id.toString(); }));
146
+ ids.size.should.equal(1);
147
+
148
+ var count = await Financials.countDocuments({ customer: customer, organization: org });
149
+ count.should.equal(1);
150
+
151
+ });
152
+
153
+ it('getOrCreateByOrg returns the existing document', function(done) {
154
+
155
+ Financials.getOrCreateByOrg(customerA, orgA, function(err, result) {
156
+ should.not.exist(err);
157
+ should.exist(result);
158
+ result.customer.toString().should.equal(customerA.toString());
159
+ result.organization.toString().should.equal(orgA.toString());
160
+ should.exist(result.asOfDate); // proves it found the doc created above, not a fresh one
161
+ done();
162
+ });
163
+
164
+ });
165
+
133
166
  describe.skip('old so skip for now', function() {
134
167
 
135
168
  it('gets financials for an org', function(done) {