Remove direct mongo access from Schema.spec.js.
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
var Config = require('../src/Config');
|
var Config = require('../src/Config');
|
||||||
var Schema = require('../src/Schema');
|
var Schema = require('../src/Schema');
|
||||||
var dd = require('deep-diff');
|
var dd = require('deep-diff');
|
||||||
@@ -512,24 +514,31 @@ describe('Schema', () => {
|
|||||||
it('drops related collection when deleting relation field', done => {
|
it('drops related collection when deleting relation field', done => {
|
||||||
var obj1 = hasAllPODobject();
|
var obj1 = hasAllPODobject();
|
||||||
obj1.save()
|
obj1.save()
|
||||||
.then(savedObj1 => {
|
.then(savedObj1 => {
|
||||||
var obj2 = new Parse.Object('HasPointersAndRelations');
|
var obj2 = new Parse.Object('HasPointersAndRelations');
|
||||||
obj2.set('aPointer', savedObj1);
|
obj2.set('aPointer', savedObj1);
|
||||||
var relation = obj2.relation('aRelation');
|
var relation = obj2.relation('aRelation');
|
||||||
relation.add(obj1);
|
relation.add(obj1);
|
||||||
return obj2.save();
|
return obj2.save();
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => config.database.collectionExists('_Join:aRelation:HasPointersAndRelations'))
|
||||||
config.database.adapter.database.collection('test__Join:aRelation:HasPointersAndRelations', { strict: true }, (err, coll) => {
|
.then(exists => {
|
||||||
expect(err).toEqual(null);
|
if (!exists) {
|
||||||
config.database.loadSchema()
|
fail('Relation collection should exist after save.');
|
||||||
.then(schema => schema.deleteField('aRelation', 'HasPointersAndRelations', config.database))
|
}
|
||||||
.then(() => config.database.adapter.database.collection('test__Join:aRelation:HasPointersAndRelations', { strict: true }, (err, coll) => {
|
})
|
||||||
expect(err).not.toEqual(null);
|
.then(() => config.database.loadSchema())
|
||||||
done();
|
.then(schema => schema.deleteField('aRelation', 'HasPointersAndRelations', config.database))
|
||||||
}));
|
.then(() => config.database.collectionExists('_Join:aRelation:HasPointersAndRelations'))
|
||||||
|
.then(exists => {
|
||||||
|
if (exists) {
|
||||||
|
fail('Relation collection should not exist after deleting relation field.');
|
||||||
|
}
|
||||||
|
done();
|
||||||
|
}, error => {
|
||||||
|
fail(error);
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can delete string fields and resave as number field', done => {
|
it('can delete string fields and resave as number field', done => {
|
||||||
|
|||||||
@@ -30,8 +30,12 @@ export class MongoStorageAdapter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
dropCollection(name: string) {
|
collectionExists(name: string) {
|
||||||
return this.connect.then(() => this.collection(name).then(collection => collection.drop()));
|
return this.connect().then(() => {
|
||||||
|
return this.database.listCollections({ name: name }).toArray();
|
||||||
|
}).then(collections => {
|
||||||
|
return collections.length > 0;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
dropCollection(name: string) {
|
dropCollection(name: string) {
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ DatabaseController.prototype.collection = function(className) {
|
|||||||
return this.rawCollection(className);
|
return this.rawCollection(className);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DatabaseController.prototype.collectionExists = function(className) {
|
||||||
|
return this.adapter.collectionExists(this.collectionPrefix + className);
|
||||||
|
};
|
||||||
|
|
||||||
DatabaseController.prototype.rawCollection = function(className) {
|
DatabaseController.prototype.rawCollection = function(className) {
|
||||||
return this.adapter.collection(this.collectionPrefix + className);
|
return this.adapter.collection(this.collectionPrefix + className);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user