16
16
* See the License for the specific language governing permissions and
17
17
* limitations under the License.
18
18
*/
19
+ /* eslint-disable @typescript-eslint/promise-function-async */
19
20
import { ConnectionProvider , newError , ServerInfo , Session } from '../src'
20
21
import Driver , { READ } from '../src/driver'
21
22
import { Bookmarks } from '../src/internal/bookmarks'
@@ -47,26 +48,24 @@ describe('Driver', () => {
47
48
} )
48
49
49
50
afterEach ( async ( ) => {
50
- if ( driver ) {
51
+ if ( driver != null ) {
51
52
await driver . close ( )
52
53
driver = null
53
54
}
54
55
} )
55
56
56
-
57
57
describe ( '.session()' , ( ) => {
58
58
it ( 'should create the session with impersonated user' , ( ) => {
59
59
const impersonatedUser = 'the impostor'
60
60
61
- const session = driver ! . session ( { impersonatedUser } )
61
+ const session = driver ? .session ( { impersonatedUser } )
62
62
63
63
expect ( session ) . not . toBeUndefined ( )
64
64
expect ( createSession ) . toHaveBeenCalledWith ( expectedSessionParams ( { impersonatedUser } ) )
65
65
} )
66
66
67
-
68
67
it ( 'should create the session without impersonated user' , ( ) => {
69
- const session = driver ! . session ( )
68
+ const session = driver ? .session ( )
70
69
71
70
expect ( session ) . not . toBeUndefined ( )
72
71
expect ( createSession ) . toHaveBeenCalledWith ( expectedSessionParams ( ) )
@@ -77,12 +76,12 @@ describe('Driver', () => {
77
76
[ null , Bookmarks . empty ( ) ] ,
78
77
[ 'bookmark' , new Bookmarks ( 'bookmark' ) ] ,
79
78
[ [ 'bookmark' ] , new Bookmarks ( [ 'bookmark' ] ) ] ,
80
- [ [ 'bookmark1' , 'bookmark2' ] , new Bookmarks ( [ 'bookmark1' , 'bookmark2' ] ) ] ,
79
+ [ [ 'bookmark1' , 'bookmark2' ] , new Bookmarks ( [ 'bookmark1' , 'bookmark2' ] ) ]
81
80
] ) ( 'should create session using param bookmarks' , ( bookmarks , expectedBookmarks ) => {
82
- // @ts -ignore
83
- const session = driver ! . session ( { bookmarks } )
81
+ // @ts -expect-error
82
+ const session = driver ? .session ( { bookmarks } )
84
83
85
- expect ( session . lastBookmarks ( ) ) . toEqual ( expectedBookmarks . values ( ) )
84
+ expect ( session ? .lastBookmarks ( ) ) . toEqual ( expectedBookmarks . values ( ) )
86
85
} )
87
86
} )
88
87
@@ -96,11 +95,11 @@ describe('Driver', () => {
96
95
] ) ( '.supportsMultiDb() => %s' , ( _ , expectedPromise ) => {
97
96
connectionProvider . supportsMultiDb = jest . fn ( ( ) => expectedPromise )
98
97
99
- const promise : Promise < boolean > = driver ! . supportsMultiDb ( )
98
+ const promise : Promise < boolean > | undefined = driver ? .supportsMultiDb ( )
100
99
101
100
expect ( promise ) . toBe ( expectedPromise )
102
101
103
- promise . catch ( _ => 'Do nothing' ) . finally ( ( ) => { } )
102
+ promise ? .catch ( _ => 'Do nothing' ) . finally ( ( ) => { } )
104
103
} )
105
104
106
105
it . each ( [
@@ -115,11 +114,11 @@ describe('Driver', () => {
115
114
( ) => expectedPromise
116
115
)
117
116
118
- const promise : Promise < boolean > = driver ! . supportsTransactionConfig ( )
117
+ const promise : Promise < boolean > | undefined = driver ? .supportsTransactionConfig ( )
119
118
120
119
expect ( promise ) . toBe ( expectedPromise )
121
120
122
- promise . catch ( _ => 'Do nothing' ) . finally ( ( ) => { } )
121
+ promise ? .catch ( _ => 'Do nothing' ) . finally ( ( ) => { } )
123
122
} )
124
123
125
124
it . each ( [
@@ -134,23 +133,23 @@ describe('Driver', () => {
134
133
( ) => expectedPromise
135
134
)
136
135
137
- const promise : Promise < boolean > = driver ! . supportsUserImpersonation ( )
136
+ const promise : Promise < boolean > | undefined = driver ? .supportsUserImpersonation ( )
138
137
139
138
expect ( promise ) . toBe ( expectedPromise )
140
139
141
- promise . catch ( _ => 'Do nothing' ) . finally ( ( ) => { } )
140
+ promise ? .catch ( _ => 'Do nothing' ) . finally ( ( ) => { } )
142
141
} )
143
142
144
143
it . each ( [
145
144
[ { encrypted : true } , true ] ,
146
145
[ { encrypted : false } , false ] ,
147
146
[ { } , false ] ,
148
147
[ { encrypted : 'ENCRYPTION_ON' } , true ] ,
149
- [ { encrypted : 'ENCRYPTION_OFF' } , false ] ,
148
+ [ { encrypted : 'ENCRYPTION_OFF' } , false ]
150
149
] ) ( '.isEncrypted()' , ( config , expectedValue ) => {
151
150
const connectionProvider = new ConnectionProvider ( )
152
151
connectionProvider . close = jest . fn ( ( ) => Promise . resolve ( ) )
153
- // @ts -ignore
152
+ // @ts -expect-error
154
153
const driver = new Driver ( META_INFO , config , mockCreateConnectonProvider ( connectionProvider ) )
155
154
156
155
expect ( driver . isEncrypted ( ) ) . toEqual ( expectedValue )
@@ -170,7 +169,7 @@ describe('Driver', () => {
170
169
// No connection timeouts should be considered valid, since it means
171
170
// the user doesn't case about the connection timeout at all.
172
171
[ { connectionTimeout : 0 , connectionAcquisitionTimeout : 2000 } , true ] ,
173
- [ { connectionTimeout : - 1 , connectionAcquisitionTimeout : 2000 } , true ] ,
172
+ [ { connectionTimeout : - 1 , connectionAcquisitionTimeout : 2000 } , true ]
174
173
] ) ( 'should emit warning if `connectionAcquisitionTimeout` and `connectionTimeout` are conflicting. [%o} ' , async ( config , valid ) => {
175
174
const logging = {
176
175
level : 'warn' as LogLevel ,
@@ -202,17 +201,17 @@ describe('Driver', () => {
202
201
[ { database : undefined } , 'Promise.resolve(ServerInfo>)' , Promise . resolve ( new ServerInfo ( ) ) ] ,
203
202
[ { database : undefined } , 'Promise.reject(Error)' , Promise . reject ( newError ( 'something went wrong' ) ) ] ,
204
203
[ { database : 'db' } , 'Promise.resolve(ServerInfo>)' , Promise . resolve ( new ServerInfo ( ) ) ] ,
205
- [ { database : 'db' } , 'Promise.reject(Error)' , Promise . reject ( newError ( 'something went wrong' ) ) ] ,
204
+ [ { database : 'db' } , 'Promise.reject(Error)' , Promise . reject ( newError ( 'something went wrong' ) ) ]
206
205
] ) ( '.verifyConnectivity(%o) => %s' , ( input : { database ?: string } | undefined , _ , expectedPromise ) => {
207
206
connectionProvider . verifyConnectivityAndGetServerInfo = jest . fn ( ( ) => expectedPromise )
208
207
209
- const promise : Promise < ServerInfo > = driver ! . verifyConnectivity ( input )
208
+ const promise : Promise < ServerInfo > | undefined = driver ? .verifyConnectivity ( input )
210
209
211
210
expect ( promise ) . toBe ( expectedPromise )
212
211
expect ( connectionProvider . verifyConnectivityAndGetServerInfo )
213
- . toBeCalledWith ( { database : input && input . database ? input . database : '' , accessMode : READ } )
212
+ . toBeCalledWith ( { database : input ? .database ?? '' , accessMode : READ } )
214
213
215
- promise . catch ( _ => 'Do nothing' ) . finally ( ( ) => { } )
214
+ promise ? .catch ( _ => 'Do nothing' ) . finally ( ( ) => { } )
216
215
} )
217
216
218
217
it . each ( [
@@ -223,20 +222,20 @@ describe('Driver', () => {
223
222
[ { database : undefined } , 'Promise.resolve(ServerInfo>)' , Promise . resolve ( new ServerInfo ( ) ) ] ,
224
223
[ { database : undefined } , 'Promise.reject(Error)' , Promise . reject ( newError ( 'something went wrong' ) ) ] ,
225
224
[ { database : 'db' } , 'Promise.resolve(ServerInfo>)' , Promise . resolve ( new ServerInfo ( ) ) ] ,
226
- [ { database : 'db' } , 'Promise.reject(Error)' , Promise . reject ( newError ( 'something went wrong' ) ) ] ,
225
+ [ { database : 'db' } , 'Promise.reject(Error)' , Promise . reject ( newError ( 'something went wrong' ) ) ]
227
226
] ) ( '.getServerInfo(%o) => %s' , ( input : { database ?: string } | undefined , _ , expectedPromise ) => {
228
227
connectionProvider . verifyConnectivityAndGetServerInfo = jest . fn ( ( ) => expectedPromise )
229
228
230
- const promise : Promise < ServerInfo > = driver ! . getServerInfo ( input )
229
+ const promise : Promise < ServerInfo > | undefined = driver ? .getServerInfo ( input )
231
230
232
231
expect ( promise ) . toBe ( expectedPromise )
233
232
expect ( connectionProvider . verifyConnectivityAndGetServerInfo )
234
- . toBeCalledWith ( { database : input && input . database ? input . database : '' , accessMode : READ } )
233
+ . toBeCalledWith ( { database : input ? .database ?? '' , accessMode : READ } )
235
234
236
- promise . catch ( _ => 'Do nothing' ) . finally ( ( ) => { } )
235
+ promise ? .catch ( _ => 'Do nothing' ) . finally ( ( ) => { } )
237
236
} )
238
237
239
- function mockCreateConnectonProvider ( connectionProvider : ConnectionProvider ) {
238
+ function mockCreateConnectonProvider ( connectionProvider : ConnectionProvider ) {
240
239
return (
241
240
id : number ,
242
241
config : Object ,
@@ -245,20 +244,20 @@ describe('Driver', () => {
245
244
) => connectionProvider
246
245
}
247
246
248
- function expectedSessionParams ( extra : any = { } ) {
247
+ function expectedSessionParams ( extra : any = { } ) : any {
249
248
return {
250
249
bookmarks : Bookmarks . empty ( ) ,
251
250
config : {
252
251
connectionAcquisitionTimeout : 60000 ,
253
252
fetchSize : 1000 ,
254
253
maxConnectionLifetime : 3600000 ,
255
254
maxConnectionPoolSize : 100 ,
256
- connectionTimeout : 30000 ,
255
+ connectionTimeout : 30000
257
256
} ,
258
257
connectionProvider,
259
258
database : '' ,
260
259
fetchSize : 1000 ,
261
- mode : " WRITE" ,
260
+ mode : ' WRITE' ,
262
261
reactive : false ,
263
262
impersonatedUser : undefined ,
264
263
...extra
0 commit comments