File tree Expand file tree Collapse file tree 1 file changed +60
-0
lines changed
libs/json-api/json-api-nestjs/src/lib/mock-utils/typeorm Expand file tree Collapse file tree 1 file changed +60
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { TypeOrmModule } from '@nestjs/typeorm' ;
2
+ import { DynamicModule } from '@nestjs/common' ;
3
+ import { IMemoryDb } from 'pg-mem' ;
4
+
5
+ import {
6
+ Addresses ,
7
+ Comments ,
8
+ Notes ,
9
+ Pods ,
10
+ Requests ,
11
+ RequestsHavePodLocks ,
12
+ Roles ,
13
+ UserGroups ,
14
+ Users ,
15
+ } from './entities' ;
16
+ import { DataSource } from 'typeorm' ;
17
+
18
+ export * from './entities' ;
19
+ export * from './utils' ;
20
+
21
+ export const entities = [
22
+ Users ,
23
+ UserGroups ,
24
+ Roles ,
25
+ RequestsHavePodLocks ,
26
+ Requests ,
27
+ Pods ,
28
+ Comments ,
29
+ Addresses ,
30
+ Notes ,
31
+ ] ;
32
+
33
+ export function mockDBTestModule ( db : IMemoryDb ) : DynamicModule {
34
+ return TypeOrmModule . forRootAsync ( {
35
+ useFactory ( ) {
36
+ return {
37
+ type : 'postgres' ,
38
+ // logging: true,
39
+ entities : [
40
+ Users ,
41
+ UserGroups ,
42
+ Roles ,
43
+ RequestsHavePodLocks ,
44
+ Requests ,
45
+ Pods ,
46
+ Comments ,
47
+ Addresses ,
48
+ Notes ,
49
+ ] ,
50
+ } ;
51
+ } ,
52
+ async dataSourceFactory ( options ) {
53
+ const dataSource : DataSource = await db . adapters . createTypeormDataSource (
54
+ options
55
+ ) ;
56
+
57
+ return dataSource ;
58
+ } ,
59
+ } ) ;
60
+ }
You can’t perform that action at this time.
0 commit comments