1- const uuidv4 = require ( "uuid/v4 " ) ;
1+ const { v4 : uuidv4 } = require ( "uuid" ) ;
22
33// TODO: Envify here and cypress.json properly
4- const API_URL = Cypress . config ( ) . apiUrl ;
4+ const API_URL = Cypress . env ( "API_URL" ) ;
55const TEST_PREFIX = "CY-TEST" ;
66
77describe ( "Basic functionalities" , ( ) => {
@@ -34,8 +34,7 @@ describe("Basic functionalities", () => {
3434
3535 it ( "Add list, select it for use and show it" , ( ) => {
3636 const uuid = `${ TEST_PREFIX } -${ uuidv4 ( ) } ` ;
37- cy . server ( ) ;
38- cy . route ( "POST" , `${ API_URL } /builds` ) . as ( "postBuild" ) ;
37+ cy . intercept ( "POST" , `${ API_URL } /builds` ) . as ( "postBuild" ) ;
3938
4039 cy . get ( "[data-cy=toggle-mode-button]" ) . click ( ) ;
4140 cy . get ( "[data-cy=new-list-button" ) . click ( ) ;
@@ -153,14 +152,12 @@ describe("Basic functionalities", () => {
153152 it ( "Generate poster" , ( ) => {
154153 const uuid = `${ TEST_PREFIX } -${ uuidv4 ( ) } ` ;
155154 const posterName = uuid . substr ( 0 , 5 ) ;
156- cy . server ( ) ;
157- cy . route ( "POST" , `${ API_URL } /builds` ) . as ( "postBuild" ) ;
155+
156+ cy . intercept ( "POST" , `${ API_URL } /builds` ) . as ( "postBuild" ) ;
158157
159158 cy . get ( "[data-cy=toggle-mode-button]" ) . click ( ) ;
160- cy . get ( "[data-cy=new-list-button" ) . click ( ) ;
161- cy . get ( "[data-cy=new-list-name-input]" )
162- . click ( )
163- . type ( uuid ) ;
159+ cy . get ( "[data-cy=new-list-button]" ) . click ( ) ;
160+ cy . get ( "[data-cy=new-list-name-input]" ) . click ( ) . type ( uuid ) ;
164161
165162 cy . get ( "[data-cy=new-list-name-input]" ) . should ( "have.value" , uuid ) ;
166163 cy . get ( "[data-cy=add-list-button]" ) . click ( ) ;
@@ -170,33 +167,25 @@ describe("Basic functionalities", () => {
170167 cy . get ( "[data-cy=select-list-button]" ) . click ( ) ;
171168
172169 cy . get ( "[data-cy=size-selector-button]" ) . click ( ) ;
173- cy . get ( "[data-cy=size-selector-width-input]" )
174- . click ( )
175- . clear ( )
176- . type ( 200 ) ;
177- cy . get ( "[data-cy=size-selector-height-input]" )
178- . click ( )
179- . clear ( )
180- . type ( 200 ) ;
170+ cy . get ( "[data-cy=size-selector-width-input]" ) . click ( ) . clear ( ) . type ( 200 ) ;
171+ cy . get ( "[data-cy=size-selector-height-input]" ) . click ( ) . clear ( ) . type ( 200 ) ;
181172
182173 cy . get ( "[data-cy=new-poster-name]" ) . type ( posterName ) ;
183- cy . get ( "[data-cy=generate-button" ) . click ( ) ;
184- cy . get ( "[data-cy=close-generate-prompt-button" ) . click ( ) ;
174+ cy . get ( "[data-cy=generate-button] " ) . click ( ) ;
175+ cy . get ( "[data-cy=close-generate-prompt-button] " ) . click ( ) ;
185176 cy . get ( "[data-cy=show-list-button]" ) . click ( ) ;
186177
187- // 60 seconds should be more than enough for 200x200 poster.
188- // Better implementation would be to somehow stop waiting after
189- // polling for build status returns "pending: 0".
190178 cy . wait ( 60000 ) ;
191179 cy . get ( `[data-cy=${ posterName } ]` ) . contains ( "READY" ) ;
192180
193- // Remove build
194181 cy . request ( "GET" , `${ API_URL } /builds` )
195182 . its ( "body" )
196183 . then ( ( buildArr ) => {
197- const build = buildArr . find ( ( build ) => build . title === uuid ) ;
198- cy . request ( "DELETE" , `${ API_URL } /builds/${ build . id } ` ) ;
199- } ) ;
184+ const build = buildArr . find ( ( b ) => b . title === uuid ) ;
185+ if ( build ) {
186+ cy . request ( "DELETE" , `${ API_URL } /builds/${ build . id } ` ) ;
187+ }
188+ } ) ;
200189
201190 cy . get ( "[data-cy=close-list-modal-button]" ) . click ( ) ;
202191 } ) ;
0 commit comments