Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

Commit

Permalink
convert tests to js-based
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslantalpa committed May 5, 2017
1 parent f349ff6 commit bd08d92
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 200 deletions.
3 changes: 3 additions & 0 deletions .babelrc
@@ -0,0 +1,3 @@
{
"presets": ["es2015"]
}
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules
9 changes: 9 additions & 0 deletions db/src/sample_data/reset.sql
@@ -0,0 +1,9 @@
BEGIN;
\set QUIET on
\set ON_ERROR_STOP on
set client_min_messages to warning;
truncate data.subitems restart identity cascade;
truncate data.items restart identity cascade;
truncate data.users restart identity cascade;
\ir data.sql
COMMIT;
14 changes: 0 additions & 14 deletions openresty/tests/all.sh

This file was deleted.

186 changes: 0 additions & 186 deletions openresty/tests/assert.sh

This file was deleted.

32 changes: 32 additions & 0 deletions openresty/tests/common.js
@@ -0,0 +1,32 @@
import {config} from 'dotenv';
import {spawnSync} from 'child_process';
// var execSync = require('child_process').execSync;
const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJyb2xlIjoid2VidXNlciJ9.vAN3uJSleb2Yj8RVPRsb1UBkokqmKlfl6lJ2bg3JfFg'
const request = require('supertest');

config();//.env file vars added to process.env
const COMPOSE_PROJECT_NAME = process.env.COMPOSE_PROJECT_NAME;
const POSTGRES_USER = process.env.POSTGRES_USER;
const POSTGRES_PASSWORD = process.env.POSTGRES_PASSWORD;
const SUPER_USER = process.env.SUPER_USER;
const SUPER_USER_PASSWORD = process.env.SUPER_USER_PASSWORD;

const DB_HOST = process.env.DB_HOST;
const DB_NAME = process.env.DB_NAME;
const PG = `${COMPOSE_PROJECT_NAME}_db_1`

var rest_service = function() {
return request('http://localhost:8080/rest');
}

const resetdb = () => {
const pg = spawnSync('docker', ['exec', PG, 'psql', '-U', SUPER_USER, DB_NAME, '-f', 'docker-entrypoint-initdb.d/sample_data/reset.sql'])
// console.log (pg.stdout.toString('utf8') )
// console.log (pg.stderr.toString('utf8') )
}

module.exports = {
jwt: jwt,
resetdb: resetdb,
rest_service: rest_service
}
29 changes: 29 additions & 0 deletions openresty/tests/rest/read.js
@@ -0,0 +1,29 @@
import {rest_service, jwt, resetdb} from '../common.js';
const request = require('supertest');
const should = require("should");

describe('read', function() {
after(function(done){ resetdb(); done(); });

it('basic', function(done) {
rest_service()
.get('/items?id=eq.1')
.expect('Content-Type', /json/)
.expect(200, done)
.expect( r => {
r.body.length.should.equal(1);
r.body[0].id.should.equal(1);
})
});

it('by primary key', function(done) {
rest_service()
.get('/items/1?select=id,name')
.expect(200, done)
.expect( r => {
r.body.id.should.equal(1);
r.body.name.should.equal('item_1');
})
});

});
19 changes: 19 additions & 0 deletions package.json
@@ -0,0 +1,19 @@
{
"name": "starter-kit",
"dependencies": {},
"devDependencies": {
"babel-core": "^6.24.0",
"babel-preset-latest": "^6.24.1",
"dotenv": "4.0.0",
"mocha": "^3.2.0",
"should": "^11.2.0",
"supertest": "^3.0.0"
},
"scripts": {
"test_rest": "mocha --compilers js:babel-core/register ./openresty/tests/rest/",
"test_db": "( source .env && docker run -i -t --rm --name pgtap --network ${COMPOSE_PROJECT_NAME}_default --link ${COMPOSE_PROJECT_NAME}_db_1:db -v $(pwd)/db/tests/:/test -e DATABASE=$DB_NAME -e USER=$SUPER_USER -e PASSWORD=$SUPER_USER_PASSWORD lren/pgtap )",
"test": "npm run test_db && npm run test_rest"
},
"author": "ruslan.talpa@subzero.cloud",
"license": "ISC"
}

0 comments on commit bd08d92

Please sign in to comment.