1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 // ***********************************************
6 // This example commands.js shows you how to
7 // create various custom commands and overwrite
10 // For more comprehensive examples of custom
11 // commands please read more here:
12 // https://on.cypress.io/custom-commands
13 // ***********************************************
16 // -- This is a parent command --
17 // Cypress.Commands.add("login", (email, password) => { ... })
20 // -- This is a child command --
21 // Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
24 // -- This is a dual command --
25 // Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
28 // -- This will overwrite an existing command --
29 // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
31 const controllerURL = Cypress.env('controller_url');
32 const systemToken = Cypress.env('system_token');
35 "doRequest", (method = 'GET', path = '', data = null, qs = null,
36 token = systemToken, auth = false, followRedirect = true) => {
39 url: `${controllerURL}/${path}`,
41 qs: auth ? qs : Object.assign({ api_token: token }, qs),
42 auth: auth ? { bearer: `${token}` } : undefined,
43 followRedirect: followRedirect
48 // This resets the DB removing all content and seeding it with the fixtures.
49 // TODO: Maybe we can add an optional param to avoid the loading part?
52 cy.request('POST', `${controllerURL}/database/reset?api_token=${systemToken}`);
57 "getUser", (username, first_name = '', last_name = '', is_admin = false, is_active = true) => {
58 // Create user if not already created
59 return cy.doRequest('POST', '/auth/controller/callback', {
60 auth_info: JSON.stringify({
61 email: `${username}@example.local`,
63 first_name: first_name,
67 return_to: ',https://example.local'
68 }, null, systemToken, true, false) // Don't follow redirects so we can catch the token
69 .its('headers.location').as('location')
70 // Get its token and set the account up as admin and/or active
72 this.userToken = this.location.split("=")[1]
73 assert.isString(this.userToken)
74 return cy.doRequest('GET', '/arvados/v1/users', null, {
75 filters: `[["username", "=", "${username}"]]`
80 cy.doRequest('PUT', `/arvados/v1/users/${this.aUser.uuid}`, {
89 return { user: this.theUser, token: this.userToken };
97 "createLink", (token, data) => {
98 return cy.createResource(token, 'links', {
99 link: JSON.stringify(data)
104 Cypress.Commands.add(
105 "createGroup", (token, data) => {
106 return cy.createResource(token, 'groups', {
107 group: JSON.stringify(data),
108 ensure_unique_name: true
113 Cypress.Commands.add(
114 "trashGroup", (token, uuid) => {
115 return cy.deleteResource(token, 'groups', uuid);
120 Cypress.Commands.add(
121 "createWorkflow", (token, data) => {
122 return cy.createResource(token, 'workflows', {
123 workflow: JSON.stringify(data),
124 ensure_unique_name: true
129 Cypress.Commands.add(
130 "createCollection", (token, data) => {
131 return cy.createResource(token, 'collections', {
132 collection: JSON.stringify(data),
133 ensure_unique_name: true
138 Cypress.Commands.add(
139 "updateCollection", (token, uuid, data) => {
140 return cy.updateResource(token, 'collections', uuid, {
141 collection: JSON.stringify(data)
146 Cypress.Commands.add(
147 "createResource", (token, suffix, data) => {
148 return cy.doRequest('POST', '/arvados/v1/' + suffix, data, null, token, true)
149 .its('body').as('resource')
151 return this.resource;
156 Cypress.Commands.add(
157 "deleteResource", (token, suffix, uuid) => {
158 return cy.doRequest('DELETE', '/arvados/v1/' + suffix + '/' + uuid)
159 .its('body').as('resource')
161 return this.resource;
166 Cypress.Commands.add(
167 "updateResource", (token, suffix, uuid, data) => {
168 return cy.doRequest('PUT', '/arvados/v1/' + suffix + '/' + uuid, data, null, token, true)
169 .its('body').as('resource')
171 return this.resource;
176 Cypress.Commands.add(
177 "loginAs", (user) => {
178 cy.visit(`/token/?api_token=${user.token}`);
179 cy.url().should('contain', '/projects/');
180 cy.get('div#root').should('contain', 'Arvados Workbench (zzzzz)');
181 cy.get('div#root').should('not.contain', 'Your account is inactive');
185 Cypress.Commands.add(
186 "doSearch", (searchTerm) => {
187 cy.get('[data-cy=searchbar-input-field]').type(`{selectall}${searchTerm}{enter}`);
191 Cypress.Commands.add('getAll', (...elements) => {
192 const promise = cy.wrap([], { log: false })
194 for (let element of elements) {
195 promise.then(arr => cy.get(element).then(got => cy.wrap([...arr, got])))
201 Cypress.Commands.add('shareWith', (srcUserToken, targetUserUUID, itemUUID, permission = 'can_write') => {
202 cy.createLink(srcUserToken, {
204 link_class: 'permission',
206 tail_uuid: targetUserUUID
210 Cypress.Commands.add('addToFavorites', (activeUserToken, activeUserUUID, itemUUID) => {
211 cy.createLink(activeUserToken, {
215 owner_uuid: activeUserUUID,
216 tail_uuid: activeUserUUID,
220 Cypress.Commands.add('createProject', ({
227 const writePermission = canWrite ? 'can_write' : 'can_read';
229 cy.createGroup(owningUser.token, {
230 name: `${projectName} ${Math.floor(Math.random() * 999999)}`,
231 group_class: 'project',
232 }).as(`${projectName}`).then((project) => {
233 if (targetUser && targetUser !== owningUser) {
234 cy.shareWith(owningUser.token, targetUser.user.uuid, project.uuid, writePermission);
236 if (addToFavorites) {
237 const user = targetUser ? targetUser : owningUser;
238 cy.addToFavorites(user.token, user.user.uuid, project.uuid);