1
1
'use strict'
2
+
3
+ import { createRequire } from 'module'
4
+ import chaiAsPromised from 'chai-as-promised'
5
+
2
6
/* globals describe it */
3
7
8
+ const totalObjectsForInsert = 10
9
+ const test1BatchSize = 1
10
+ const test2BatchSize = 10
11
+ const require = createRequire ( import . meta. url )
4
12
const { TestEnv } = require ( './env/test-env' )
5
13
const env = new TestEnv ( )
6
14
const chai = require ( 'chai' )
15
+ chai . use ( chaiAsPromised )
7
16
const expect = chai . expect
8
17
const assert = chai . assert
9
18
10
- const totalObjectsForInsert = 10
11
- const test1BatchSize = 1
12
- const test2BatchSize = 10
13
-
14
19
describe ( 'bulk' , function ( ) {
15
20
this . timeout ( 100000 )
16
21
@@ -857,6 +862,11 @@ describe('bulk', function () {
857
862
assert ( table !== null )
858
863
} )
859
864
865
+ async function doesThrow ( sql , message , connection ) {
866
+ const proxy = connection || env . theConnection
867
+ await expect ( proxy . promises . query ( sql ) ) . to . be . rejectedWith ( message )
868
+ }
869
+
860
870
it ( 'bulk insert condition failure' , async function handler ( ) {
861
871
const createTableSql = 'CREATE TABLE Persons (Name varchar(255) NOT NULL)'
862
872
await env . theConnection . promises . query ( env . dropTableSql ( 'Persons' ) )
@@ -867,9 +877,9 @@ describe('bulk', function () {
867
877
const nullJohn = 'INSERT INTO [Persons] ([Name]) OUTPUT INSERTED.* VALUES (null), (N\'John\')'
868
878
const error = 'Cannot insert the value NULL into column'
869
879
870
- await env . doesThrow ( johnNullSql , error )
871
- await env . doesThrow ( nullSql , error )
872
- await env . doesThrow ( nullJohn , error )
880
+ await doesThrow ( johnNullSql , error )
881
+ await doesThrow ( nullSql , error )
882
+ await doesThrow ( nullJohn , error )
873
883
} )
874
884
875
885
it ( 'non null varchar write empty string' , async function handler ( ) {
0 commit comments