20219: Switch log panel requests to use live log endpoint, adjust tests to match
[arvados-workbench2.git] / cypress / support / commands.js
index e4f6fd603a12bbca7e5e3fb31cb5cdea338841a0..24629d993a90b9e99e6839e4c8c93b7be8eb0a66 100644 (file)
@@ -34,6 +34,8 @@ const controllerURL = Cypress.env('controller_url');
 const systemToken = Cypress.env('system_token');
 let createdResources = [];
 
+const containerLogFolderPrefix = 'log for container ';
+
 // Clean up on a 'before' hook to allow post-mortem analysis on individual tests.
 beforeEach(function () {
     if (createdResources.length === 0) {
@@ -192,6 +194,12 @@ Cypress.Commands.add(
     }
 )
 
+Cypress.Commands.add(
+    "collectionReplaceFiles", (token, uuid, data) => {
+        return cy.updateResource(token, 'collections', uuid, JSON.stringify(data))
+    }
+)
+
 Cypress.Commands.add(
     "getContainer", (token, uuid) => {
         return cy.getResource(token, 'containers', uuid)
@@ -237,18 +245,19 @@ Cypress.Commands.add(
         cy.getContainerRequest(token, crUuid).then((containerRequest) => {
             if (containerRequest.log_uuid) {
                 cy.listContainerRequestLogs(token, crUuid).then((logFiles) => {
+                    const filePath = `${containerRequest.log_uuid}/${containerLogFolderPrefix}${containerRequest.container_uuid}/${fileName}`;
                     if (logFiles.find((file) => (file.name === fileName))) {
                         // File exists, fetch and append
                         return cy.doKeepRequest(
                                 "GET",
-                                `c=${containerRequest.log_uuid}/${fileName}`,
+                                `c=${filePath}`,
                                 null,
                                 null,
                                 token
                             )
                             .then(({ body: contents }) => cy.doKeepRequest(
                                 "PUT",
-                                `c=${containerRequest.log_uuid}/${fileName}`,
+                                `c=${filePath}`,
                                 contents.split("\n").concat(lines).join("\n"),
                                 null,
                                 token
@@ -257,37 +266,44 @@ Cypress.Commands.add(
                         // File not exists, put new file
                         cy.doKeepRequest(
                             "PUT",
-                            `c=${containerRequest.log_uuid}/${fileName}`,
+                            `c=${filePath}`,
                             lines.join("\n"),
                             null,
                             token
                         )
                     }
                 });
-                // Fetch current log contents and append new line
-                // let newLines = [...lines];
-                // return cy.doKeepRequest('GET', `c=${containerRequest.log_uuid}/${fileName}`, null, null, token)
-                //     .then(({body: contents}) => {
-                //         newLines = [contents.split('\n'), ...newLines];
-                //     })
-                //     .then(() => (
-                //         cy.doKeepRequest('PUT', `c=${containerRequest.log_uuid}/${fileName}`, newLines.join('\n'), null, token)
-                //     ));
             } else {
                 // Create log collection
                 return cy.createCollection(token, {
                     name: `Test log collection ${Math.floor(Math.random() * 999999)}`,
                     owner_uuid: containerRequest.owner_uuid,
                     manifest_text: ""
-                }).then((collection) => (
+                }).then((collection) => {
                     // Update CR log_uuid to fake log collection
                     cy.updateContainerRequest(token, containerRequest.uuid, {
                         log_uuid: collection.uuid,
                     }).then(() => (
-                        // Put new log file with contents into fake log collection
-                        cy.doKeepRequest('PUT', `c=${collection.uuid}/${fileName}`, lines.join('\n'), null, token)
-                    ))
-                ));
+                        // Create empty directory for container uuid
+                        cy.collectionReplaceFiles(token, collection.uuid, {
+                            collection: {
+                                preserve_version: true,
+                            },
+                            replace_files: {
+                                [`/${containerLogFolderPrefix}${containerRequest.container_uuid}`]: "d41d8cd98f00b204e9800998ecf8427e+0"
+                            }
+                        }).then(() => (
+                            // Put new log file with contents into fake log collection
+                            cy.doKeepRequest(
+                                'PUT',
+                                `c=${collection.uuid}/${containerLogFolderPrefix}${containerRequest.container_uuid}/${fileName}`,
+                                lines.join('\n'),
+                                null,
+                                token
+                            )
+                        ))
+                    ));
+                });
             }
         })
     )
@@ -296,7 +312,7 @@ Cypress.Commands.add(
 Cypress.Commands.add(
     "listContainerRequestLogs", (token, crUuid) => (
         cy.getContainerRequest(token, crUuid).then((containerRequest) => (
-            cy.doKeepRequest('PROPFIND', `c=${containerRequest.log_uuid}`, null, null, token)
+            cy.doKeepRequest('PROPFIND', `c=${containerRequest.log_uuid}/${containerLogFolderPrefix}${containerRequest.container_uuid}`, null, null, token)
                 .then(({body: data}) => {
                     return extractFilesData(new DOMParser().parseFromString(data, "text/xml"));
                 })