Skip to content

Commit 0371270

Browse files
author
Peter Svetlichny
committed
test(postgres): add single quote test and remove interdependence
1 parent 410355b commit 0371270

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

test/src/index.spec.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ describe('postgres', () => {
99
inst.tableName = 'foo'
1010
// Mock validation method, this is automatically done by the model
1111
inst.validate = (body) => Promise.resolve(body)
12+
return inst.createTable(fixd.postgres.createTable)
1213
})
14+
beforeEach(() => inst.create(Object.assign({}, fixd.postgres.testData)))
15+
afterEach(() => inst.query(`TRUNCATE ${inst.tableName}`))
1316
after(() => inst.pg.end())
1417
describe('query', () => {
1518
it('runs a query against the database when connection is good', () => {
@@ -35,10 +38,11 @@ describe('postgres', () => {
3538
beforeEach(() => {
3639
data = Object.assign({}, fixd.postgres.testData)
3740
})
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"
3943
return inst.create(data)
4044
.then((res) => {
41-
expect(res).to.containSubset(fixd.postgres.testData)
45+
expect(res.fname).to.equal('first name\'s John')
4246
})
4347
})
4448
it('rejects if record is not created', () => {
@@ -53,8 +57,7 @@ describe('postgres', () => {
5357
inst.sanitize = sandbox.spy(body => body)
5458
return inst.read()
5559
.then((res) => {
56-
expect(inst.sanitize).to.be.calledOnce()
57-
expect(res.length).to.equal(1)
60+
expect(inst.sanitize).to.be.called()
5861
expect(res[0].email).to.equal(fixd.postgres.testData.email)
5962
})
6063
})
@@ -96,9 +99,9 @@ describe('postgres', () => {
9699
})
97100
describe('delete', () => {
98101
it('deletes record(s) based on query', () => {
99-
return inst.delete('fname=\'Bob\'')
102+
return inst.delete('fname=\'John\'')
100103
.then((res) => {
101-
expect(res.rowCount).to.equal(1)
104+
expect(res.rowCount).to.be.at.least(1)
102105
})
103106
})
104107
})

0 commit comments

Comments
 (0)