1
+ /* eslint-disable @typescript-eslint/unbound-method */
1
2
import { Hub , Scope } from '@sentry/hub' ;
2
3
3
4
import { Prisma } from '../../../src/integrations/node/prisma' ;
@@ -6,30 +7,30 @@ import { Span } from '../../../src/span';
6
7
type PrismaMiddleware = ( params : unknown , next : ( params ?: unknown ) => Promise < unknown > ) => Promise < unknown > ;
7
8
8
9
class PrismaClient {
10
+ public user : { create : ( ) => Promise < unknown > } = {
11
+ create : ( ) => this . _middleware ?.( { action : 'create' , model : 'user' } , ( ) => Promise . resolve ( 'result' ) ) ,
12
+ } ;
13
+
14
+ private _middleware ?: PrismaMiddleware ;
15
+
9
16
constructor ( ) {
10
- this . middleware = undefined ;
17
+ this . _middleware = undefined ;
11
18
}
12
19
13
- private middleware ?: PrismaMiddleware ;
14
-
15
20
public $use ( cb : PrismaMiddleware ) {
16
- this . middleware = cb ;
21
+ this . _middleware = cb ;
17
22
}
18
-
19
- public user = {
20
- create : ( ) => this . middleware ?.( { action : 'create' , model : 'user' } , ( ) => Promise . resolve ( 'result' ) ) ,
21
- } ;
22
23
}
23
24
24
- describe ( 'setupOnce' , ( ) => {
25
+ describe ( 'setupOnce' , function ( ) {
25
26
const Client : PrismaClient = new PrismaClient ( ) ;
26
27
27
28
let scope = new Scope ( ) ;
28
29
let parentSpan : Span ;
29
30
let childSpan : Span ;
30
31
31
32
beforeAll ( ( ) => {
32
- // @ts -ignore
33
+ // @ts -ignore, not to export PrismaClient types from integration source
33
34
new Prisma ( { client : Client } ) . setupOnce (
34
35
( ) => undefined ,
35
36
( ) => new Hub ( undefined , scope ) ,
@@ -45,8 +46,8 @@ describe('setupOnce', () => {
45
46
jest . spyOn ( childSpan , 'finish' ) ;
46
47
} ) ;
47
48
48
- it ( ` should add middleware with $use method correctly` , done => {
49
- Client . user . create ( ) ?. then ( res => {
49
+ it ( ' should add middleware with $use method correctly' , done => {
50
+ void Client . user . create ( ) ?. then ( res => {
50
51
expect ( res ) . toBe ( 'result' ) ;
51
52
expect ( scope . getSpan ) . toBeCalled ( ) ;
52
53
expect ( parentSpan . startChild ) . toBeCalledWith ( {
0 commit comments