-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsage.js
51 lines (45 loc) · 1.57 KB
/
sage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const _ = require('lodash');
const moment = require('moment');
const TestHelpers = require('./test_helpers');
const expect = require('chai').expect;
const User = require('./setup/models/user');
const Profile = require('./setup/models/profile');
const Post = require('./setup/models/post');
let sage = TestHelpers.sage;
sage.logger.transports.console.level = 'debug';
describe('sage basic methods', () => {
// Reset Db
before(() => TestHelpers.initdb().then(TestHelpers.connect));
it('should execute', () => {
const query = 'SELECT * FROM users';
return sage.execute(query).then(response => {
expect(response.length).to.equal(0);
});
});
});
// https://github.com/FoundationMedicineInc/oracle-sage/issues/34
describe('sage basic methods work with transactions', () => {
// Reset Db
before(() => TestHelpers.initdb().then(TestHelpers.connect));
it('should execute in the context of a transaction', done => {
sage = require('../build/sage');
const query = 'SELECT * FROM users';
return sage.transaction().then(t =>
sage
.execute(query, [], { transaction: t })
.then(response => {
expect(response.length).to.equal(0);
})
.then(() => User.create({ USERNAME: 'jpollard' }, { transaction: t }))
.then(() => sage.execute(query, [], { transaction: t }))
.then(response => {
expect(response.length).to.equal(1);
})
.then(() => t.commit().then(done))
.catch(err => {
console.log('err', err);
return t.rollback().then(done);
})
);
});
});