@@ -36,48 +36,61 @@ addCommands()
3636// and also to determine paths, urls and the like.
3737let auth
3838Cypress . Commands . overwrite ( 'login' , ( login , user ) => {
39+ cy . window ( ) . then ( ( win ) => {
40+ win . location . href = 'about:blank'
41+ } )
3942 auth = { user : user . userId , password : user . password }
4043 login ( user )
4144} )
4245
4346Cypress . Commands . add ( 'ocsRequest' , ( options ) => {
44- return cy . request ( {
45- form : true ,
46- auth,
47- headers : {
48- 'OCS-ApiRequest' : 'true' ,
49- 'Content-Type' : 'application/x-www-form-urlencoded' ,
50- } ,
51- ...options ,
52- } )
47+ return cy . request ( '/csrftoken' )
48+ . then ( ( { body } ) => body . token )
49+ . then ( requesttoken => {
50+ return cy . request ( {
51+ form : true ,
52+ auth,
53+ headers : {
54+ 'OCS-ApiRequest' : 'true' ,
55+ 'Content-Type' : 'application/x-www-form-urlencoded' ,
56+ requesttoken,
57+ } ,
58+ ...options ,
59+ } )
60+ } )
5361} )
5462
5563Cypress . Commands . add ( 'uploadFile' , ( fileName , mimeType , target ) => {
56- return cy . fixture ( fileName , 'base64 ' )
57- . then ( Cypress . Blob . base64StringToBlob )
64+ return cy . fixture ( fileName , 'binary ' )
65+ . then ( Cypress . Blob . binaryStringToBlob )
5866 . then ( blob => {
59- const file = new File ( [ blob ] , fileName , { type : mimeType } )
6067 if ( typeof target !== 'undefined' ) {
6168 fileName = target
6269 }
63- return cy . request ( '/csrftoken' )
64- . then ( ( { body } ) => body . token )
65- . then ( requesttoken => {
66- return axios . put ( `${ url } /remote.php/webdav/${ fileName } ` , file , {
70+ cy . request ( '/csrftoken' )
71+ . then ( ( { body } ) => {
72+ return cy . wrap ( body . token )
73+ } )
74+ . then ( async ( requesttoken ) => {
75+ return cy . request ( {
76+ url : `${ url } /remote.php/webdav/${ fileName } ` ,
77+ method : 'put' ,
78+ body : blob . size > 0 ? blob : '' ,
79+ auth,
6780 headers : {
6881 requesttoken,
6982 'Content-Type' : mimeType ,
7083 } ,
71- } ) . then ( response => {
72- const fileId = Number (
73- response . headers [ 'oc-fileid' ] ?. split ( 'oc' ) ?. [ 0 ]
74- )
75- cy . log ( `Uploaded ${ fileName } ` ,
76- response . status ,
77- { fileId }
78- )
79- return fileId
8084 } )
85+ } ) . then ( response => {
86+ const fileId = Number (
87+ response . headers [ 'oc-fileid' ] ?. split ( 'oc' ) ?. [ 0 ]
88+ )
89+ cy . log ( `Uploaded ${ fileName } ` ,
90+ response . status ,
91+ { fileId }
92+ )
93+ return cy . wrap ( fileId )
8194 } )
8295 } )
8396} )
@@ -95,27 +108,27 @@ Cypress.Commands.add('downloadFile', (fileName) => {
95108} )
96109
97110Cypress . Commands . add ( 'createFile' , ( target , content , mimeType = 'text/markdown' ) => {
98- const fileName = target . split ( '/' ) . pop ( )
99-
100111 const blob = new Blob ( [ content ] , { type : mimeType } )
101- const file = new File ( [ blob ] , fileName , { type : mimeType } )
102112
103- return cy . window ( )
104- . then ( async win => {
105- const response = await axios . put ( `${ url } /remote.php/webdav/${ target } ` , file , {
113+ return cy . request ( '/csrftoken' )
114+ . then ( ( { body } ) => body . token )
115+ . then ( requesttoken => {
116+ return cy . request ( {
117+ url : `${ url } /remote.php/webdav/${ target } ` ,
118+ method : 'put' ,
119+ body : blob . size > 0 ? blob : '' ,
120+ auth,
106121 headers : {
107- requesttoken : win . OC . requestToken ,
108122 'Content-Type' : mimeType ,
123+ requesttoken,
109124 } ,
125+ } ) . then ( ( response ) => {
126+ return cy . log ( `Uploaded ${ target } ` , response . status )
110127 } )
111-
112- return cy . log ( `Uploaded ${ fileName } ` , response . status )
113128 } )
114-
115129} )
116130
117131Cypress . Commands . add ( 'shareFileToUser' , ( path , targetUser , shareData = { } ) => {
118- cy . clearCookies ( )
119132 cy . ocsRequest ( {
120133 method : 'POST' ,
121134 url : `${ url } /ocs/v2.php/apps/files_sharing/api/v1/shares` ,
@@ -212,7 +225,8 @@ Cypress.Commands.add('createFolder', (target) => {
212225 return cy . request ( '/csrftoken' )
213226 . then ( ( { body } ) => body . token )
214227 . then ( requesttoken => {
215- return axios . request ( `${ rootPath } /${ dirPath } ` , {
228+ return cy . request ( {
229+ url : `${ rootPath } /${ dirPath } ` ,
216230 method : 'MKCOL' ,
217231 auth,
218232 headers : {
0 commit comments