-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
5 changed files
with
65 additions
and
12 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
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
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
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
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 |
---|---|---|
|
@@ -6,8 +6,13 @@ var dbConn = require('./test_pg_client.js'); | |
var db = require('../lib/db_handlers.js'); | ||
var schema = require('../example_schema.js'); | ||
|
||
var client = dbConn.client; | ||
|
||
var multipleSchema = [{ | ||
table_name: 'table_1', // eslint-disable-line | ||
fields: { field: { type: 'string', email: true } } | ||
}, { | ||
table_name: 'table_2', // eslint-disable-line | ||
fields: { field: { type: 'string', email: true } } | ||
}]; | ||
|
||
var testInsert = { | ||
email: '[email protected]', | ||
|
@@ -16,17 +21,17 @@ var testInsert = { | |
}; | ||
var testTab = schema.table_name; | ||
|
||
var client = dbConn.client; | ||
|
||
test('init test client', function (t) { | ||
client.connect(function () { | ||
client.query('DROP TABLE IF EXISTS ' + schema.table_name, t.end); | ||
client.query('DROP TABLE IF EXISTS ' + schema.table_name); | ||
client.query('DROP TABLE IF EXISTS table_1'); | ||
client.query('DROP TABLE IF EXISTS table_2', t.end); | ||
}); | ||
}); | ||
|
||
test('db.init', function (t) { | ||
t.throws( | ||
function () { db.init(client, { rubbish: 'schema' }) }, | ||
'error thrown when given when using invalid schema' | ||
); | ||
db.init(client, schema) | ||
.then(function () { return client.query('SELECT * from user_data') }) | ||
.then(function (res) { | ||
|
@@ -41,6 +46,24 @@ test('db.init', function (t) { | |
; | ||
}); | ||
|
||
test('db.init multiple tables', function (t) { | ||
function checkFieldExist (res) { | ||
t.ok( | ||
res.fields | ||
.map(function (field) { return field.name }) | ||
.indexOf('field') > -1 | ||
, 'table created with a correct field' | ||
); | ||
} | ||
db.init(client, multipleSchema) | ||
.then(function () { return client.query('SELECT * from table_1') }) | ||
.then(checkFieldExist) | ||
.then(function () { return client.query('SELECT * from table_2') }) | ||
.then(checkFieldExist) | ||
.then(t.end) | ||
; | ||
}); | ||
|
||
|
||
test('db.insert & default select w custom where', function (t) { | ||
db.insert(client, schema, { fields: testInsert, tableName: testTab }) | ||
|