Commit 8f370433 authored by Bogdan Cochior's avatar Bogdan Cochior

test: update submitManuscript via API

parent ab7c398d
......@@ -26,31 +26,27 @@
// -- This is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
const fileTypes = {
pdf: 'application/pdf',
doc: 'application/msword',
docx:
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
txt: 'text/plain',
excel: 'application/vnd.ms-excel',
xlm: 'application/vnd.ms-excel',
}
Cypress.Commands.add(
'uploadFile',
({ fileName, fileType = 'pdf', filePicker }) => {
cy
.fixture(fileName, 'base64')
.then(Cypress.Blob.base64StringToBlob)
.then(blob => {
const el = filePicker[0]
const testFile = new File([blob], fileName, {
type: fileTypes[fileType],
})
const dataTransfer = new DataTransfer()
dataTransfer.items.add(testFile)
el.files = dataTransfer.files
({ fragmentId, fileType = 'manuscripts', token }) => {
const data = new FormData()
const file = new File(['some text'], 'filename.pdf', { type: 'text/plain' })
data.append('fileType', fileType)
data.append('fragmentId', fragmentId)
data.append('file', file)
data.append('newName', 'filename.pdf')
return cy
.request({
method: 'POST',
url: '/api/files',
headers: {
Accept: 'text/plain',
Authorization: `Bearer ${token}`,
},
body: data,
})
.then(response => response)
},
)
......@@ -92,7 +88,12 @@ Cypress.Commands.add('searchManuscriptByFragmentId', () => {
Cypress.Commands.add(
'createManuscriptViaAPI',
(author = { email: 'admin', password: 'password' }) => {
(
author = {
email: `admin`,
password: 'password',
},
) => {
let fragmentID = null
let collectionID = null
......@@ -106,9 +107,9 @@ Cypress.Commands.add(
Authorization: `Bearer ${userToken}`,
},
body: {
type: 'collection',
owners: [],
fragments: [],
customId: Math.random()
.toString()
.slice(-7),
},
})
.then(response => {
......@@ -128,33 +129,9 @@ Cypress.Commands.add(
body: {
created: Date.now(),
files: {
coverLetter: [
{
id:
'db1038c0-afb0-4b40-8913-53fc03f13fa7/2bfe9174-67fc-4e5f-8108-ed8761c053be',
originalName: 'scimakelatex.23367.sab+d.sab+nr+2.pdf',
name: 'scimakelatex.23367.sab+d.sab+nr+2.pdf',
size: 71312,
},
],
manuscripts: [
{
id:
'db1038c0-afb0-4b40-8913-53fc03f13fa7/2bfe9174-67fc-4e5f-8108-ed8761c053be',
originalName: 'scimakelatex.23367.sab+d.sab+nr+2.pdf',
name: 'scimakelatex.23367.sab+d.sab+nr+2.pdf',
size: 71312,
},
],
supplementary: [
{
id:
'db1038c0-afb0-4b40-8913-53fc03f13fa7/2bfe9174-67fc-4e5f-8108-ed8761c053be',
originalName: 'scimakelatex.23367.sab+d.sab+nr+2.pdf',
name: 'scimakelatex.23367.sab+d.sab+nr+2.pdf',
size: 71312,
},
],
coverLetter: [],
manuscripts: [],
supplementary: [],
},
fragmentType: 'version',
metadata: {
......@@ -164,8 +141,6 @@ Cypress.Commands.add(
},
version: 1,
collectionId: collectionID,
type: 'fragment',
owners: [],
},
})
})
......@@ -196,6 +171,7 @@ Cypress.Commands.add(
})
Cypress.env('fragmentId', fragmentID)
})
// .then(() => cy.uploadFile({ fragmentId: fragmentID, token: userToken }))
.then(() => {
cy.request({
method: 'POST',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment