I'm working on a API using node, where ModelName means the model built using bookshelf.js like this:
const bookshelf = require('./bookshelf')
const Intake = require('./intake')
const ModelName = bookshelf.Model.extend(
{
tableName: 'modelName',
hasTimestamps: true,
uuid: true,
otherModel: function() {
return this.hasOne(OtherModel)
}
},
{
dependents: ['otherModel']
}
)
module.exports = ModelName
and when testing the following funtion:
deleteModelName(Id) {
try {
return ModelName.forge({ id: Id }).destroy()
} catch (err) {
Logger.error('ModelNameService#deleteModelName :: failed to delete ModelName', > err.stack)
throw err
}
}
With this test:
describe('#deleteModelName', () => { it('should call deleteModelName', async () => { /*Creating a ModelName*/ const deleteModelName = sandbox.stub() deleteModelName.resolves(CreatedModelName) const result = await ModelNameService.deleteModelName(ModelName.id) expect(result).to.be.undefined }}
I get this error:
TypeError: ModelName.forge(...).destroy is not a function