16068: Merge branch 'main' of git.arvados.org:arvados-workbench2 into 16068
[arvados-workbench2.git] / cypress / support / commands.js
index 5764808cb9149d7690e830a6d771771e9c759de8..c2d78b54b2e71f3b295bbee47d63a6352193f926 100644 (file)
@@ -135,11 +135,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 +156,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 +222,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 +246,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;
             })
     }
 )