1
1
import request from 'supertest' ;
2
+ import { Connection , getConnection } from 'typeorm' ;
2
3
import { app } from '../app' ;
3
4
4
- import createConnection from '../database'
5
+ import createConnection from '../database' ;
5
6
6
- describe ( "Surveys" , ( ) => {
7
- beforeAll ( async ( ) => {
8
- const connetcion = await createConnection ( ) ;
9
- await connetcion . runMigrations ( ) ;
7
+
8
+ describe ( "Surveys" , ( ) => {
9
+
10
+
11
+ beforeAll ( async ( ) => {
12
+ const connection = await createConnection ( ) ;
13
+ await connection . runMigrations ( ) ;
14
+ } ) ;
15
+
16
+
17
+ afterAll ( async ( ) => {
18
+ const connection = getConnection ( ) ;
19
+ await connection . dropDatabase ( ) ;
20
+ await connection . close ( ) ;
10
21
} ) ;
11
- it ( "should be able to create a new survey" , async ( ) => {
12
- const response = await request ( app ) . post ( "/surveys" ) . send ( {
13
- title :"Title Example" ,
14
- description :"Description Example" ,
22
+
23
+ it ( "Should be able to create a new survey" , async ( ) => {
24
+
25
+ const response = await request ( app ) . post ( "/surveys" )
26
+ . send ( {
27
+ title : "Title Example1" ,
28
+ description : "Description Example1" ,
15
29
} ) ;
16
- expect ( response . status ) . toBe ( 201 ) ;
17
- expect ( response . body ) . toHaveProperty ( "id" ) ;
30
+
31
+
32
+ expect ( response . status ) . toBe ( 201 ) ;
33
+
34
+
18
35
} ) ;
19
- it ( "should be able to get all surveys" , async ( ) => {
20
- await request ( app ) . post ( "/surveys" ) . send ( {
21
- title :"Title Example2" ,
22
- description :"Description Example2" ,
36
+
37
+ it ( "Should be able to create a new survey" , async ( ) => {
38
+
39
+ const response = await request ( app ) . post ( "/surveys" )
40
+ . send ( {
41
+ title : "Title Example2" ,
42
+ description : "Description Example2" ,
23
43
} ) ;
24
- const response = await request ( app ) . get ( "/surveys" ) ;
25
- expect ( response . body . length ) . toBe ( 2 ) ;
44
+
45
+
46
+ expect ( response . status ) . toBe ( 201 ) ;
47
+
48
+
49
+ expect ( response . body ) . toHaveProperty ( "id" ) ;
26
50
} ) ;
51
+
52
+ it ( "Should be able get all surveys" , async ( ) => {
53
+
54
+ const response = await request ( app ) . get ( "/surveys" ) ;
55
+
56
+
57
+ expect ( response . body . length ) . toBe ( 2 ) ;
58
+ } ) ;
59
+
27
60
} ) ;
0 commit comments