@@ -6,38 +6,44 @@ import * as request from 'supertest';
6
6
import { ConfigModule , ConfigService } from '@nestjs/config' ;
7
7
import { PrismaService } from '../src/prisma/prisma.service' ;
8
8
import { sign } from 'jsonwebtoken' ;
9
- import { Profile , Space } from '@prisma/client' ;
9
+ import { Space } from '@prisma/client' ;
10
+ import { PrismaModule } from '../src/prisma/prisma.module' ;
11
+ import { v4 as uuid } from 'uuid' ;
10
12
11
13
describe ( 'SpacesController (e2e)' , ( ) => {
12
14
let app : INestApplication ;
13
15
let testToken : string ;
14
16
let testSpace : Space ;
15
- let testProfile : Profile ;
16
17
let configService : ConfigService ;
18
+ let prisma : PrismaService ;
17
19
18
20
beforeAll ( async ( ) => {
19
21
const module : TestingModule = await Test . createTestingModule ( {
20
- imports : [ ConfigModule ] ,
22
+ imports : [ ConfigModule , PrismaModule ] ,
21
23
} ) . compile ( ) ;
22
24
23
25
const configService : ConfigService =
24
26
module . get < ConfigService > ( ConfigService ) ;
27
+ prisma = module . get < PrismaService > ( PrismaService ) ;
28
+
29
+ await prisma . profile . deleteMany ( { } ) ;
30
+ await prisma . user . deleteMany ( { } ) ;
31
+
32
+ const testUser = await prisma . user . create ( { data : { uuid : uuid ( ) } } ) ;
33
+ await prisma . profile . create ( {
34
+ data : {
35
+ uuid : uuid ( ) ,
36
+ userId : testUser . uuid ,
37
+ image : 'test image' ,
38
+ nickname : 'test nickname' ,
39
+ } ,
40
+ } ) ;
41
+
25
42
testToken = sign (
26
- { sub : 'test uuid' } ,
43
+ { sub : testUser . uuid } ,
27
44
configService . get < string > ( 'JWT_ACCESS_SECRET' ) ,
28
45
{ expiresIn : '5m' } ,
29
46
) ;
30
- testSpace = {
31
- uuid : 'space-uuid' ,
32
- name : 'test space' ,
33
- icon : 'test space icon' ,
34
- } ;
35
- testProfile = {
36
- uuid : 'profile uuid' ,
37
- user_id : 'test uuid' ,
38
- image : configService . get < string > ( 'BASE_IMAGE_URL' ) ,
39
- nickname : 'test nickname' ,
40
- } ;
41
47
} ) ;
42
48
43
49
beforeEach ( async ( ) => {
@@ -57,38 +63,10 @@ describe('SpacesController (e2e)', () => {
57
63
moduleFixture . get < PrismaService > ( PrismaService ) ;
58
64
configService = moduleFixture . get < ConfigService > ( ConfigService ) ;
59
65
60
- const testUser = { email :
'[email protected] ' , provider :
'kakao' } ;
61
- await prisma . user . upsert ( {
62
- where : {
63
- email_provider : { email : testUser . email , provider : testUser . provider } ,
64
- } ,
65
- update : { } ,
66
- create : {
67
- uuid : 'test uuid' ,
68
- email : testUser . email ,
69
- provider : testUser . provider ,
70
- } ,
71
- } ) ;
72
- await prisma . profile . upsert ( {
73
- where : { user_id : 'test uuid' } ,
74
- update : { } ,
75
- create : {
76
- uuid : testProfile . uuid ,
77
- user_id : testProfile . user_id ,
78
- image : testProfile . image ,
79
- nickname : testProfile . nickname ,
80
- } ,
81
- } ) ;
82
- await prisma . space . upsert ( {
83
- where : {
84
- uuid : testSpace . uuid ,
85
- } ,
86
- update : { } ,
87
- create : {
88
- uuid : testSpace . uuid ,
89
- name : testSpace . name ,
90
- icon : testSpace . icon ,
91
- } ,
66
+ await prisma . space . deleteMany ( { } ) ;
67
+
68
+ testSpace = await prisma . space . create ( {
69
+ data : { uuid : 'space-uuid' , name : 'test space' , icon : 'test icon' } ,
92
70
} ) ;
93
71
} ) ;
94
72
0 commit comments