diff --git a/.travis.yml b/.travis.yml index bb3e6dd..1fb7d60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,10 +9,16 @@ - sed -e 's/exports.testmode = false/exports.testmode = true/g' config.js > foo - mv foo config.js - cat config.js + - sudo service postgresql stop + - sudo service postgresql start 9.3 + - psql --version - "echo create database blobvault as user postgres" - psql -c 'create database blobvault;' -U postgres + - psql -d blobvault -c "\conninfo" -U postgres - node migration.js - ./node_modules/knex/lib/bin/cli.js migrate:latest - "echo make test script executable" - chmod +x test.sh - "echo End of before script" +addons: + postgresql: 9.3 diff --git a/api/attestation/phone.js b/api/attestation/phone.js index 9cb2860..924dc96 100644 --- a/api/attestation/phone.js +++ b/api/attestation/phone.js @@ -30,6 +30,7 @@ exports.get = function(req,res,next) { var phoneNumber = normalizePhone(req.body.phone.country_code, req.body.phone.number); exports.store.getPhoneAttestation(identity_id, phoneNumber, function(resp){ + console.log("GetPhoneAttestation Response:", resp) if (resp.error) { response.json({result:'error', message:'attestation DB error'}).status(500).pipe(res); @@ -78,10 +79,13 @@ exports.update = function (req, res, next) { var identity_id = req.params.identity_id; var phoneNumber = normalizePhone(req.body.phone.country_code, req.body.phone.number); var q = new Queue; + + console.log("attestation:phone:update:identity_id", identity_id,"phoneNumber:", phoneNumber) q.series([ function(lib) { exports.store.getPhoneAttestation(identity_id, phoneNumber, function(resp){ + console.log("update:getPhoneAttestation:", resp) if (resp.error) { response.json({result:'error', message:'attestation DB error'}).status(500).pipe(res); lib.terminate(); @@ -181,6 +185,7 @@ exports.update = function (req, res, next) { }; exports.store.insert_or_update_where(options, function(db_resp) { + console.log("inert_or_update_where:resp:", db_resp) if (db_resp.error) { response.json({result:'error', message:'attestation database error'}).status(500).pipe(res); lib.terminate(); @@ -248,4 +253,4 @@ var normalizePhone = function (country, number) { return normalized; } - \ No newline at end of file + diff --git a/lib/dbcommon.js b/lib/dbcommon.js index db642c4..892bec7 100644 --- a/lib/dbcommon.js +++ b/lib/dbcommon.js @@ -276,6 +276,7 @@ var dbcommon = function(db) { .select() .nodeify(function(err, resp) { if (err) { + console.log("The real error is:", err) cb({error:new Error('Attestation DB error')}); } else { cb(resp); diff --git a/test.sh b/test.sh index 13046aa..6dc6d1b 100755 --- a/test.sh +++ b/test.sh @@ -14,4 +14,5 @@ node_modules/.bin/mocha --ui tdd -R spec test/test-guard-requests.js && node_modules/.bin/mocha --ui tdd -R spec test/test-profile-details.js && node_modules/.bin/mocha --ui tdd -R spec test/test-2fa.js && node_modules/.bin/mocha --ui tdd -R spec test/test-attestation.js && +node test/test-json.js && node test/test-libutils.js diff --git a/test/test-attestation.js b/test/test-attestation.js index a116f7f..cc70e75 100644 --- a/test/test-attestation.js +++ b/test/test-attestation.js @@ -375,7 +375,6 @@ describe('Attestation:', function() { }); }); - var validAttestation = function (attestation) { var utils = require('../lib/utils'); @@ -395,4 +394,4 @@ var validAttestation = function (attestation) { } return true; -}; \ No newline at end of file +}; diff --git a/test/test-json.js b/test/test-json.js new file mode 100644 index 0000000..cddb4e1 --- /dev/null +++ b/test/test-json.js @@ -0,0 +1,40 @@ +var config = require('../config'); +var store = require('../lib/store')(config.dbtype); +var assert = require('assert') + +var QL = require('queuelib') + +var q = new QL; + +q.series([ +function(lib) { + store.db.raw('select version()').then(function(resp) { + console.log("VERSION:", resp) + lib.done(); + }); +}, +function(lib) { + store.db('attestations') + .truncate() + .then(function() { + return store.db('attestations') + .insert({id:'catcat',payload:{foo:'bar',life:42,animal:{cat:'gabby'}}}) + }) + .then(function() { + lib.done() + }); +}, +function(lib) { + store.db('attestations') + .whereRaw("payload->>'life' = ?", 42) + .select() + .then(function(resp) { + assert.equal(84,resp[0].payload.life*2) + assert.equal('gabby',resp[0].payload.animal.cat) + console.log("all done") + lib.done() + process.exit() + }) +} +]) +