This repository has been archived by the owner on Mar 20, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f349ff6
commit bd08d92
Showing
8 changed files
with
93 additions
and
200 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["es2015"] | ||
} |
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 @@ | ||
node_modules |
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,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; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,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 | ||
} |
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,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'); | ||
}) | ||
}); | ||
|
||
}); |
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,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" | ||
} |