Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions __tests__/DbRelation.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ test ('good columns is function', () => {

const r = new DbRelation ({
name: 't',
columns: function () { return {
id: {type: 'int'},
}},
columns: function () {

expect (this instanceof DbRelation).toBe(true)

expect (this.name).toBe('t')

return { id: {type: 'int'} }
},
pk: 'id',
})

Expand Down
22 changes: 16 additions & 6 deletions __tests__/DbTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,23 @@ test ('good', () => {

const r = new DbTable ({
name: 't',
columns: function () { return {
id: {type: 'int'},
}},
columns: function () {

expect (this instanceof DbTable).toBe(true)

expect (this.name).toBe('t')

return { id: {type: 'int'} }
},
pk: 'id',
data: function () { return [{
id: 1
}]}
data: function () {

expect (this instanceof DbTable).toBe(true)

expect (this.name).toBe('t')

return [ {id: 1} ]
}
})

expect (r.columns.id.type).toBe ('int')
Expand Down
15 changes: 14 additions & 1 deletion __tests__/DbTrigger.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const DbTrigger = require ('../lib/model/DbTrigger.js')
const DbTable = require ('../lib/model/DbTable.js')
const DbModel = require ('../lib/model/DbModel.js')

test ('bad', () => {
Expand All @@ -24,7 +25,15 @@ test ('not bad', () => {
pk: ['id'],
triggers: [
{name: 't', phase: 'BEFORE UPDATE', sql: 'NULL;'},
{name: 't1', phase: 'AFTER UPDATE', sql: function () {return 'NULL;'}},
{name: 't1', phase: 'AFTER UPDATE', sql: function () {

expect (this instanceof DbTrigger).toBe(true)
expect (this.table instanceof DbTable).toBe(true)
expect (this.table.name).toBe('users')
expect (this.table.model).toStrictEqual (m)

return 'NULL;'
}},
]
})

Expand All @@ -38,4 +47,8 @@ test ('not bad', () => {

expect (t1.sql).toBe ('NULL;')

expect (t1.table.name).toBe ('users')

expect (t1.table.model).toStrictEqual (m)

})
2 changes: 1 addition & 1 deletion lib/model/DbTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class DbTrigger extends DbObject {

super (o)

if (typeof this.sql === 'function') this.sql = this.sql (this.table)
if (typeof this.sql === 'function') this.sql = this.sql ()

for (const k of ['phase', 'sql']) if (!this [k] || typeof this [k] !== 'string') throw new Error (`${k} must be a non empty string`)

Expand Down