Changeset View
Changeset View
Standalone View
Standalone View
cypress/integration/vault.spec.js
Show All 24 Lines | function getVaultItemList() { | ||||
return JSON.parse(window.localStorage.getItem('swh-vault-cooking-tasks')); | return JSON.parse(window.localStorage.getItem('swh-vault-cooking-tasks')); | ||||
} | } | ||||
function updateVaultItemList(vaultItems) { | function updateVaultItemList(vaultItems) { | ||||
window.localStorage.setItem('swh-vault-cooking-tasks', JSON.stringify(vaultItems)); | window.localStorage.setItem('swh-vault-cooking-tasks', JSON.stringify(vaultItems)); | ||||
} | } | ||||
// Mocks API response : /api/1/vault/(:bundleType)/(:swhid) | // Mocks API response : /api/1/vault/(:bundleType)/(:swhid) | ||||
// bundleType : {'flat', 'gitfast'} | // bundleType : {'flat', 'git_bare'} | ||||
function genVaultCookingResponse(bundleType, swhid, status, message, fetchUrl) { | function genVaultCookingResponse(bundleType, swhid, status, message, fetchUrl) { | ||||
return { | return { | ||||
'bundle_type': bundleType, | 'bundle_type': bundleType, | ||||
'id': 1, | 'id': 1, | ||||
'progress_message': message, | 'progress_message': message, | ||||
'status': status, | 'status': status, | ||||
'swhid': swhid, | 'swhid': swhid, | ||||
'fetch_url': fetchUrl | 'fetch_url': fetchUrl | ||||
Show All 27 Lines | before(function() { | ||||
this.directoryUrl = this.Urls.browse_origin_directory() + | this.directoryUrl = this.Urls.browse_origin_directory() + | ||||
`?origin_url=${this.origin[0].url}&path=${dirInfo.path}`; | `?origin_url=${this.origin[0].url}&path=${dirInfo.path}`; | ||||
this.vaultDirectoryUrl = this.Urls.api_1_vault_cook_flat(this.directory); | this.vaultDirectoryUrl = this.Urls.api_1_vault_cook_flat(this.directory); | ||||
this.vaultFetchDirectoryUrl = this.Urls.api_1_vault_fetch_flat(this.directory); | this.vaultFetchDirectoryUrl = this.Urls.api_1_vault_fetch_flat(this.directory); | ||||
this.revisionId = this.origin[1].revisions[0]; | this.revisionId = this.origin[1].revisions[0]; | ||||
this.revision = `swh:1:rev:${this.revisionId}`; | this.revision = `swh:1:rev:${this.revisionId}`; | ||||
this.revisionUrl = this.Urls.browse_revision(this.revisionId); | this.revisionUrl = this.Urls.browse_revision(this.revisionId); | ||||
this.vaultRevisionUrl = this.Urls.api_1_vault_cook_gitfast(this.revision); | this.vaultRevisionUrl = this.Urls.api_1_vault_cook_git_bare(this.revision); | ||||
this.vaultFetchRevisionUrl = this.Urls.api_1_vault_fetch_gitfast(this.revision); | this.vaultFetchRevisionUrl = this.Urls.api_1_vault_fetch_git_bare(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_flat(`swh:1:dir:${release.directory}`); | this.vaultReleaseDirectoryUrl = this.Urls.api_1_vault_cook_flat(`swh:1:dir:${release.directory}`); | ||||
}); | }); | ||||
beforeEach(function() { | beforeEach(function() { | ||||
// For some reason, this gets reset if we define it in the before() hook, | // For some reason, this gets reset if we define it in the before() hook, | ||||
// so we need to define it here | // so we need to define it here | ||||
this.vaultItems = [ | this.vaultItems = [ | ||||
{ | { | ||||
'bundle_type': 'gitfast', | 'bundle_type': 'git_bare', | ||||
'swhid': this.revision, | 'swhid': this.revision, | ||||
'email': '', | 'email': '', | ||||
'status': 'done', | 'status': 'done', | ||||
'fetch_url': `/api/1/vault/gitfast/${this.revision}/raw/`, | 'fetch_url': `/api/1/vault/git-bare/${this.revision}/raw/`, | ||||
'progress_message': null | 'progress_message': null | ||||
} | } | ||||
]; | ]; | ||||
this.legacyVaultItems = [ | this.legacyVaultItems = [ | ||||
{ | { | ||||
'object_type': 'revision', | 'object_type': 'revision', | ||||
'object_id': this.revisionId, | 'object_id': this.revisionId, | ||||
'email': '', | 'email': '', | ||||
'status': 'done', | 'status': 'done', | ||||
'fetch_url': `/api/1/vault/revision/${this.revisionId}/gitfast/raw/`, | 'fetch_url': `/api/1/vault/revision/${this.revisionId}/gitfast/raw/`, | ||||
'progress_message': null | 'progress_message': null | ||||
} | } | ||||
]; | ]; | ||||
this.genVaultDirCookingResponse = (status, message = null) => { | this.genVaultDirCookingResponse = (status, message = null) => { | ||||
return genVaultCookingResponse('flat', this.directory, status, | return genVaultCookingResponse('flat', this.directory, status, | ||||
message, this.vaultFetchDirectoryUrl); | message, this.vaultFetchDirectoryUrl); | ||||
}; | }; | ||||
this.genVaultRevCookingResponse = (status, message = null) => { | this.genVaultRevCookingResponse = (status, message = null) => { | ||||
return genVaultCookingResponse('gitfast', this.revision, status, | return genVaultCookingResponse('git_bare', this.revision, status, | ||||
message, this.vaultFetchRevisionUrl); | message, this.vaultFetchRevisionUrl); | ||||
}; | }; | ||||
}); | }); | ||||
it('should report an error when vault service is experiencing issues', function() { | it('should report an error when vault service is experiencing issues', function() { | ||||
// Browse a directory | // Browse a directory | ||||
cy.visit(this.directoryUrl); | cy.visit(this.directoryUrl); | ||||
▲ Show 20 Lines • Show All 156 Lines • ▼ Show 20 Lines | describe('Vault Cooking User Interface Tests', function() { | ||||
it('should create a revision cooking task and report its status', function() { | it('should create a revision cooking task and report its status', function() { | ||||
cy.adminLogin(); | cy.adminLogin(); | ||||
// Browse a revision | // Browse a revision | ||||
cy.visit(this.revisionUrl); | cy.visit(this.revisionUrl); | ||||
// Stub response to the vault API indicating to simulate archive download | // Stub response to the vault API indicating to simulate archive download | ||||
cy.intercept({url: this.vaultFetchRevisionUrl}, { | cy.intercept({url: this.vaultFetchRevisionUrl}, { | ||||
fixture: `${this.revision}.gitfast.gz`, | fixture: `${this.revision}.git.tar`, | ||||
headers: { | headers: { | ||||
'Content-disposition': `attachment; filename=${this.revision}.gitfast.gz`, | 'Content-disposition': `attachment; filename=${this.revision}.git.tar`, | ||||
'Content-Type': 'application/gzip' | 'Content-Type': 'application/gzip' | ||||
} | } | ||||
}).as('fetchCookedArchive'); | }).as('fetchCookedArchive'); | ||||
// Stub responses when checking vault task status | // Stub responses when checking vault task status | ||||
const checkVaultResponses = [ | const checkVaultResponses = [ | ||||
{'exception': 'NotFoundExc'}, | {'exception': 'NotFoundExc'}, | ||||
this.genVaultRevCookingResponse('new'), | this.genVaultRevCookingResponse('new'), | ||||
▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | it('should offer to immediately download a directory tarball if already cooked', function() { | ||||
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 bare revision git archive if already cooked', function() { | ||||
cy.adminLogin(); | cy.adminLogin(); | ||||
// Browse a directory | // Browse a directory | ||||
cy.visit(this.revisionUrl); | cy.visit(this.revisionUrl); | ||||
// Stub response to the vault API to simulate archive download | // Stub response to the vault API to simulate archive download | ||||
cy.intercept({url: this.vaultFetchRevisionUrl}, { | cy.intercept({url: this.vaultFetchRevisionUrl}, { | ||||
fixture: `${this.revision}.gitfast.gz`, | fixture: `${this.revision}.git.tar`, | ||||
headers: { | headers: { | ||||
'Content-disposition': `attachment; filename=${this.revision}.gitfast.gz`, | 'Content-disposition': `attachment; filename=${this.revision}.git.tar`, | ||||
'Content-Type': 'application/gzip' | 'Content-Type': 'application/gzip' | ||||
} | } | ||||
}).as('fetchCookedArchive'); | }).as('fetchCookedArchive'); | ||||
// 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.intercept(this.vaultRevisionUrl, { | cy.intercept(this.vaultRevisionUrl, { | ||||
body: this.genVaultRevCookingResponse('done') | body: this.genVaultRevCookingResponse('done') | ||||
Show All 33 Lines |