Changeset View
Standalone View
cypress/integration/vault.spec.js
/** | /** | ||||
* Copyright (C) 2019 The Software Heritage developers | * Copyright (C) 2019-2020 The Software Heritage developers | ||||
* See the AUTHORS file at the top-level directory of this distribution | * See the AUTHORS file at the top-level directory of this distribution | ||||
* License: GNU Affero General Public License version 3, or any later version | * License: GNU Affero General Public License version 3, or any later version | ||||
* See top-level LICENSE file for more information | * See top-level LICENSE file for more information | ||||
*/ | */ | ||||
let vaultItems = []; | let vaultItems = []; | ||||
const progressbarColors = { | const progressbarColors = { | ||||
'new': 'rgba(128, 128, 128, 0.5)', | 'new': 'rgba(128, 128, 128, 0.5)', | ||||
'pending': 'rgba(0, 0, 255, 0.5)', | 'pending': 'rgba(0, 0, 255, 0.5)', | ||||
'done': 'rgb(92, 184, 92)' | 'done': 'rgb(92, 184, 92)' | ||||
}; | }; | ||||
function checkVaultCookingTask(objectType) { | function adminLogin() { | ||||
cy.contains('button', 'Actions') | cy.visit('/admin/') | ||||
.click(); | .get('input[name="username"]') | ||||
.type('admin') | |||||
.get('input[name="password"]') | |||||
.type('admin') | |||||
.get('form') | |||||
.submit(); | |||||
ardumont: I read in the cypress doc that it'd be best to avoid using the ui to login and
use internal… | |||||
Done Inline Actions
I do not think we need to do that. The idea to go through the UI is to ensure the login process does not break as the webapp code evolves.
Ack, will put that function in the cypress/utils/index.js file. anlambert: > I read in the cypress doc that it'd be best to avoid using the ui to login and
> use internal… | |||||
Done Inline Actions
Just found your comment while trying to factorize login process. I think I know how to do that. I will open a new diff instead of updating that one. anlambert: > I do not think we need to do that. The idea to go through the UI is to ensure the login… | |||||
Done Inline Actionsanlambert: D3331 | |||||
} | |||||
cy.contains('.dropdown-item', 'Download') | function checkVaultCookingTask(objectType) { | ||||
cy.contains('button', 'Download') | |||||
.click(); | .click(); | ||||
cy.contains('.dropdown-item', objectType) | cy.contains('.dropdown-item', objectType) | ||||
.click(); | .click(); | ||||
cy.wait('@checkVaultCookingTask'); | cy.wait('@checkVaultCookingTask'); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | it('should create a directory cooking task and report its status', function() { | ||||
}).as('checkVaultCookingTask'); | }).as('checkVaultCookingTask'); | ||||
cy.route({ | cy.route({ | ||||
method: 'POST', | method: 'POST', | ||||
url: this.vaultDirectoryUrl, | url: this.vaultDirectoryUrl, | ||||
response: this.genVaultDirCookingResponse('new') | response: this.genVaultDirCookingResponse('new') | ||||
}).as('createVaultCookingTask'); | }).as('createVaultCookingTask'); | ||||
checkVaultCookingTask('as tarball'); | cy.contains('button', 'Download') | ||||
.click(); | |||||
cy.route({ | cy.route({ | ||||
method: 'GET', | method: 'GET', | ||||
url: this.vaultDirectoryUrl, | url: this.vaultDirectoryUrl, | ||||
response: this.genVaultDirCookingResponse('new') | response: this.genVaultDirCookingResponse('new') | ||||
}).as('checkVaultCookingTask'); | }).as('checkVaultCookingTask'); | ||||
// Create a vault cooking task through the GUI | // Create a vault cooking task through the GUI | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | it('should create a directory cooking task and report its status', function() { | ||||
cy.wait('@fetchCookedArchive').then((xhr) => { | cy.wait('@fetchCookedArchive').then((xhr) => { | ||||
assert.isNotNull(xhr.response.body); | assert.isNotNull(xhr.response.body); | ||||
}); | }); | ||||
}); | }); | ||||
it('should create a revision cooking task and report its status', function() { | it('should create a revision cooking task and report its status', function() { | ||||
adminLogin(); | |||||
// Browse a revision | // Browse a revision | ||||
cy.visit(this.revisionUrl); | cy.visit(this.revisionUrl); | ||||
// Stub responses when requesting the vault API to simulate | // Stub responses when requesting the vault API to simulate | ||||
// a task has been created | // a task has been created | ||||
cy.route({ | cy.route({ | ||||
method: 'GET', | method: 'GET', | ||||
▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Lines | cy.route({ | ||||
response: `fx:${this.directory}.tar.gz,binary`, | response: `fx:${this.directory}.tar.gz,binary`, | ||||
headers: { | headers: { | ||||
'Content-disposition': `attachment; filename=${this.directory}.tar.gz`, | 'Content-disposition': `attachment; filename=${this.directory}.tar.gz`, | ||||
'Content-Type': 'application/gzip' | 'Content-Type': 'application/gzip' | ||||
} | } | ||||
}).as('fetchCookedArchive'); | }).as('fetchCookedArchive'); | ||||
// Create a vault cooking task through the GUI | // Create a vault cooking task through the GUI | ||||
checkVaultCookingTask('as tarball'); | cy.contains('button', 'Download') | ||||
.click(); | |||||
// Start archive download through the GUI | // Start archive download through the GUI | ||||
cy.get('.modal-dialog') | cy.get('.modal-dialog') | ||||
.contains('button:visible', 'Ok') | .contains('button:visible', 'Ok') | ||||
.click(); | .click(); | ||||
cy.wait('@fetchCookedArchive'); | cy.wait('@fetchCookedArchive'); | ||||
}); | }); | ||||
it('should offer to immediately download a revision gitfast archive if already cooked', function() { | it('should offer to immediately download a revision gitfast archive if already cooked', function() { | ||||
adminLogin(); | |||||
// Browse a directory | // Browse a directory | ||||
cy.visit(this.revisionUrl); | cy.visit(this.revisionUrl); | ||||
// Stub responses when requesting the vault API to simulate | // Stub responses when requesting the vault API to simulate | ||||
// the directory tarball has already been cooked | // the directory tarball has already been cooked | ||||
cy.route({ | cy.route({ | ||||
method: 'GET', | method: 'GET', | ||||
url: this.vaultRevisionUrl, | url: this.vaultRevisionUrl, | ||||
Show All 29 Lines | it('should offer to recook an object if previous vault task failed', function() { | ||||
// Stub responses when requesting the vault API to simulate | // Stub responses when requesting the vault API to simulate | ||||
// the last cooking of the directory tarball has failed | // the last cooking of the directory tarball has failed | ||||
cy.route({ | cy.route({ | ||||
method: 'GET', | method: 'GET', | ||||
url: this.vaultDirectoryUrl, | url: this.vaultDirectoryUrl, | ||||
response: this.genVaultDirCookingResponse('failed') | response: this.genVaultDirCookingResponse('failed') | ||||
}).as('checkVaultCookingTask'); | }).as('checkVaultCookingTask'); | ||||
checkVaultCookingTask('as tarball'); | cy.contains('button', 'Download') | ||||
.click(); | |||||
// Check that recooking the directory is offered to user | // Check that recooking the directory is offered to user | ||||
cy.get('.modal-dialog') | cy.get('.modal-dialog') | ||||
.contains('button:visible', 'Ok') | .contains('button:visible', 'Ok') | ||||
.should('be.visible'); | .should('be.visible'); | ||||
}); | }); | ||||
}); | }); |
I read in the cypress doc that it'd be best to avoid using the ui to login and
use internal authentication api instead. I tried to start something about it
but failed to make it ok ¯\_(ツ)_/¯ so far.
I guess, we'll tackle this later.
Although, note that we kinda use this snippet in multiple locations now (each
time we need to login in the admin page so that'd be deposit, the main admin
page test and here i guess).
Maybe there we could define this as a main function we can reuse?
What do you think?