18881: Improves & expands resource handling commands.
[arvados-workbench2.git] / cypress / support / commands.js
index 5a2428b2c5e7764f1f8c1c30cb9a221a7bb61ffc..a28308e3cd6f2db7e9af30ba1bd5068e15cceb00 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;
             })
     }
 )