Skip to content

Commit

Permalink
update travis w/new Database tests, will update tests to include old …
Browse files Browse the repository at this point in the history
…overhauled tests

ref #10
  • Loading branch information
maxgrossman committed Aug 5, 2018
1 parent b3c1743 commit 41a6aac
Show file tree
Hide file tree
Showing 16 changed files with 872 additions and 523 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
./node_modules
node_modules/
testData/
1 change: 0 additions & 1 deletion .python-version

This file was deleted.

8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
sudo: required

env:
- SPATIALITE_LOCATION=/usr/lib/x86_64-linux/gnu/mod_spatialite.so.7
- ENVIRONMENT=test

services:
- docker

before_install:
- docker build -t posm-paths .
- npm run clean-migrations && docker build -t posm-paths .

script:
- docker run posm-paths /bin/bash -c 'echo "UNIT TESTS GO HERE"'
- docker run posm-paths /bin/bash -c 'npm install --build-from-sources && SPATIALITE_LOCATION=/usr/lib/x86_64-linux-gnu ENVIRONMENT=test npm run test:migrate'
40 changes: 29 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
FROM ubuntu:14.04
FROM ubuntu:16.04

RUN mkdir /home/posm-paths
COPY ./ /home/posm-paths/

# nvm help -> https://gist.github.com/remarkablemark/aacf14c29b3f01d6900d13137b21db3a
# replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

# --- get curl and deps for building node. --- #
# update the repository sources list
# and install dependencies
RUN apt-get update \
&& apt-get install -yq curl \
build-essential \
sqlite3 \
libsqlite3-dev \
libspatialite-dev \

# -- specific node version -- #
RUN curl -sL https://deb.nodesource.com/setup_10.x \
&& apt-get install nodejs
&& apt-get install -y curl python make g++ libsqlite3-mod-spatialite \
&& apt-get -y autoclean

# nvm environment variables
ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION 10.7.0

# install nvm
# https://github.com/creationix/nvm#install-script
RUN curl --silent -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.2/install.sh | bash

# install node and npm
RUN source $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default

# add node and npm to path so the commands are available
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH

WORKDIR /home/posm-paths
29 changes: 0 additions & 29 deletions LICENSE

This file was deleted.

13 changes: 7 additions & 6 deletions db/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
const fs = require('fs-extra');
const sqlite3 = require('sqlite3').verbose();;
const config = require('../config');

Promise = require('bluebird');

