11import { Test , TestingModule } from '@nestjs/testing' ;
22import { Table } from '@typedorm/common' ;
3- import { DocumentClientV3 } from '@typedorm/document-client' ;
4- import { DynamoDBClient } from '@aws-sdk/client-dynamodb' ;
3+ import { DocumentClientV3 } from '@typedorm/document-client' ;
4+ import { DynamoDBClient } from '@aws-sdk/client-dynamodb' ;
55import { TypeDormModule } from './type-dorm.module' ;
66import { getTypeDormConnectionToken } from './type-dorm.util' ;
77import { Connection , getEntityManager } from '@typedorm/core' ;
@@ -20,74 +20,83 @@ describe('TypeDormModule', () => {
2020 it ( 'Instance typeDorm' , async ( ) => {
2121 const instanceName = 'dummy' ;
2222 const module : TestingModule = await Test . createTestingModule ( {
23- imports : [ TypeDormModule . forRoot ( {
24- table,
25- entities : [ ] ,
26- documentClient : new DocumentClientV3 ( new DynamoDBClient ( { } ) ) ,
27- name : instanceName
28- } ) ] ,
23+ imports : [
24+ TypeDormModule . forRoot ( {
25+ table,
26+ entities : [ ] ,
27+ documentClient : new DocumentClientV3 ( new DynamoDBClient ( { } ) ) ,
28+ name : instanceName ,
29+ } ) ,
30+ ] ,
2931 } ) . compile ( ) ;
3032
3133 const typeDormModule = module . get ( TypeDormModule ) ;
3234 expect ( typeDormModule ) . toBeInstanceOf ( TypeDormModule ) ;
3335
34- const typeDormConnection : Connection = module . get ( getTypeDormConnectionToken ( instanceName ) ) ;
36+ const typeDormConnection : Connection = module . get (
37+ getTypeDormConnectionToken ( instanceName ) ,
38+ ) ;
3539 expect ( typeDormConnection ) . toBeInstanceOf ( Connection ) ;
3640
37- const entityManager = getEntityManager ( instanceName )
38- expect ( entityManager ) . toStrictEqual ( typeDormConnection . entityManager )
41+ const entityManager = getEntityManager ( instanceName ) ;
42+ expect ( entityManager ) . toStrictEqual ( typeDormConnection . entityManager ) ;
3943 } ) ;
4044
4145 it ( 'inject redis connection' , async ( ) => {
42-
4346 @Injectable ( )
4447 class TestProvider {
45- constructor ( @InjectTypeDorm ( ) private readonly connection : TypeDormConnection ) { }
48+ constructor (
49+ @InjectTypeDorm ( ) private readonly connection : TypeDormConnection ,
50+ ) { }
4651
4752 getConnection ( ) {
4853 return this . connection ;
4954 }
5055 }
5156
5257 const module : TestingModule = await Test . createTestingModule ( {
53- imports : [ TypeDormModule . forRoot ( {
54- table,
55- entities : [ ] ,
56- documentClient : new DocumentClientV3 ( new DynamoDBClient ( { } ) ) ,
57- } ) ] ,
58+ imports : [
59+ TypeDormModule . forRoot ( {
60+ table,
61+ entities : [ ] ,
62+ documentClient : new DocumentClientV3 ( new DynamoDBClient ( { } ) ) ,
63+ } ) ,
64+ ] ,
5865 providers : [ TestProvider ] ,
5966 } ) . compile ( ) ;
6067
61-
6268 const provider = module . get ( TestProvider ) ;
6369 expect ( provider . getConnection ( ) ) . toBeInstanceOf ( Connection ) ;
64-
6570 } ) ;
6671
6772 it ( 'Instance async typeDorm' , async ( ) => {
6873 const instanceName = 'dummy2' ;
6974 const module : TestingModule = await Test . createTestingModule ( {
70- imports : [ TypeDormModule . forRootAsync ( {
71- name : instanceName ,
72- useFactory : async ( ) => {
73- return {
74- table,
75- entities : [ ] ,
76- documentClient : new DocumentClientV3 ( new DynamoDBClient ( { } ) ) ,
77- name : instanceName
78- }
79- } ,
80- } ) ] ,
75+ imports : [
76+ TypeDormModule . forRootAsync ( {
77+ name : instanceName ,
78+ useFactory : async ( ) => {
79+ return {
80+ table,
81+ entities : [ ] ,
82+ documentClient : new DocumentClientV3 ( new DynamoDBClient ( { } ) ) ,
83+ name : instanceName ,
84+ } ;
85+ } ,
86+ } ) ,
87+ ] ,
8188 } ) . compile ( ) ;
8289
8390 const typeDormModule = module . get ( TypeDormModule ) ;
8491 expect ( typeDormModule ) . toBeInstanceOf ( TypeDormModule ) ;
8592
86- const typeDormConnection : Connection = module . get ( getTypeDormConnectionToken ( instanceName ) ) ;
93+ const typeDormConnection : Connection = module . get (
94+ getTypeDormConnectionToken ( instanceName ) ,
95+ ) ;
8796 expect ( typeDormConnection ) . toBeInstanceOf ( Connection ) ;
8897
89- const entityManager = getEntityManager ( instanceName )
90- expect ( entityManager ) . toStrictEqual ( typeDormConnection . entityManager )
98+ const entityManager = getEntityManager ( instanceName ) ;
99+ expect ( entityManager ) . toStrictEqual ( typeDormConnection . entityManager ) ;
91100 } ) ;
92101
93102 it ( 'Instance async typeDorm use class' , async ( ) => {
@@ -97,38 +106,44 @@ describe('TypeDormModule', () => {
97106 table,
98107 entities : [ ] ,
99108 documentClient : new DocumentClientV3 ( new DynamoDBClient ( { } ) ) ,
100- name : instanceName
101- }
109+ name : instanceName ,
110+ } ;
102111 }
103112 }
104113
105114 const instanceName = 'dummy3' ;
106115 const module : TestingModule = await Test . createTestingModule ( {
107- imports : [ TypeDormModule . forRootAsync ( {
108- name : instanceName ,
109- useClass : Factory ,
110- } ) ] ,
116+ imports : [
117+ TypeDormModule . forRootAsync ( {
118+ name : instanceName ,
119+ useClass : Factory ,
120+ } ) ,
121+ ] ,
111122 } ) . compile ( ) ;
112123
113124 const typeDormModule = module . get ( TypeDormModule ) ;
114125 expect ( typeDormModule ) . toBeInstanceOf ( TypeDormModule ) ;
115126
116- const typeDormConnection : Connection = module . get ( getTypeDormConnectionToken ( instanceName ) ) ;
127+ const typeDormConnection : Connection = module . get (
128+ getTypeDormConnectionToken ( instanceName ) ,
129+ ) ;
117130 expect ( typeDormConnection ) . toBeInstanceOf ( Connection ) ;
118131
119- const entityManager = getEntityManager ( instanceName )
120- expect ( entityManager ) . toStrictEqual ( typeDormConnection . entityManager )
132+ const entityManager = getEntityManager ( instanceName ) ;
133+ expect ( entityManager ) . toStrictEqual ( typeDormConnection . entityManager ) ;
121134 } ) ;
122135
123136 it ( 'Instance typeDorm without injection' , async ( ) => {
124137 const instanceName = 'dummy5' ;
125138 const module : TestingModule = await Test . createTestingModule ( {
126- imports : [ TypeDormModule . forRootNonInjection ( {
127- table,
128- entities : [ ] ,
129- documentClient : new DocumentClientV3 ( new DynamoDBClient ( { } ) ) ,
130- name : instanceName
131- } ) ] ,
139+ imports : [
140+ TypeDormModule . forRootNonInjection ( {
141+ table,
142+ entities : [ ] ,
143+ documentClient : new DocumentClientV3 ( new DynamoDBClient ( { } ) ) ,
144+ name : instanceName ,
145+ } ) ,
146+ ] ,
132147 } ) . compile ( ) ;
133148
134149 const typeDormModule = module . get ( TypeDormModule ) ;
@@ -137,16 +152,22 @@ describe('TypeDormModule', () => {
137152 const typeDormConnection = module . get ( TypeDormConnection ) ;
138153 expect ( typeDormConnection ) . toBeInstanceOf ( Connection ) ;
139154
140- const entityManager = getEntityManager ( instanceName )
141- expect ( entityManager ) . toStrictEqual ( typeDormConnection . entityManager )
155+ const entityManager = getEntityManager ( instanceName ) ;
156+ expect ( entityManager ) . toStrictEqual ( typeDormConnection . entityManager ) ;
142157 } ) ;
143158
144159 it ( 'Throw error if pass invalid configuration' , async ( ) => {
145160 const instanceName = 'dummy6' ;
146- expect ( ( ) => Test . createTestingModule ( {
147- imports : [ TypeDormModule . forRootAsync ( {
148- name : instanceName ,
149- } ) ] ,
150- } ) . compile ( ) ) . toThrow ( 'Invalid configuration. Must provide useFactory, useClass or useExisting' ) ;
161+ expect ( ( ) =>
162+ Test . createTestingModule ( {
163+ imports : [
164+ TypeDormModule . forRootAsync ( {
165+ name : instanceName ,
166+ } ) ,
167+ ] ,
168+ } ) . compile ( ) ,
169+ ) . toThrow (
170+ 'Invalid configuration. Must provide useFactory, useClass or useExisting' ,
171+ ) ;
151172 } ) ;
152- } ) ;
173+ } ) ;
0 commit comments