1
1
/**
2
2
* Tests for list.js
3
3
*/
4
- import chai from 'chai' ;
4
+ // import chai from 'chai';
5
5
import request from 'supertest' ;
6
6
7
7
import models from '../../models' ;
8
8
import server from '../../app' ;
9
9
import testUtil from '../../tests/util' ;
10
10
11
- const should = chai . should ( ) ;
11
+ // const should = chai.should();
12
+
13
+ const validateProductTemplates = ( count , resJson , expectedTemplates ) => {
14
+ resJson . should . have . length ( count ) ;
15
+ resJson . forEach ( ( pt , idx ) => {
16
+ pt . should . have . all . keys ( 'id' , 'name' , 'productKey' , 'icon' , 'brief' , 'details' , 'aliases' ,
17
+ 'template' , 'createdBy' , 'createdAt' , 'updatedBy' , 'updatedAt' ) ;
18
+ pt . should . not . have . all . keys ( 'deletedAt' , 'deletedBy' ) ;
19
+ pt . name . should . be . eql ( expectedTemplates [ idx ] . name ) ;
20
+ pt . productKey . should . be . eql ( expectedTemplates [ idx ] . productKey ) ;
21
+ pt . icon . should . be . eql ( expectedTemplates [ idx ] . icon ) ;
22
+ pt . brief . should . be . eql ( expectedTemplates [ idx ] . brief ) ;
23
+ pt . details . should . be . eql ( expectedTemplates [ idx ] . details ) ;
24
+ pt . aliases . should . be . eql ( expectedTemplates [ idx ] . aliases ) ;
25
+ pt . template . should . be . eql ( expectedTemplates [ idx ] . template ) ;
26
+ pt . createdBy . should . be . eql ( expectedTemplates [ idx ] . createdBy ) ;
27
+ pt . updatedBy . should . be . eql ( expectedTemplates [ idx ] . updatedBy ) ;
28
+ } ) ;
29
+ } ;
12
30
13
31
describe ( 'LIST product templates' , ( ) => {
14
32
const templates = [
15
33
{
16
34
name : 'name 1' ,
17
- productKey : 'productKey 1' ,
35
+ productKey : 'productKey- 1' ,
18
36
icon : 'http://example.com/icon1.ico' ,
19
37
brief : 'brief 1' ,
20
38
details : 'details 1' ,
@@ -46,7 +64,7 @@ describe('LIST product templates', () => {
46
64
} ,
47
65
{
48
66
name : 'template 2' ,
49
- productKey : 'productKey 2' ,
67
+ productKey : 'productKey- 2' ,
50
68
icon : 'http://example.com/icon2.ico' ,
51
69
brief : 'brief 2' ,
52
70
details : 'details 2' ,
@@ -83,26 +101,9 @@ describe('LIST product templates', () => {
83
101
} )
84
102
. expect ( 200 )
85
103
. end ( ( err , res ) => {
86
- const template = templates [ 0 ] ;
87
-
88
104
const resJson = res . body . result . content ;
89
- resJson . should . have . length ( 2 ) ;
105
+ validateProductTemplates ( 2 , resJson , templates ) ;
90
106
resJson [ 0 ] . id . should . be . eql ( templateId ) ;
91
- resJson [ 0 ] . name . should . be . eql ( template . name ) ;
92
- resJson [ 0 ] . productKey . should . be . eql ( template . productKey ) ;
93
- resJson [ 0 ] . icon . should . be . eql ( template . icon ) ;
94
- resJson [ 0 ] . brief . should . be . eql ( template . brief ) ;
95
- resJson [ 0 ] . details . should . be . eql ( template . details ) ;
96
- resJson [ 0 ] . aliases . should . be . eql ( template . aliases ) ;
97
- resJson [ 0 ] . template . should . be . eql ( template . template ) ;
98
-
99
- resJson [ 0 ] . createdBy . should . be . eql ( template . createdBy ) ;
100
- should . exist ( resJson [ 0 ] . createdAt ) ;
101
- resJson [ 0 ] . updatedBy . should . be . eql ( template . updatedBy ) ;
102
- should . exist ( resJson [ 0 ] . updatedAt ) ;
103
- should . not . exist ( resJson [ 0 ] . deletedBy ) ;
104
- should . not . exist ( resJson [ 0 ] . deletedAt ) ;
105
-
106
107
done ( ) ;
107
108
} ) ;
108
109
} ) ;
@@ -114,7 +115,12 @@ describe('LIST product templates', () => {
114
115
Authorization : `Bearer ${ testUtil . jwts . connectAdmin } ` ,
115
116
} )
116
117
. expect ( 200 )
117
- . end ( done ) ;
118
+ . end ( ( err , res ) => {
119
+ const resJson = res . body . result . content ;
120
+ validateProductTemplates ( 2 , resJson , templates ) ;
121
+ resJson [ 0 ] . id . should . be . eql ( templateId ) ;
122
+ done ( ) ;
123
+ } ) ;
118
124
} ) ;
119
125
120
126
it ( 'should return 200 for connect manager' , ( done ) => {
@@ -124,7 +130,12 @@ describe('LIST product templates', () => {
124
130
Authorization : `Bearer ${ testUtil . jwts . manager } ` ,
125
131
} )
126
132
. expect ( 200 )
127
- . end ( done ) ;
133
+ . end ( ( err , res ) => {
134
+ const resJson = res . body . result . content ;
135
+ validateProductTemplates ( 2 , resJson , templates ) ;
136
+ resJson [ 0 ] . id . should . be . eql ( templateId ) ;
137
+ done ( ) ;
138
+ } ) ;
128
139
} ) ;
129
140
130
141
it ( 'should return 200 for member' , ( done ) => {
@@ -133,7 +144,12 @@ describe('LIST product templates', () => {
133
144
. set ( {
134
145
Authorization : `Bearer ${ testUtil . jwts . member } ` ,
135
146
} )
136
- . expect ( 200 , done ) ;
147
+ . end ( ( err , res ) => {
148
+ const resJson = res . body . result . content ;
149
+ validateProductTemplates ( 2 , resJson , templates ) ;
150
+ resJson [ 0 ] . id . should . be . eql ( templateId ) ;
151
+ done ( ) ;
152
+ } ) ;
137
153
} ) ;
138
154
139
155
it ( 'should return 200 for copilot' , ( done ) => {
@@ -142,7 +158,26 @@ describe('LIST product templates', () => {
142
158
. set ( {
143
159
Authorization : `Bearer ${ testUtil . jwts . copilot } ` ,
144
160
} )
145
- . expect ( 200 , done ) ;
161
+ . end ( ( err , res ) => {
162
+ const resJson = res . body . result . content ;
163
+ validateProductTemplates ( 2 , resJson , templates ) ;
164
+ resJson [ 0 ] . id . should . be . eql ( templateId ) ;
165
+ done ( ) ;
166
+ } ) ;
167
+ } ) ;
168
+
169
+ it ( 'should return filtered templates' , ( done ) => {
170
+ request ( server )
171
+ . get ( '/v4/productTemplates?filter=productKey%3DproductKey-2' )
172
+ . set ( {
173
+ Authorization : `Bearer ${ testUtil . jwts . manager } ` ,
174
+ } )
175
+ . expect ( 200 )
176
+ . end ( ( err , res ) => {
177
+ const resJson = res . body . result . content ;
178
+ validateProductTemplates ( 1 , resJson , [ templates [ 1 ] ] ) ;
179
+ done ( ) ;
180
+ } ) ;
146
181
} ) ;
147
182
} ) ;
148
183
} ) ;
0 commit comments