Changeset View
Changeset View
Standalone View
Standalone View
cypress/integration/vault.spec.js
/** | /** | ||||
* Copyright (C) 2019-2021 The Software Heritage developers | * Copyright (C) 2019-2021 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 | ||||
*/ | */ | ||||
const 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 checkVaultCookingTask(objectType) { | ||||
cy.contains('button', 'Download') | cy.contains('button', 'Download') | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | before(function() { | ||||
this.revision = this.origin[1].revisions[0]; | this.revision = this.origin[1].revisions[0]; | ||||
this.revisionUrl = this.Urls.browse_revision(this.revision); | this.revisionUrl = this.Urls.browse_revision(this.revision); | ||||
this.vaultRevisionUrl = this.Urls.api_1_vault_cook_revision_gitfast(this.revision); | this.vaultRevisionUrl = this.Urls.api_1_vault_cook_revision_gitfast(this.revision); | ||||
this.vaultFetchRevisionUrl = this.Urls.api_1_vault_fetch_revision_gitfast(this.revision); | this.vaultFetchRevisionUrl = this.Urls.api_1_vault_fetch_revision_gitfast(this.revision); | ||||
const release = this.origin[1].release; | const release = this.origin[1].release; | ||||
this.releaseUrl = this.Urls.browse_release(release.id) + `?origin_url=${this.origin[1].url}`; | this.releaseUrl = this.Urls.browse_release(release.id) + `?origin_url=${this.origin[1].url}`; | ||||
this.vaultReleaseDirectoryUrl = this.Urls.api_1_vault_cook_directory(release.directory); | this.vaultReleaseDirectoryUrl = this.Urls.api_1_vault_cook_directory(release.directory); | ||||
}); | |||||
vaultItems[0] = { | beforeEach(function() { | ||||
// For some reason, this gets reset if we define it in the before() hook, | |||||
// so we need to define it here | |||||
this.vaultItems = [ | |||||
{ | |||||
'object_type': 'revision', | 'object_type': 'revision', | ||||
'object_id': this.revision, | 'object_id': this.revision, | ||||
'email': '', | 'email': '', | ||||
'status': 'done', | 'status': 'done', | ||||
'fetch_url': `/api/1/vault/revision/${this.revision}/gitfast/raw/`, | 'fetch_url': `/api/1/vault/revision/${this.revision}/gitfast/raw/`, | ||||
'progress_message': null | 'progress_message': null | ||||
}; | } | ||||
}); | ]; | ||||
beforeEach(function() { | |||||
this.genVaultDirCookingResponse = (status, message = null) => { | this.genVaultDirCookingResponse = (status, message = null) => { | ||||
return genVaultCookingResponse('directory', this.directory, status, | return genVaultCookingResponse('directory', this.directory, status, | ||||
message, this.vaultFetchDirectoryUrl); | message, this.vaultFetchDirectoryUrl); | ||||
}; | }; | ||||
this.genVaultRevCookingResponse = (status, message = null) => { | this.genVaultRevCookingResponse = (status, message = null) => { | ||||
return genVaultCookingResponse('revision', this.revision, status, | return genVaultCookingResponse('revision', this.revision, status, | ||||
message, this.vaultFetchRevisionUrl); | message, this.vaultFetchRevisionUrl); | ||||
▲ Show 20 Lines • Show All 256 Lines • ▼ Show 20 Lines | it('should create a directory cooking task from the release view', function() { | ||||
// Check success alert is displayed | // Check success alert is displayed | ||||
cy.get('.alert-success') | cy.get('.alert-success') | ||||
.should('be.visible') | .should('be.visible') | ||||
.should('contain', 'Archive cooking request successfully submitted.'); | .should('contain', 'Archive cooking request successfully submitted.'); | ||||
}); | }); | ||||
it('should offer to recook an archive if no more available to download', function() { | it('should offer to recook an archive if no more available to download', function() { | ||||
updateVaultItemList(this.Urls.browse_vault(), vaultItems); | updateVaultItemList(this.Urls.browse_vault(), this.vaultItems); | ||||
// Send 404 when fetching vault item | // Send 404 when fetching vault item | ||||
cy.intercept({url: this.vaultFetchRevisionUrl}, { | cy.intercept({url: this.vaultFetchRevisionUrl}, { | ||||
statusCode: 404, | statusCode: 404, | ||||
body: { | body: { | ||||
'exception': 'NotFoundExc', | 'exception': 'NotFoundExc', | ||||
'reason': `Revision with ID '${this.revision}' not found.` | 'reason': `Revision with ID '${this.revision}' not found.` | ||||
}, | }, | ||||
Show All 23 Lines | cy.wait('@fetchCookedArchive').then(() => { | ||||
.then(() => { | .then(() => { | ||||
testStatus(this.revision, progressbarColors['new'], 'new', 'new'); | testStatus(this.revision, progressbarColors['new'], 'new', 'new'); | ||||
}); | }); | ||||
}); | }); | ||||
}); | }); | ||||
it('should remove selected vault items', function() { | it('should remove selected vault items', function() { | ||||
updateVaultItemList(this.Urls.browse_vault(), vaultItems); | updateVaultItemList(this.Urls.browse_vault(), this.vaultItems); | ||||
cy.get(`#vault-task-${this.revision}`) | cy.get(`#vault-task-${this.revision}`) | ||||
.find('input[type="checkbox"]') | .find('input[type="checkbox"]') | ||||
.click({force: true}); | .click({force: true}); | ||||
cy.contains('button', 'Remove selected tasks') | cy.contains('button', 'Remove selected tasks') | ||||
.click(); | .click(); | ||||
cy.get(`#vault-task-${this.revision}`) | cy.get(`#vault-task-${this.revision}`) | ||||
▲ Show 20 Lines • Show All 87 Lines • Show Last 20 Lines |