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);
119 Cypress.Commands.add(
120 "createCollection", (token, data) => {
121 return cy.createResource(token, 'collections', {
122 collection: JSON.stringify(data),
123 ensure_unique_name: true
128 Cypress.Commands.add(
129 "createResource", (token, suffix, data) => {
130 return cy.doRequest('POST', '/arvados/v1/'+suffix, data, null, token, true)
131 .its('body').as('resource')
133 return this.resource;
138 Cypress.Commands.add(
139 "deleteResource", (token, suffix, uuid) => {
140 return cy.doRequest('DELETE', '/arvados/v1/'+suffix+'/'+uuid)
141 .its('body').as('resource')
143 return this.resource;
148 Cypress.Commands.add(
149 "loginAs", (user) => {
150 cy.visit(`/token/?api_token=${user.token}`);
151 cy.url().should('contain', '/projects/');
152 cy.get('div#root').should('contain', 'Arvados Workbench (zzzzz)');
153 cy.get('div#root').should('not.contain', 'Your account is inactive');