|
| 1 | +// Copyright IBM Corp. 2019. All Rights Reserved. |
| 2 | +// Node module: loopback-connector-dashdb |
| 3 | +// This file is licensed under the Artistic License 2.0. |
| 4 | +// License text available at https://opensource.org/licenses/Artistic-2.0 |
| 5 | + |
| 6 | +'use strict'; |
| 7 | + |
| 8 | +/* eslint-env node, mocha */ |
| 9 | +process.env.NODE_ENV = 'test'; |
| 10 | + |
| 11 | +require('should'); |
| 12 | + |
| 13 | +let db, FloatingPoint; |
| 14 | + |
| 15 | +describe('dml', function() { |
| 16 | + before(function() { |
| 17 | + require('./init.js'); |
| 18 | + }); |
| 19 | + |
| 20 | + describe('insert and patch', function() { |
| 21 | + before(function(done) { |
| 22 | + db = global.getDataSource(); |
| 23 | + |
| 24 | + FloatingPoint = db.define('FLOATING_POINT', { |
| 25 | + id: {type: String, length: 20, index: true}, |
| 26 | + aFloat: {type: Number, dashdb: {dataType: 'double'}}, |
| 27 | + }); |
| 28 | + db.automigrate('FLOATING_POINT', done); |
| 29 | + }); |
| 30 | + |
| 31 | + // Return an async function create a record in floating_point table |
| 32 | + function createRecInFP(rec) { |
| 33 | + return function(done) { |
| 34 | + FloatingPoint.create(rec, |
| 35 | + function(err, p) { |
| 36 | + if (err) { |
| 37 | + done(err); |
| 38 | + } else { |
| 39 | + done(); |
| 40 | + } |
| 41 | + }); |
| 42 | + }; |
| 43 | + } |
| 44 | + |
| 45 | + describe('patch', function() { |
| 46 | + const rec = {aFloat: 42.234567}; |
| 47 | + before(createRecInFP(rec)); |
| 48 | + |
| 49 | + it('should fail with a specific SQL error', async function() { |
| 50 | + await FloatingPoint.updateAll(rec, {aFloat: 42.234567890123456789}) |
| 51 | + .should.be.rejectedWith( |
| 52 | + '[IBM][CLI Driver] CLI0135E Invalid scale value. SQLSTATE=HY094', |
| 53 | + ); |
| 54 | + }); |
| 55 | + }); |
| 56 | + }); |
| 57 | +}); |
0 commit comments