This repository has been archived by the owner on Apr 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from LucianoPAlmeida/v1.0.0
V1.0.0
- Loading branch information
Showing
11 changed files
with
1,296 additions
and
482 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
'use strict'; | ||
|
||
const test = require('tape'); | ||
const { OGMNeoOperation, OGMNeoOperationBuilder } = require('../lib/ogmneo-operation'); | ||
const OGMNeoOperationExecuter = require('../lib/ogmneo-operation-executer'); | ||
const OGMNeoNode = require('../lib/ogmneo-node'); | ||
const OGMNeo = require('../lib/ogmneo'); | ||
const OGMNeoQuery = require('../lib/ogmneo-query'); | ||
const OGMNeoWhere = require('../lib/ogmneo-where'); | ||
|
||
const _ = require('lodash'); | ||
|
||
test('Test Invalid Operation', (assert) => { | ||
OGMNeoOperationExecuter.execute({}).catch((error) => { | ||
assert.equal(error.message, 'The operation must be a instance of ogmneo.Operation'); | ||
assert.end(); | ||
}); | ||
}); | ||
|
||
//Testing OGMNeoOperationExecuter.write | ||
test('Test write type on operation', (assert) => { | ||
let create = OGMNeoNode.createOperation({name: 'Ayrton Senna', carNumber: 12 }, 'Person'); | ||
OGMNeoOperationExecuter.write((transaction) => { | ||
return OGMNeoOperationExecuter.execute(create, transaction) | ||
.then((created) => { | ||
assert.equal(created.name, 'Ayrton Senna'); | ||
assert.equal(created.carNumber, 12); | ||
let id = created.id; | ||
created.carNumber = 1; | ||
let update = OGMNeoNode.updateOperation(created); | ||
return OGMNeoOperationExecuter.execute(update, transaction); | ||
}); | ||
}).then((result) => { | ||
assert.equal(result.name, 'Ayrton Senna'); | ||
assert.equal(result.carNumber, 1); | ||
assert.end(); | ||
}); | ||
}); | ||
|
||
test('Test batch write type operations', (assert) => { | ||
let createUser1 = OGMNeoNode.createOperation({name: 'Ayrton Senna'}, 'Person'); | ||
let createUser2 = OGMNeoNode.createOperation({name: 'Alain Prost'}, 'Person'); | ||
|
||
OGMNeoOperationExecuter.batchWriteOperations([createUser1, createUser2]).then((result) => { | ||
let created1 = result[0]; | ||
let created2 = result[1]; | ||
assert.notEqual(created1.id, undefined); | ||
assert.equal(created1.name, 'Ayrton Senna'); | ||
assert.notEqual(created2.id, undefined); | ||
assert.equal(created2.name, 'Alain Prost'); | ||
assert.end(); | ||
}); | ||
}); | ||
|
||
test('Test batch read type operations', (assert) => { | ||
let query1 = OGMNeoNode.findOneOperation(OGMNeoQuery.create('Person').where(OGMNeoWhere.create('name', { $eq: 'Ayrton Senna' }))); | ||
let query2 = OGMNeoNode.findOneOperation(OGMNeoQuery.create('Person').where(OGMNeoWhere.create('name', { $eq: 'Alain Prost' }))); | ||
|
||
OGMNeoOperationExecuter.batchReadOperations([query1, query2]).then((result) => { | ||
let found1 = result[0]; | ||
let found2 = result[1]; | ||
assert.notEqual(found1.id, undefined); | ||
assert.equal(found1.name, 'Ayrton Senna'); | ||
assert.notEqual(found2.id, undefined); | ||
assert.equal(found2.name, 'Alain Prost'); | ||
assert.end(); | ||
}); | ||
}); | ||
|
||
test('Test validate batch operations', (assert) => { | ||
let query1 = OGMNeoNode.findOneOperation(OGMNeoQuery.create('Person').where(OGMNeoWhere.create('name', { $eq: 'Ayrton Senna' }))); | ||
|
||
assert.throws(() => { | ||
OGMNeoOperationExecuter._validateOperations('',OGMNeoOperation.READ); | ||
}, /The parameter operations must be an array/); | ||
|
||
assert.throws(() => { | ||
OGMNeoOperationExecuter._validateOperations([''],OGMNeoOperation.READ); | ||
}, /The parameter operations must be an array that contains only instances of ogmneo.Operation/); | ||
|
||
assert.throws(() => { | ||
OGMNeoOperationExecuter._validateOperations([query1], OGMNeoOperation.WRITE); | ||
}, /The parameter operations must be an array that contains only instances of ogmneo.Operation that have type : WRITE/); | ||
assert.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
const test = require('tape'); | ||
const { OGMNeoOperation, OGMNeoOperationBuilder } = require('../lib/ogmneo-operation'); | ||
const _ = require('lodash'); | ||
|
||
test('Test create operation', (assert) => { | ||
let operation = OGMNeoOperationBuilder.create() | ||
.cypher('CREATE (n:Label {property: {property}}) RETURN n') | ||
.object({property: 'value'}) | ||
.type(OGMNeoOperation.READ) | ||
.then((result) => { | ||
return { id: 1, property: 'value' } | ||
}).build(); | ||
|
||
assert.equal(operation.cypher, 'CREATE (n:Label {property: {property}}) RETURN n'); | ||
assert.equal(operation.type, OGMNeoOperation.READ); | ||
assert.deepEqual(operation.object, {property: 'value'} ); | ||
assert.true(_.isFunction(operation.then), 'Then is not a function'); | ||
|
||
assert.end(); | ||
}); | ||
|
||
test('Test operation convenience methods', (assert) => { | ||
let operation = OGMNeoOperationBuilder.create() | ||
.cypher('CREATE (n:Label {property: {property}}) RETURN n') | ||
.object({property: 'value'}) | ||
.type(OGMNeoOperation.READ) | ||
.then((result)=> { | ||
return { id: 1, property: 'value' } | ||
}).build(); | ||
assert.true(operation.isReadType, 'Then is not a read operation'); | ||
assert.false(operation.isWriteType, 'Then is not a write operation'); | ||
assert.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.