Changeset View
Changeset View
Standalone View
Standalone View
cypress/integration/origin-save.spec.js
Show All 13 Lines | const saveCodeMsg = { | ||||
'warning': 'The "save code now" request has been put in pending state and may be accepted for processing after manual review.', | 'warning': 'The "save code now" request has been put in pending state and may be accepted for processing after manual review.', | ||||
'rejected': 'The "save code now" request has been rejected because the provided origin url is blacklisted.', | 'rejected': 'The "save code now" request has been rejected because the provided origin url is blacklisted.', | ||||
'rateLimit': 'The rate limit for "save code now" requests has been reached. Please try again later.', | 'rateLimit': 'The rate limit for "save code now" requests has been reached. Please try again later.', | ||||
'not-found': 'The provided url does not exist', | 'not-found': 'The provided url does not exist', | ||||
'unknownError': 'An unexpected error happened when submitting the "save code now request', | 'unknownError': 'An unexpected error happened when submitting the "save code now request', | ||||
'csrfError': 'CSRF Failed: Referrer checking failed - no Referrer.' | 'csrfError': 'CSRF Failed: Referrer checking failed - no Referrer.' | ||||
}; | }; | ||||
const anonymousVisitTypes = ['git', 'hg', 'svn']; | |||||
const allVisitTypes = ['bundle', 'git', 'hg', 'svn']; | |||||
function makeOriginSaveRequest(originType, originUrl) { | function makeOriginSaveRequest(originType, originUrl) { | ||||
cy.get('#swh-input-origin-url') | cy.get('#swh-input-origin-url') | ||||
.type(originUrl) | .type(originUrl) | ||||
.get('#swh-input-visit-type') | .get('#swh-input-visit-type') | ||||
.select(originType) | .select(originType) | ||||
.get('#swh-save-origin-form') | .get('#swh-save-origin-form') | ||||
.submit(); | .submit(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 437 Lines • ▼ Show 20 Lines | it('should show only user requests when filter is activated', function() { | ||||
cy.get('#swh-save-requests-user-filter') | cy.get('#swh-save-requests-user-filter') | ||||
.click({force: true}); | .click({force: true}); | ||||
cy.get('tbody tr').then(rows => { | cy.get('tbody tr').then(rows => { | ||||
expect(rows.length).to.eq(2); | expect(rows.length).to.eq(2); | ||||
}); | }); | ||||
}); | }); | ||||
it('should list unprivileged visit types when not connected', function() { | |||||
cy.visit(url); | |||||
cy.get('#swh-input-visit-type').children('option').then(options => { | |||||
const actual = [...options].map(o => o.value); | |||||
expect(actual).to.deep.eq(anonymousVisitTypes); | |||||
}); | |||||
}); | |||||
it('should list unprivileged visit types when connected as unprivileged user', function() { | |||||
cy.userLogin(); | |||||
cy.visit(url); | |||||
cy.get('#swh-input-visit-type').children('option').then(options => { | |||||
const actual = [...options].map(o => o.value); | |||||
expect(actual).to.deep.eq(anonymousVisitTypes); | |||||
}); | |||||
}); | |||||
it('should list privileged visit types when connected as ambassador', function() { | |||||
cy.ambassadorLogin(); | |||||
cy.visit(url); | |||||
cy.get('#swh-input-visit-type').children('option').then(options => { | |||||
const actual = [...options].map(o => o.value); | |||||
expect(actual).to.deep.eq(allVisitTypes); | |||||
}); | |||||
}); | |||||
it('should display extra inputs when dealing with bundle visit type', function() { | |||||
cy.ambassadorLogin(); | |||||
cy.visit(url); | |||||
for (let visitType of anonymousVisitTypes) { | |||||
cy.get('#swh-input-visit-type').select(visitType); | |||||
cy.get('#optional-origin-forms').should('not.be.visible'); | |||||
} | |||||
// bundle should display more inputs with the bundle type | |||||
cy.get('#swh-input-visit-type').select('bundle'); | |||||
cy.get('#optional-origin-forms').should('be.visible'); | |||||
}); | |||||
it('should be allowed to submit bundle save request when connected as ambassador', function() { | |||||
let originUrl = 'https://ftp.gnu.org/pub/pub/gnu/3dldf'; | |||||
let artifactUrl = 'https://ftp.gnu.org/pub/pub/gnu/3dldf/3DLDF-1.1.4.tar.gz'; | |||||
let artifactFilename = '3DLDF-1.1.4.tar.gz'; | |||||
let artifactVersion = '1.1.4'; | |||||
stubSaveRequest({ | |||||
requestUrl: this.Urls.api_1_save_origin('bundle', originUrl), | |||||
saveRequestStatus: 'accepted', | |||||
originUrl: originUrl, | |||||
saveTaskStatus: 'not yet scheduled' | |||||
}); | |||||
cy.ambassadorLogin(); | |||||
cy.visit(url); | |||||
// input new bundle information and submit | |||||
cy.get('#swh-input-origin-url') | |||||
.type(originUrl) | |||||
.get('#swh-input-visit-type') | |||||
.select('bundle') | |||||
.get('#swh-input-artifact-url') | |||||
.type(artifactUrl) | |||||
.get('#swh-input-artifact-filename') | |||||
.type(artifactFilename) | |||||
.get('#swh-input-artifact-version') | |||||
.type(artifactVersion) | |||||
.get('#swh-save-origin-form') | |||||
.submit(); | |||||
cy.wait('@saveRequest').then(() => { | |||||
checkAlertVisible('success', saveCodeMsg['success']); | |||||
}); | |||||
}); | |||||
}); | }); |