@@ -9,7 +9,10 @@ describe('postgres', () => {
9
9
inst . tableName = 'foo'
10
10
// Mock validation method, this is automatically done by the model
11
11
inst . validate = ( body ) => Promise . resolve ( body )
12
+ return inst . createTable ( fixd . postgres . createTable )
12
13
} )
14
+ beforeEach ( ( ) => inst . create ( Object . assign ( { } , fixd . postgres . testData ) ) )
15
+ afterEach ( ( ) => inst . query ( `TRUNCATE ${ inst . tableName } ` ) )
13
16
after ( ( ) => inst . pg . end ( ) )
14
17
describe ( 'query' , ( ) => {
15
18
it ( 'runs a query against the database when connection is good' , ( ) => {
@@ -35,10 +38,11 @@ describe('postgres', () => {
35
38
beforeEach ( ( ) => {
36
39
data = Object . assign ( { } , fixd . postgres . testData )
37
40
} )
38
- it ( 'creates a new record based on object passed' , ( ) => {
41
+ it ( 'creates a new record based on object passed, escaping single quotes in string values' , ( ) => {
42
+ data . fname = "first name's John"
39
43
return inst . create ( data )
40
44
. then ( ( res ) => {
41
- expect ( res ) . to . containSubset ( fixd . postgres . testData )
45
+ expect ( res . fname ) . to . equal ( 'first name\'s John' )
42
46
} )
43
47
} )
44
48
it ( 'rejects if record is not created' , ( ) => {
@@ -53,8 +57,7 @@ describe('postgres', () => {
53
57
inst . sanitize = sandbox . spy ( body => body )
54
58
return inst . read ( )
55
59
. then ( ( res ) => {
56
- expect ( inst . sanitize ) . to . be . calledOnce ( )
57
- expect ( res . length ) . to . equal ( 1 )
60
+ expect ( inst . sanitize ) . to . be . called ( )
58
61
expect ( res [ 0 ] . email ) . to . equal ( fixd . postgres . testData . email )
59
62
} )
60
63
} )
@@ -96,9 +99,9 @@ describe('postgres', () => {
96
99
} )
97
100
describe ( 'delete' , ( ) => {
98
101
it ( 'deletes record(s) based on query' , ( ) => {
99
- return inst . delete ( 'fname=\'Bob \'' )
102
+ return inst . delete ( 'fname=\'John \'' )
100
103
. then ( ( res ) => {
101
- expect ( res . rowCount ) . to . equal ( 1 )
104
+ expect ( res . rowCount ) . to . be . at . least ( 1 )
102
105
} )
103
106
} )
104
107
} )
0 commit comments