Merge branch '16115-sharing-links'. Closes #16115
[arvados-workbench2.git] / cypress / support / commands.js
index 5764808cb9149d7690e830a6d771771e9c759de8..e98000fc71403462a2f67ffbb0008c804da5c4b0 100644 (file)
@@ -73,30 +73,48 @@ Cypress.Commands.add(
             }),
             return_to: ',https://example.local'
         }, null, systemToken, true, false) // Don't follow redirects so we can catch the token
-            .its('headers.location').as('location')
-            // Get its token and set the account up as admin and/or active
+        .its('headers.location').as('location')
+        // Get its token and set the account up as admin and/or active
+        .then(function () {
+            this.userToken = this.location.split("=")[1]
+            assert.isString(this.userToken)
+            return cy.doRequest('GET', '/arvados/v1/users', null, {
+                filters: `[["username", "=", "${username}"]]`
+            })
+            .its('body.items.0').as('aUser')
             .then(function () {
-                this.userToken = this.location.split("=")[1]
-                assert.isString(this.userToken)
-                return cy.doRequest('GET', '/arvados/v1/users', null, {
-                    filters: `[["username", "=", "${username}"]]`
+                cy.doRequest('PUT', `/arvados/v1/users/${this.aUser.uuid}`, {
+                    user: {
+                        is_admin: is_admin,
+                        is_active: is_active
+                    }
                 })
-                    .its('body.items.0')
-                    .as('aUser')
+                .its('body').as('theUser')
+                .then(function () {
+                    cy.doRequest('GET', '/arvados/v1/api_clients', null, {
+                        filters: `[["is_trusted", "=", false]]`,
+                        order: `["created_at desc"]`
+                    })
+                    .its('body.items').as('apiClients')
                     .then(function () {
-                        cy.doRequest('PUT', `/arvados/v1/users/${this.aUser.uuid}`, {
-                            user: {
-                                is_admin: is_admin,
-                                is_active: is_active
-                            }
-                        })
-                            .its('body')
-                            .as('theUser')
-                            .then(function () {
-                                return { user: this.theUser, token: this.userToken };
+                        if (this.apiClients.length > 0) {
+                            cy.doRequest('PUT', `/arvados/v1/api_clients/${this.apiClients[0].uuid}`, {
+                                api_client: {
+                                    is_trusted: true
+                                }
                             })
+                            .its('body').as('updatedApiClient')
+                            .then(function() {
+                                assert(this.updatedApiClient.is_trusted);
+                            })
+                        }
+                    })
+                    .then(function () {
+                        return { user: this.theUser, token: this.userToken };
                     })
+                })
             })
+        })
     }
 )
 
@@ -135,11 +153,7 @@ Cypress.Commands.add(
 
 Cypress.Commands.add(
     "getCollection", (token, uuid) => {
-        return cy.doRequest('GET', `/arvados/v1/collections/${uuid}`, null, {}, token)
-            .its('body')
-            .then(function (theCollection) {
-                return theCollection;
-            })
+        return cy.getResource(token, 'collections', uuid)
     }
 )
 
@@ -160,6 +174,20 @@ Cypress.Commands.add(
     }
 )
 
+Cypress.Commands.add(
+    "getContainer", (token, uuid) => {
+        return cy.getResource(token, 'containers', uuid)
+    }
+)
+
+Cypress.Commands.add(
+    "updateContainer", (token, uuid, data) => {
+        return cy.updateResource(token, 'containers', uuid, {
+            container: JSON.stringify(data)
+        })
+    }
+)
+
 Cypress.Commands.add(
     'createContainerRequest', (token, data) => {
         return cy.createResource(token, 'container_requests', {
@@ -212,13 +240,23 @@ Cypress.Commands.add(
     }
 )
 
+Cypress.Commands.add(
+    "getResource", (token, suffix, uuid) => {
+        return cy.doRequest('GET', `/arvados/v1/${suffix}/${uuid}`, null, {}, token)
+            .its('body')
+            .then(function (resource) {
+                return resource;
+            })
+    }
+)
+
 Cypress.Commands.add(
     "createResource", (token, suffix, data) => {
         return cy.doRequest('POST', '/arvados/v1/' + suffix, data, null, token, true)
-            .its('body').as('resource')
-            .then(function () {
-                createdResources.push({suffix, uuid: this.resource.uuid});
-                return this.resource;
+            .its('body')
+            .then(function (resource) {
+                createdResources.push({suffix, uuid: resource.uuid});
+                return resource;
             })
     }
 )
@@ -226,19 +264,19 @@ Cypress.Commands.add(
 Cypress.Commands.add(
     "deleteResource", (token, suffix, uuid, failOnStatusCode = true) => {
         return cy.doRequest('DELETE', '/arvados/v1/' + suffix + '/' + uuid, null, null, token, false, true, failOnStatusCode)
-            .its('body').as('resource')
-            .then(function () {
-                return this.resource;
+            .its('body')
+            .then(function (resource) {
+                return resource;
             })
     }
 )
 
 Cypress.Commands.add(
     "updateResource", (token, suffix, uuid, data) => {
-        return cy.doRequest('PUT', '/arvados/v1/' + suffix + '/' + uuid, data, null, token, true)
-            .its('body').as('resource')
-            .then(function () {
-                return this.resource;
+        return cy.doRequest('PATCH', '/arvados/v1/' + suffix + '/' + uuid, data, null, token, true)
+            .its('body')
+            .then(function (resource) {
+                return resource;
             })
     }
 )
@@ -385,7 +423,10 @@ function b64toBlob(b64Data, contentType = '', sliceSize = 512) {
 // From https://github.com/cypress-io/cypress/issues/7306#issuecomment-1076451070=
 // This command requires the async package (https://www.npmjs.com/package/async)
 Cypress.Commands.add('waitForDom', () => {
-    cy.window().then(win => {
+    cy.window().then({
+        // Don't timeout before waitForDom finishes
+        timeout: 10000
+    }, win => {
       let timeElapsed = 0;
 
       cy.log("Waiting for DOM mutations to complete");