diff --git a/assets/src/bundles/save/index.js b/assets/src/bundles/save/index.js --- a/assets/src/bundles/save/index.js +++ b/assets/src/bundles/save/index.js @@ -5,7 +5,7 @@ * See top-level LICENSE file for more information */ -import {handleFetchError, isGitRepoUrl, htmlAlert, removeUrlFragment} from 'utils/functions'; +import {csrfPost, handleFetchError, isGitRepoUrl, htmlAlert, removeUrlFragment} from 'utils/functions'; import {swhSpinnerSrc} from 'utils/constants'; let saveRequestsTable; @@ -14,7 +14,7 @@ acceptedCallback, pendingCallback, errorCallback) { let addSaveOriginRequestUrl = Urls.api_1_save_origin(originType, originUrl); $('.swh-processing-save-request').css('display', 'block'); - fetch(addSaveOriginRequestUrl, {method: 'POST'}) + csrfPost(addSaveOriginRequestUrl) .then(handleFetchError) .then(response => response.json()) .then(data => { diff --git a/cypress/integration/origin-save.spec.js b/cypress/integration/origin-save.spec.js --- a/cypress/integration/origin-save.spec.js +++ b/cypress/integration/origin-save.spec.js @@ -399,4 +399,20 @@ }); }); + it('should create save request for authenticated user', function() { + cy.adminLogin(); + cy.visit(url); + const originUrl = 'https://git.example.org/account/repo'; + stubSaveRequest({requestUrl: this.Urls.api_1_save_origin('git', originUrl), + saveRequestStatus: 'accepted', + originUrl: origin.url, + saveTaskStatus: 'not yet scheduled'}); + + makeOriginSaveRequest('git', originUrl); + + cy.wait('@saveRequest').then(() => { + checkAlertVisible('success', saveCodeMsg['success']); + }); + }); + });