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 "do_request", (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}`);
56 Cypress.Commands.add("getUser", (username, first_name='', last_name='', is_admin=false, is_active=true) => {
57 // Create user if not already created
58 return cy.do_request('POST', '/auth/controller/callback', {
59 auth_info: JSON.stringify({
60 email: `${username}@example.local`,
62 first_name: first_name,
66 return_to: ',https://example.local'
67 }, null, systemToken, true, false) // Don't follow redirects so we can catch the token
68 .its('headers.location').as('location')
69 // Get its token and set the account up as admin and/or active
71 this.userToken = this.location.split("=")[1]
72 assert.isString(this.userToken)
73 return cy.do_request('GET', '/arvados/v1/users', null, {
74 filters: `[["username", "=", "${username}"]]`
79 cy.do_request('PUT', `/arvados/v1/users/${this.aUser.uuid}`, {
88 return {user: this.theUser, token: this.userToken};