class Database {
constructor() {
if (!Database.instance) {
this._spatialite = process.env.SPATIALITE_LOCATION;
this._dbLoc = config[process.env.ENVIRONMENT || 'develop'].db;
this._spatialite = process.env.SPATIALITE_LOCATION + '/mod_spatialite';
}
return Database.instance
};
Expand All @@ -18,14 +15,18 @@ class Database {
get db () {
return this._db;
}
connect() {
connect(dbLoc) {
try {
const db = new sqlite3.Database(this._dbLoc);
const db = new sqlite3.Database(dbLoc);
this._dbLoc = dbLoc;
this._db = Promise.promisifyAll(db);
} catch (error) {
throw error;
}
}
close() {
this._db.close();
}
execute(sql) {
return this._db
.execAsync(sql)
Expand Down
38 changes: 23 additions & 15 deletions db/migrations/1533377087768-add-users.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
'use strict'
'use strict';

const dbLoc = require('../../config')[process.env.ENVIRONMENT || 'test'].db;
const Database = require('../');

const fs = require('fs');
const path = require('path');
const upSQL = fs.readFileSync(path.join(__dirname, '..', 'sql', '1533377087768-add-users-up.sql')).toString();
const downSQL = fs.readFileSync(path.join(__dirname, '..', 'sql', '1533377087768-add-users-down.sql')).toString();
const readFile = require('fs-extra').readFile

const up = path.join(__dirname, '..', 'sql', '1533377087768-add-users-up.sql')
const down = path.join(__dirname, '..', 'sql', '1533377087768-add-users-down.sql')

const dbLoc = require('../../config')[process.env.ENVIRONMENT || 'develop'].db;
const Database = require('../');
Database.connect(dbLoc);

module.exports.up = function (next) {
Database.execute(upSQL)
.then(() => next())
.catch(error => { console.error(error); next(); });
exports.up = (next) => {
readFile(up).then(sql => {
Database
.execute(sql.toString())
.then(() => next())
.catch((err) => { throw err; });
});
};

module.exports.down = function (next) {
Database.execute(downSQL)
.then(() => next())
.catch(error => { console.error(error); next(); });
};
exports.down = (next) => {
readFile(down).then(sql => {
Database
.execute(sql.toString())
.then(() => next())
.catch((err) => { throw err; })
})
}
38 changes: 23 additions & 15 deletions db/migrations/1533377095426-add-sequences.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
'use strict'
'use strict';

const dbLoc = require('../../config')[process.env.ENVIRONMENT || 'test'].db;
const Database = require('../');

const fs = require('fs');
const path = require('path');
const upSQL = fs.readFileSync(path.join(__dirname, '..', 'sql', '1533377095426-add-sequences-up.sql')).toString();
const downSQL = fs.readFileSync(path.join(__dirname, '..', 'sql', '1533377095426-add-sequences-down.sql')).toString();
const readFile = require('fs-extra').readFile;

const up = path.join(__dirname, '..', 'sql', '1533377095426-add-sequences-up.sql')
const down = path.join(__dirname, '..', 'sql', '1533377095426-add-sequences-down.sql')

const dbLoc = require('../../config')[process.env.ENVIRONMENT || 'develop'].db;
const Database = require('../');
Database.connect(dbLoc);

module.exports.up = function (next) {
Database.execute(upSQL)
.then(() => next())
.catch(error => { console.error(error); next(); })
exports.up = (next) => {
readFile(up).then(sql => {
Database
.execute(sql.toString())
.then(() => next())
.catch((err) => { throw err; })
})
}

module.exports.down = function (next) {
Database.execute(downSQL)
.then(() => next())
.catch(error => { console.error(error); next(); })
}
exports.down = (next) => {
readFile(down).then(sql => {
Database
.execute(sql.toString())
.then(() => next())
.catch((err) => { throw err; })
})
}
38 changes: 23 additions & 15 deletions db/migrations/1533377102405-add-images.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
'use strict'
'use strict';

const dbLoc = require('../../config')[process.env.ENVIRONMENT || 'test'].db;
const Database = require('../');

const fs = require('fs');
const path = require('path');
const upSQL = fs.readFileSync(path.join(__dirname, '..', 'sql', '1533377102405-add-images-up.sql')).toString();
const downSQL = fs.readFileSync(path.join(__dirname, '..', 'sql', '1533377102405-add-images-down.sql')).toString();
const readFile = require('fs-extra').readFile;

const up = path.join(__dirname, '..', 'sql', '1533377102405-add-images-up.sql')
const down = path.join(__dirname, '..', 'sql', '1533377102405-add-images-down.sql')

const dbLoc = require('../../config')[process.env.ENVIRONMENT || 'develop'].db;
const Database = require('../');
Database.connect(dbLoc);

module.exports.up = function (next) {
Database.executeSpatial(upSQL)
.then(() => next())
.catch(error => { console.error(error); next(); })
exports.up = (next) => {
readFile(up).then(sql => {
Database
.executeSpatial(sql.toString())
.then(() => next())
.catch((err) => { throw err; })
})
}

module.exports.down = function (next) {
Database.executeSpatial(downSQL)
.then(() => next())
.catch(error => { console.error(error); next(); });
}
exports.down = (next) => {
readFile(down).then(sql => {
Database
.executeSpatial(sql.toString())
.then(() => next())
.catch((err) => { throw err; });
})
}
2 changes: 1 addition & 1 deletion db/seeds/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const users = require('../../testData/seeds').users;
const users = require('./users');
const uuidv4 = require('uuid/v4');
const dbLoc = require('../../config')[process.env.ENVIRONMENT || 'develop'].db;
const Database = require('../');
Expand Down
File renamed without changes.
Loading

0 comments on commit 41a6aac

Please sign in to comment.