(Type, value, options)
| 76 | }); |
| 77 | |
| 78 | const testSuccess = async function(Type, value, options) { |
| 79 | const parse = Type.constructor.parse = sinon.spy(value => { |
| 80 | return value; |
| 81 | }); |
| 82 | |
| 83 | const stringify = Type.constructor.prototype.stringify = sinon.spy(function() { |
| 84 | return Sequelize.ABSTRACT.prototype.stringify.apply(this, arguments); |
| 85 | }); |
| 86 | let bindParam; |
| 87 | if (options && options.useBindParam) { |
| 88 | bindParam = Type.constructor.prototype.bindParam = sinon.spy(function() { |
| 89 | return Sequelize.ABSTRACT.prototype.bindParam.apply(this, arguments); |
| 90 | }); |
| 91 | } |
| 92 | |
| 93 | const User = current.define('user', { |
| 94 | field: Type |
| 95 | }, { |
| 96 | timestamps: false |
| 97 | }); |
| 98 | |
| 99 | await current.sync({ force: true }); |
| 100 | |
| 101 | current.refreshTypes(); |
| 102 | |
| 103 | await User.create({ |
| 104 | field: value |
| 105 | }); |
| 106 | |
| 107 | await User.findAll(); |
| 108 | expect(parse).to.have.been.called; |
| 109 | if (options && options.useBindParam) { |
| 110 | expect(bindParam).to.have.been.called; |
| 111 | } else { |
| 112 | expect(stringify).to.have.been.called; |
| 113 | } |
| 114 | |
| 115 | delete Type.constructor.parse; |
| 116 | delete Type.constructor.prototype.stringify; |
| 117 | if (options && options.useBindParam) { |
| 118 | delete Type.constructor.prototype.bindParam; |
| 119 | } |
| 120 | }; |
| 121 | |
| 122 | const testFailure = function(Type) { |
| 123 | Type.constructor.parse = _.noop(); |
no test coverage detected