ogm
Version:
OGM for OrientDB
228 lines (168 loc) • 7.92 kB
JavaScript
;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _bluebird = require('bluebird');
var _bluebird2 = _interopRequireDefault(_bluebird);
var _specModelsPerson = require('./spec.models/Person');
var _specModelsPerson2 = _interopRequireDefault(_specModelsPerson);
var _specModelsTerritory = require('./spec.models/Territory');
var _specModelsTerritory2 = _interopRequireDefault(_specModelsTerritory);
var _specModelsIsPartOf = require('./spec.models/IsPartOf');
var _specModelsIsPartOf2 = _interopRequireDefault(_specModelsIsPartOf);
describe("Vertex", function () {
before(function callee$1$0() {
return regeneratorRuntime.async(function callee$1$0$(context$2$0) {
while (1) switch (context$2$0.prev = context$2$0.next) {
case 0:
context$2$0.next = 2;
return regeneratorRuntime.awrap(CREATE_TEST_DB(this, 'testdb_Vertex').bind(this));
case 2:
context$2$0.next = 4;
return regeneratorRuntime.awrap(_bluebird2['default'].map(['CREATE CLASS Person EXTENDS V', 'CREATE CLASS Territory EXTENDS V', 'CREATE CLASS IsPartOf EXTENDS E', 'CREATE PROPERTY IsPartOf.in LINK Territory', 'CREATE PROPERTY IsPartOf.out LINK Territory', 'ALTER PROPERTY IsPartOf.out MANDATORY=true', 'ALTER PROPERTY IsPartOf.in MANDATORY=true', 'INSERT INTO Territory SET name = "Frisia"', 'INSERT INTO Territory SET name = "Lotharingia"', 'INSERT INTO Territory SET name = "Bavaria"', 'INSERT INTO Territory SET name = "Germany"', 'INSERT INTO Territory SET name = "Holy Roman Empire"', 'CREATE EDGE IsPartOf FROM (SELECT FROM Territory WHERE name = "Frisia") TO (SELECT FROM Territory WHERE name="Holy Roman Empire")', 'CREATE EDGE IsPartOf FROM (SELECT FROM Territory WHERE name = "Lotharingia") TO (SELECT FROM Territory WHERE name="Holy Roman Empire")', 'CREATE EDGE IsPartOf FROM (SELECT FROM Territory WHERE name = "Bavaria") TO (SELECT FROM Territory WHERE name="Holy Roman Empire")', 'CREATE EDGE IsPartOf FROM (SELECT FROM Territory WHERE name = "Germany") TO (SELECT FROM Territory WHERE name="Holy Roman Empire")'], this.db.query.bind(this.db)));
case 4:
case 'end':
return context$2$0.stop();
}
}, null, this);
});
// await Person.sync()
after(function callee$1$0() {
return regeneratorRuntime.async(function callee$1$0$(context$2$0) {
while (1) switch (context$2$0.prev = context$2$0.next) {
case 0:
context$2$0.next = 2;
return regeneratorRuntime.awrap(DELETE_TEST_DB('testdb_Vertex'));
case 2:
case 'end':
return context$2$0.stop();
}
}, null, this);
});
var newRid, t1;
it('should be able to save an new instance', function callee$1$0() {
var p1, result;
return regeneratorRuntime.async(function callee$1$0$(context$2$0) {
while (1) switch (context$2$0.prev = context$2$0.next) {
case 0:
p1 = new _specModelsPerson2['default']({ name: "Gholi" });
expect(p1.name).to.eql("Gholi");
context$2$0.next = 4;
return regeneratorRuntime.awrap(p1.save());
case 4:
expect(p1).to.have.property('@rid');
newRid = p1['@rid'];
context$2$0.next = 8;
return regeneratorRuntime.awrap(_specModelsPerson2['default'].query().all());
case 8:
result = context$2$0.sent;
expect(result).to.have.length(1);
expect(result[0]).to.be.an['instanceof'](_specModelsPerson2['default']);
expect(result[0].name).to.eql("Gholi");
expect(result[0].name).to.eql("Gholi");
case 13:
case 'end':
return context$2$0.stop();
}
}, null, this);
});
it('should be able to query and update an instance', function callee$1$0() {
var p1, rid, result;
return regeneratorRuntime.async(function callee$1$0$(context$2$0) {
while (1) switch (context$2$0.prev = context$2$0.next) {
case 0:
context$2$0.next = 2;
return regeneratorRuntime.awrap(_specModelsPerson2['default'].query({ name: 'Gholi' }).one());
case 2:
p1 = context$2$0.sent;
expect(p1).to.be.an['instanceof'](_specModelsPerson2['default']);
expect(p1.name).to.eql("Gholi");
rid = p1['@rid'];
p1.name = 'Taghi';
context$2$0.next = 9;
return regeneratorRuntime.awrap(p1.save());
case 9:
expect(p1['@rid']).to.eql(rid);
expect(p1.name).to.eql('Taghi');
context$2$0.next = 13;
return regeneratorRuntime.awrap(_specModelsPerson2['default'].query().all());
case 13:
result = context$2$0.sent;
expect(result).to.have.length(1);
expect(result[0].name).to.eql("Taghi");
case 16:
case 'end':
return context$2$0.stop();
}
}, null, this);
});
it('should be able to get and delete an instance', function callee$1$0() {
var p1, result;
return regeneratorRuntime.async(function callee$1$0$(context$2$0) {
while (1) switch (context$2$0.prev = context$2$0.next) {
case 0:
context$2$0.next = 2;
return regeneratorRuntime.awrap(_specModelsPerson2['default'].get(newRid));
case 2:
p1 = context$2$0.sent;
expect(p1).to.be.an['instanceof'](_specModelsPerson2['default']);
expect(p1.name).to.eql("Taghi");
context$2$0.next = 7;
return regeneratorRuntime.awrap(p1['delete']());
case 7:
context$2$0.next = 9;
return regeneratorRuntime.awrap(_specModelsPerson2['default'].query().all());
case 9:
result = context$2$0.sent;
expect(result).to.have.length(0);
case 11:
case 'end':
return context$2$0.stop();
}
}, null, this);
});
it('should be able to get all vertexes have link with specific edge', function callee$1$0() {
var p1, subTerritories;
return regeneratorRuntime.async(function callee$1$0$(context$2$0) {
while (1) switch (context$2$0.prev = context$2$0.next) {
case 0:
context$2$0.next = 2;
return regeneratorRuntime.awrap(_specModelsTerritory2['default'].query({ 'name': 'Holy Roman Empire' }).one());
case 2:
p1 = context$2$0.sent;
expect(p1).to.be.an['instanceof'](_specModelsTerritory2['default']);
expect(p1.name).to.eql('Holy Roman Empire');
context$2$0.next = 7;
return regeneratorRuntime.awrap(p1.inV(_specModelsIsPartOf2['default']).all());
case 7:
subTerritories = context$2$0.sent;
expect(subTerritories).to.have.length(4);
t1 = subTerritories[0];
expect(subTerritories[0]).to.be.an['instanceof'](_specModelsTerritory2['default']);
expect(subTerritories.map(function (t) {
return t.name;
})).to.have.members(['Frisia', 'Lotharingia', 'Germany', 'Bavaria']);
case 12:
case 'end':
return context$2$0.stop();
}
}, null, this);
});
it('should be able to delete an instance by rid', function callee$1$0() {
var result;
return regeneratorRuntime.async(function callee$1$0$(context$2$0) {
while (1) switch (context$2$0.prev = context$2$0.next) {
case 0:
context$2$0.next = 2;
return regeneratorRuntime.awrap(_specModelsTerritory2['default']['delete'](t1['@rid']));
case 2:
context$2$0.next = 4;
return regeneratorRuntime.awrap(_specModelsTerritory2['default'].query().all());
case 4:
result = context$2$0.sent;
expect(result).to.have.length(4);
case 6:
case 'end':
return context$2$0.stop();
}
}, null, this);
});
});