Changeset View
Changeset View
Standalone View
Standalone View
cypress/e2e/add-forge-now-request-dashboard.cy.js
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | function genEmailSrc() { | ||||
return `Message-ID: <d5c43e75-2a11-250a-43e3-37034ae3904b@example.com> | return `Message-ID: <d5c43e75-2a11-250a-43e3-37034ae3904b@example.com> | ||||
Date: Tue, 19 Apr 2022 14:00:56 +0200 | Date: Tue, 19 Apr 2022 14:00:56 +0200 | ||||
MIME-Version: 1.0 | MIME-Version: 1.0 | ||||
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 | User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 | ||||
Thunderbird/91.8.0 | Thunderbird/91.8.0 | ||||
To: ${requestData.forge_contact_email} | To: ${requestData.forge_contact_email} | ||||
Cc: ${requestInboundEmailAddress} | Cc: ${requestInboundEmailAddress} | ||||
Reply-To: ${requestInboundEmailAddress} | Reply-To: ${requestInboundEmailAddress} | ||||
Subject: Software Heritage archival request for test.example.com | Subject: Software Heritage archival notification for test.example.com | ||||
Content-Language: en-US | Content-Language: en-US | ||||
From: Test Admin <admin@example.com> | From: Test Admin <admin@example.com> | ||||
Content-Type: text/plain; charset=UTF-8; format=flowed | Content-Type: text/plain; charset=UTF-8; format=flowed | ||||
Content-Transfer-Encoding: 7bit | Content-Transfer-Encoding: 7bit | ||||
Dear forge administrator, | Dear forge administrator, | ||||
The mission of Software Heritage is to collect, preserve and share all the | The mission of Software Heritage is to collect, preserve and share all the | ||||
publicly available source code (see https://www.softwareheritage.org for more | publicly available source code (see https://www.softwareheritage.org for more | ||||
information). | information). | ||||
We just received a request to add the forge hosted at https://test.example.com to the | We just received a request to add the forge hosted at https://test.example.com to the | ||||
list of software origins that are archived, and it is our understanding that you | list of software origins that are archived, and it is our understanding that you | ||||
are the contact person for this forge. | are the contact person for this forge. | ||||
In order to archive the forge contents, we will have to periodically pull the | In order to archive the forge contents, we will have to periodically pull the | ||||
public repositories it contains and clone them into the | public repositories it contains and clone them into the | ||||
Software Heritage archive. | Software Heritage archive. | ||||
Would you be so kind as to reply to this message to acknowledge the reception | Please let us know if there are any technical issues to consider before we | ||||
of this email and let us know if there are any special steps we should take in | launch the archival of the public repositories hosted on your infrastructure. | ||||
order to properly archive the public repositories hosted on your infrastructure? | (use "Reply all" to ensure our system will process your answer properly) | ||||
In the absence of an answer to this message, we will start to archive your | |||||
forge in the coming weeks (only the publicly accessible repositories will be | |||||
archived) | |||||
Thank you in advance for your help. | Thank you in advance for your help. | ||||
Kind regards, | Kind regards, | ||||
The Software Heritage team | The Software Heritage team | ||||
`; | `; | ||||
} | } | ||||
describe('Test add forge now request dashboard load', function() { | describe('Test add forge now request dashboard load', function () { | ||||
before(function() { | before(function () { | ||||
// Create an add-forge-request object in the DB | // Create an add-forge-request object in the DB | ||||
createDummyRequest(this.Urls); | createDummyRequest(this.Urls); | ||||
}); | }); | ||||
beforeEach(function() { | beforeEach(function () { | ||||
const url = this.Urls.add_forge_now_request_dashboard(requestId); | const url = this.Urls.add_forge_now_request_dashboard(requestId); | ||||
// request dashboard require admin permissions to view | // request dashboard require admin permissions to view | ||||
cy.adminLogin(); | cy.adminLogin(); | ||||
cy.intercept(`${this.Urls.api_1_add_forge_request_get(requestId)}**`).as('forgeRequestGet'); | cy.intercept(`${this.Urls.api_1_add_forge_request_get(requestId)}**`).as('forgeRequestGet'); | ||||
cy.visit(url); | cy.visit(url); | ||||
cy.get('.swh-add-forge-now-moderation-item') | cy.get('.swh-add-forge-now-moderation-item') | ||||
.should('have.class', 'active'); | .should('have.class', 'active'); | ||||
}); | }); | ||||
it('should load add forge request details', function() { | it('should load add forge request details', function () { | ||||
cy.wait('@forgeRequestGet'); | cy.wait('@forgeRequestGet'); | ||||
cy.get('#requestStatus') | cy.get('#requestStatus') | ||||
.should('contain', 'Pending'); | .should('contain', 'Pending'); | ||||
cy.get('#requestType') | cy.get('#requestType') | ||||
.should('contain', 'bitbucket'); | .should('contain', 'bitbucket'); | ||||
cy.get('#requestURL') | cy.get('#requestURL') | ||||
Show All 10 Lines | it('should load add forge request details', function () { | ||||
cy.get('#requestContactConsent') | cy.get('#requestContactConsent') | ||||
.should('contain', 'true'); | .should('contain', 'true'); | ||||
cy.get('#submitterMessage') | cy.get('#submitterMessage') | ||||
.should('contain', 'test comment'); | .should('contain', 'test comment'); | ||||
}); | }); | ||||
it('should show send message link', function() { | it('should show send message link', function () { | ||||
cy.wait('@forgeRequestGet'); | cy.wait('@forgeRequestGet'); | ||||
cy.get('#contactForgeAdmin') | cy.get('#contactForgeAdmin') | ||||
.should('have.attr', 'emailto') | .should('have.attr', 'emailto') | ||||
.and('include', 'test@example.com'); | .and('include', 'test@example.com'); | ||||
cy.get('#contactForgeAdmin') | cy.get('#contactForgeAdmin') | ||||
.should('have.attr', 'emailsubject') | .should('have.attr', 'emailsubject') | ||||
.and('include', `Software Heritage archival request for ${requestForgeDomain}`); | .and('include', `Software Heritage archival request for ${requestForgeDomain}`); | ||||
anlambert: s/request/notification/ to fix cypress test | |||||
}); | }); | ||||
it('should not show any error message', function() { | it('should not show any error message', function () { | ||||
cy.wait('@forgeRequestGet'); | cy.wait('@forgeRequestGet'); | ||||
cy.get('#fetchError') | cy.get('#fetchError') | ||||
.should('have.class', 'd-none'); | .should('have.class', 'd-none'); | ||||
cy.get('#requestDetails') | cy.get('#requestDetails') | ||||
.should('not.have.class', 'd-none'); | .should('not.have.class', 'd-none'); | ||||
}); | }); | ||||
it('should show error message for an api error', function() { | it('should show error message for an api error', function () { | ||||
// requesting with a non existing request ID | // requesting with a non existing request ID | ||||
const invalidRequestId = requestId + 10; | const invalidRequestId = requestId + 10; | ||||
const url = this.Urls.add_forge_now_request_dashboard(invalidRequestId); | const url = this.Urls.add_forge_now_request_dashboard(invalidRequestId); | ||||
cy.intercept(`${this.Urls.api_1_add_forge_request_get(invalidRequestId)}**`, | cy.intercept(`${this.Urls.api_1_add_forge_request_get(invalidRequestId)}**`, | ||||
{statusCode: 400}).as('forgeAddInvalidRequest'); | { statusCode: 400 }).as('forgeAddInvalidRequest'); | ||||
cy.visit(url); | cy.visit(url); | ||||
cy.wait('@forgeAddInvalidRequest'); | cy.wait('@forgeAddInvalidRequest'); | ||||
cy.get('#fetchError') | cy.get('#fetchError') | ||||
.should('not.have.class', 'd-none'); | .should('not.have.class', 'd-none'); | ||||
cy.get('#requestDetails') | cy.get('#requestDetails') | ||||
.should('have.class', 'd-none'); | .should('have.class', 'd-none'); | ||||
}); | }); | ||||
it('should load add forge request history', function() { | it('should load add forge request history', function () { | ||||
cy.wait('@forgeRequestGet'); | cy.wait('@forgeRequestGet'); | ||||
cy.get('#requestHistory') | cy.get('#requestHistory') | ||||
.children() | .children() | ||||
.should('have.length', 1); | .should('have.length', 1); | ||||
cy.get('#requestHistory') | cy.get('#requestHistory') | ||||
.children() | .children() | ||||
.should('contain', 'New status: Pending'); | .should('contain', 'New status: Pending'); | ||||
cy.get('#requestHistory') | cy.get('#requestHistory') | ||||
.should('contain', 'From user (SUBMITTER)'); | .should('contain', 'From user (SUBMITTER)'); | ||||
}); | }); | ||||
it('should load possible next status', function() { | it('should load possible next status', function () { | ||||
cy.wait('@forgeRequestGet'); | cy.wait('@forgeRequestGet'); | ||||
// 3 possible next status and the comment option | // 3 possible next status and the comment option | ||||
cy.get('#decisionOptions') | cy.get('#decisionOptions') | ||||
.children() | .children() | ||||
.should('have.length', 4); | .should('have.length', 4); | ||||
}); | }); | ||||
}); | }); | ||||
function populateAndSubmitForm() { | function populateAndSubmitForm() { | ||||
cy.get('#decisionOptions').select('WAITING_FOR_FEEDBACK'); | cy.get('#decisionOptions').select('WAITING_FOR_FEEDBACK'); | ||||
cy.get('#updateComment').type('This is an update comment'); | cy.get('#updateComment').type('This is an update comment'); | ||||
cy.get('#updateRequestForm').submit(); | cy.get('#updateRequestForm').submit(); | ||||
} | } | ||||
describe('Test add forge now request update', function() { | describe('Test add forge now request update', function () { | ||||
beforeEach(function() { | beforeEach(function () { | ||||
createDummyRequest(this.Urls).then(() => { | createDummyRequest(this.Urls).then(() => { | ||||
this.url = this.Urls.add_forge_now_request_dashboard(requestId); | this.url = this.Urls.add_forge_now_request_dashboard(requestId); | ||||
cy.adminLogin(); | cy.adminLogin(); | ||||
// intercept GET API on page load | // intercept GET API on page load | ||||
cy.intercept(`${this.Urls.api_1_add_forge_request_get(requestId)}**`).as('forgeRequestGet'); | cy.intercept(`${this.Urls.api_1_add_forge_request_get(requestId)}**`).as('forgeRequestGet'); | ||||
// intercept update POST API | // intercept update POST API | ||||
cy.intercept('POST', `${this.Urls.api_1_add_forge_request_update(requestId)}**`).as('forgeRequestUpdate'); | cy.intercept('POST', `${this.Urls.api_1_add_forge_request_update(requestId)}**`).as('forgeRequestUpdate'); | ||||
cy.visit(this.url).then(() => { | cy.visit(this.url).then(() => { | ||||
cy.wait('@forgeRequestGet'); | cy.wait('@forgeRequestGet'); | ||||
}); | }); | ||||
}); | }); | ||||
}); | }); | ||||
it('should submit correct details', function() { | it('should submit correct details', function () { | ||||
populateAndSubmitForm(); | populateAndSubmitForm(); | ||||
// Making sure posting the right data | // Making sure posting the right data | ||||
cy.wait('@forgeRequestUpdate').its('request.body') | cy.wait('@forgeRequestUpdate').its('request.body') | ||||
.should('include', 'new_status') | .should('include', 'new_status') | ||||
.should('include', 'text') | .should('include', 'text') | ||||
.should('include', 'WAITING_FOR_FEEDBACK'); | .should('include', 'WAITING_FOR_FEEDBACK'); | ||||
}); | }); | ||||
it('should show success message', function() { | it('should show success message', function () { | ||||
populateAndSubmitForm(); | populateAndSubmitForm(); | ||||
// Making sure showing the success message | // Making sure showing the success message | ||||
cy.wait('@forgeRequestUpdate'); | cy.wait('@forgeRequestUpdate'); | ||||
cy.get('#userMessage') | cy.get('#userMessage') | ||||
.should('contain', 'The request status has been updated') | .should('contain', 'The request status has been updated') | ||||
.should('not.have.class', 'badge-danger') | .should('not.have.class', 'badge-danger') | ||||
.should('have.class', 'badge-success'); | .should('have.class', 'badge-success'); | ||||
}); | }); | ||||
it('should update the dashboard after submit', function() { | it('should update the dashboard after submit', function () { | ||||
populateAndSubmitForm(); | populateAndSubmitForm(); | ||||
// Making sure the UI is updated after the submit | // Making sure the UI is updated after the submit | ||||
cy.wait('@forgeRequestGet'); | cy.wait('@forgeRequestGet'); | ||||
cy.get('#requestStatus') | cy.get('#requestStatus') | ||||
.should('contain', 'Waiting for feedback'); | .should('contain', 'Waiting for feedback'); | ||||
cy.get('#requestHistory') | cy.get('#requestHistory') | ||||
Show All 12 Lines | cy.get('#requestHistory') | ||||
.children() | .children() | ||||
.should('contain', 'Status changed to: Waiting for feedback'); | .should('contain', 'Status changed to: Waiting for feedback'); | ||||
cy.get('#decisionOptions') | cy.get('#decisionOptions') | ||||
.children() | .children() | ||||
.should('have.length', 2); | .should('have.length', 2); | ||||
}); | }); | ||||
it('should update the dashboard after receiving email', function() { | it('should update the dashboard after receiving email', function () { | ||||
const emailSrc = genEmailSrc(); | const emailSrc = genEmailSrc(); | ||||
cy.task('processAddForgeNowInboundEmail', emailSrc); | cy.task('processAddForgeNowInboundEmail', emailSrc); | ||||
// Refresh page and wait for the async request to complete | // Refresh page and wait for the async request to complete | ||||
cy.visit(this.url); | cy.visit(this.url); | ||||
cy.wait('@forgeRequestGet'); | cy.wait('@forgeRequestGet'); | ||||
cy.get('#requestHistory') | cy.get('#requestHistory') | ||||
.children() | .children() | ||||
.should('have.length', 2); | .should('have.length', 2); | ||||
cy.get('#historyItem1') | cy.get('#historyItem1') | ||||
.click() | .click() | ||||
.should('contain', 'New status: Waiting for feedback'); | .should('contain', 'New status: Waiting for feedback'); | ||||
cy.get('#historyItemBody1') | cy.get('#historyItemBody1') | ||||
.find('a') | .find('a') | ||||
.should('contain', 'Open original message in email client') | .should('contain', 'Open original message in email client') | ||||
.should('have.prop', 'href').and('contain', '/message-source/').then(function(href) { | .should('have.prop', 'href').and('contain', '/message-source/').then(function (href) { | ||||
cy.request(href).then((response) => { | cy.request(href).then((response) => { | ||||
expect(response.headers['content-type']) | expect(response.headers['content-type']) | ||||
.to.equal('text/email'); | .to.equal('text/email'); | ||||
expect(response.headers['content-disposition']) | expect(response.headers['content-disposition']) | ||||
.to.match(/filename="add-forge-now-test.example.com-message\d+.eml"/); | .to.match(/filename="add-forge-now-test.example.com-message\d+.eml"/); | ||||
expect(response.body) | expect(response.body) | ||||
.to.equal(emailSrc); | .to.equal(emailSrc); | ||||
}); | }); | ||||
}); | }); | ||||
}); | }); | ||||
it('should show an error on API failure', function() { | it('should show an error on API failure', function () { | ||||
cy.intercept('POST', | cy.intercept('POST', | ||||
`${this.Urls.api_1_add_forge_request_update(requestId)}**`, | `${this.Urls.api_1_add_forge_request_update(requestId)}**`, | ||||
{forceNetworkError: true}) | { forceNetworkError: true }) | ||||
.as('updateFailedRequest'); | .as('updateFailedRequest'); | ||||
cy.get('#updateComment').type('This is an update comment'); | cy.get('#updateComment').type('This is an update comment'); | ||||
cy.get('#updateRequestForm').submit(); | cy.get('#updateRequestForm').submit(); | ||||
cy.wait('@updateFailedRequest'); | cy.wait('@updateFailedRequest'); | ||||
cy.get('#userMessage') | cy.get('#userMessage') | ||||
.should('contain', 'Sorry; Updating the request failed') | .should('contain', 'Sorry; Updating the request failed') | ||||
.should('have.class', 'badge-danger') | .should('have.class', 'badge-danger') | ||||
.should('not.have.class', 'badge-success'); | .should('not.have.class', 'badge-success'); | ||||
}); | }); | ||||
}); | }); |
s/request/notification/ to fix cypress test