1
+ const expect = require ( 'chai' ) . expect
2
+ const app = require ( '../routing.js' )
3
+
4
+ const request = require ( 'supertest' ) ( app )
5
+
6
+ ////////////////////////////
7
+ /////// PREPARES ///////
8
+ ////////////////////////////
9
+
10
+ describe ( 'POST/prepare endpoint' , ( ) => {
11
+ describe ( 'response' , ( ) => {
12
+ before ( ( ) => {
13
+ this . testObj = {
14
+ words : [ 'yo' , 'el abuelo' , 'estar' , 'ir a' , 'mi' , 'casa' , 'linda' , 'ahora' ] ,
15
+ types : [ 'SUBJ' , 'SUBJ' , 'VERB' , 'VERB' , 'PREP' , 'NOUN' , 'MOD' , 'MISC' ] ,
16
+ language : 'es' ,
17
+ props : { }
18
+ }
19
+
20
+ this . response = request . post ( '/prepare' ) . send ( this . testObj )
21
+ } )
22
+
23
+ it ( 'Should return a correct status and an array in sentence' , async ( ) => {
24
+ const res = await this . response ;
25
+ expect ( res . status ) . to . equal ( 200 ) ;
26
+ expect ( res . body ) . to . include . keys ( 'sentence' ) ;
27
+ expect ( res . body . sentence . length ) . to . exist ;
28
+ } )
29
+ } )
30
+ describe ( 'error' , ( ) => {
31
+ it ( 'Should return status 400 if words and types have different length' , async ( ) => {
32
+ const res = await request . post ( '/prepare' ) . send ( {
33
+ words : [ 'hola' , 'tener' , 'sueño' ] ,
34
+ types : [ 'VERB' , 'NOUN' ] ,
35
+ language : 'es' ,
36
+ props : { }
37
+ } )
38
+ expect ( res . status ) . to . equal ( 400 ) ;
39
+ expect ( res . body ) . to . include . keys ( 'error' ) ;
40
+ } )
41
+ it ( 'Should return status 500 if words a key has an improper value' , async ( ) => {
42
+ const res = await request . post ( '/prepare' ) . send ( {
43
+ words : 'hola' ,
44
+ types : [ 'VERB' , 'NOUN' ] ,
45
+ language : 'es' ,
46
+ props : { }
47
+ } )
48
+ expect ( res . status ) . to . equal ( 500 ) ;
49
+ expect ( res . body ) . to . include . keys ( 'error' ) ;
50
+ } )
51
+ } )
52
+ } )
53
+
54
+ ////////////////////////////
55
+ /////// PARSE ///////
56
+ ////////////////////////////
57
+
58
+ describe ( 'POST/parse endpoint' , ( ) => {
59
+ describe ( 'response' , ( ) => {
60
+ before ( ( ) => {
61
+ this . testObj = {
62
+ words : [ 'yo' , 'el abuelo' , 'estar' , 'ir a' , 'mi' , 'casa' , 'linda' , 'ahora' ] ,
63
+ types : [ 'SUBJ' , 'SUBJ' , 'VERB' , 'VERB' , 'PREP' , 'NOUN' , 'MOD' , 'MISC' ] ,
64
+ language : 'es' ,
65
+ props : { }
66
+ }
67
+
68
+ this . response = request . post ( '/parse' ) . send ( this . testObj )
69
+ } )
70
+
71
+ it ( 'Should return a correct status and an array in sentence' , async ( ) => {
72
+ const res = await this . response ;
73
+ expect ( res . status ) . to . equal ( 200 ) ;
74
+ expect ( res . body ) . to . include . keys ( 'sentence' ) ;
75
+ expect ( res . body . sentence . length ) . to . exist ;
76
+ } )
77
+ } )
78
+ describe ( 'error' , ( ) => {
79
+ it ( 'Should return status 400 if words and types have different length' , async ( ) => {
80
+ const res = await request . post ( '/prepare' ) . send ( {
81
+ words : [ 'hola' , 'tener' , 'sueño' ] ,
82
+ types : [ 'VERB' , 'NOUN' ] ,
83
+ language : 'es' ,
84
+ props : { }
85
+ } )
86
+ expect ( res . status ) . to . equal ( 400 ) ;
87
+ expect ( res . body ) . to . include . keys ( 'error' ) ;
88
+ } )
89
+ it ( 'Should return status 500 if words a key has an improper value' , async ( ) => {
90
+ const res = await request . post ( '/prepare' ) . send ( {
91
+ words : 'hola' ,
92
+ types : [ 'VERB' , 'NOUN' ] ,
93
+ language : 'es' ,
94
+ props : { }
95
+ } )
96
+ expect ( res . status ) . to . equal ( 500 ) ;
97
+ expect ( res . body ) . to . include . keys ( 'error' ) ;
98
+ } )
99
+ } )
100
+ } )
101
+
102
+ ////////////////////////////
103
+ /////// DEPENDATE ///////
104
+ ////////////////////////////
105
+
106
+ describe ( 'POST/process endpoint' , ( ) => {
107
+ describe ( 'response' , ( ) => {
108
+ before ( ( ) => {
109
+ this . testObj = {
110
+ words : [ 'yo' , 'el abuelo' , 'estar' , 'ir a' , 'mi' , 'casa' , 'linda' , 'ahora' ] ,
111
+ types : [ 'SUBJ' , 'SUBJ' , 'VERB' , 'VERB' , 'PREP' , 'NOUN' , 'MOD' , 'MISC' ] ,
112
+ language : 'es' ,
113
+ props : { }
114
+ }
115
+
116
+ this . response = request . post ( '/process' ) . send ( this . testObj )
117
+ } )
118
+
119
+ it ( 'Should return a correct status and an array in sentence' , async ( ) => {
120
+ const res = await this . response ;
121
+ expect ( res . status ) . to . equal ( 200 ) ;
122
+ expect ( res . body ) . to . include . keys ( 'sentence' ) ;
123
+ expect ( res . body . sentence . length ) . to . exist ;
124
+ } )
125
+ } )
126
+ describe ( 'error' , ( ) => {
127
+ it ( 'Should return status 400 if words and types have different length' , async ( ) => {
128
+ const res = await request . post ( '/prepare' ) . send ( {
129
+ words : [ 'hola' , 'tener' , 'sueño' ] ,
130
+ types : [ 'VERB' , 'NOUN' ] ,
131
+ language : 'es' ,
132
+ props : { }
133
+ } )
134
+ expect ( res . status ) . to . equal ( 400 ) ;
135
+ expect ( res . body ) . to . include . keys ( 'error' ) ;
136
+ } )
137
+ it ( 'Should return status 500 if words a key has an improper value' , async ( ) => {
138
+ const res = await request . post ( '/prepare' ) . send ( {
139
+ words : 'hola' ,
140
+ types : [ 'VERB' , 'NOUN' ] ,
141
+ language : 'es' ,
142
+ props : { }
143
+ } )
144
+ expect ( res . status ) . to . equal ( 500 ) ;
145
+ expect ( res . body ) . to . include . keys ( 'error' ) ;
146
+ } )
147
+ } )
148
+ } )
149
+
150
+ ////////////////////////////
151
+ /////// REALISE ///////
152
+ ////////////////////////////
153
+
154
+ describe ( 'POST/realise endpoint' , ( ) => {
155
+ describe ( 'response' , ( ) => {
156
+ before ( ( ) => {
157
+ this . testObj = {
158
+ words : [ 'yo' , 'el abuelo' , 'estar' , 'ir a' , 'mi' , 'casa' , 'linda' , 'ahora' ] ,
159
+ types : [ 'SUBJ' , 'SUBJ' , 'VERB' , 'VERB' , 'PREP' , 'NOUN' , 'MOD' , 'MISC' ] ,
160
+ language : 'es' ,
161
+ props : { }
162
+ }
163
+
164
+ this . response = request . post ( '/realise' ) . send ( this . testObj )
165
+ } )
166
+
167
+ it ( 'Should return a correct status and an array in sentence' , async ( ) => {
168
+ const res = await this . response ;
169
+ expect ( res . status ) . to . equal ( 200 ) ;
170
+ expect ( res . body ) . to . include . keys ( 'sentence' ) ;
171
+ expect ( res . body . sentence . length ) . to . exist ;
172
+ } )
173
+ } )
174
+ describe ( 'error' , ( ) => {
175
+ it ( 'Should return status 400 if words and types have different length' , async ( ) => {
176
+ const res = await request . post ( '/prepare' ) . send ( {
177
+ words : [ 'hola' , 'tener' , 'sueño' ] ,
178
+ types : [ 'VERB' , 'NOUN' ] ,
179
+ language : 'es' ,
180
+ props : { }
181
+ } )
182
+ expect ( res . status ) . to . equal ( 400 ) ;
183
+ expect ( res . body ) . to . include . keys ( 'error' ) ;
184
+ } )
185
+ it ( 'Should return status 500 if words a key has an improper value' , async ( ) => {
186
+ const res = await request . post ( '/prepare' ) . send ( {
187
+ words : 'hola' ,
188
+ types : [ 'VERB' , 'NOUN' ] ,
189
+ language : 'es' ,
190
+ props : { }
191
+ } )
192
+ expect ( res . status ) . to . equal ( 500 ) ;
193
+ expect ( res . body ) . to . include . keys ( 'error' ) ;
194
+ } )
195
+ } )
196
+ } )
197
+
198
+ ////////////////////////////
199
+ /////// REPLICATE ///////
200
+ ////////////////////////////
201
+
202
+ describe ( 'POST/replicate endpoint' , ( ) => {
203
+ describe ( 'response' , ( ) => {
204
+ before ( ( ) => {
205
+ this . testObj = {
206
+ words : [ 'yo' , 'el abuelo' , 'estar' , 'ir a' , 'mi' , 'casa' , 'linda' , 'ahora' ] ,
207
+ types : [ 'SUBJ' , 'SUBJ' , 'VERB' , 'VERB' , 'PREP' , 'NOUN' , 'MOD' , 'MISC' ] ,
208
+ language : 'es' ,
209
+ props : { }
210
+ }
211
+
212
+ this . response = request . post ( '/replicate' ) . send ( this . testObj )
213
+ } )
214
+
215
+ it ( 'Should replicate the request object' , async ( ) => {
216
+ const res = await this . response ;
217
+ expect ( res . status ) . to . equal ( 200 )
218
+ expect ( res . body ) . to . include . keys ( Object . keys ( this . testObj ) )
219
+ expect ( res . body . words ) . to . eql ( this . testObj . words )
220
+ expect ( res . body . types ) . to . eql ( this . testObj . types )
221
+ expect ( res . body . language ) . to . eql ( this . testObj . language )
222
+ expect ( res . body . props ) . to . eql ( this . testObj . props )
223
+ } )
224
+ } )
225
+ } )
0 commit comments