Page MenuHomeSoftware Heritage

Add missing cypress tests to 'add-forge-now' request dashboard
ClosedPublic

Authored by jayeshv on Mar 29 2022, 12:04 PM.

Details

Summary

Add tests for status update and API failure
Add tests for mailto email contact

Diff Detail

Repository
rDWAPPS Web applications
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Build has FAILED

Patch application report for D7451 (id=26977)

Rebasing onto 4bc8aaf1d9...

Current branch diff-target is up to date.
Changes applied before test
commit 48d8c0f3559fae428dd2d67b77102c2ae9a30f4d
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Tue Mar 29 12:00:00 2022 +0200

    Add missing cypress tests to 'add-fore-now' request dashboard
    
    Add tests for status update and API failiure
    Add tests for mailto email contact

Link to build: https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/1616/
See console output for more information: https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/1616/console

Harbormaster returned this revision to the author for changes because remote builds failed.Mar 29 2022, 12:23 PM
Harbormaster failed remote builds in B27893: Diff 26977!

Fixed issue related to timezone

Build is green

Patch application report for D7451 (id=26978)

Rebasing onto 4bc8aaf1d9...

Current branch diff-target is up to date.
Changes applied before test
commit 5e38178834e6a063326f4954d2541c56d9dda0ef
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Tue Mar 29 12:26:53 2022 +0200

    Add missing cypress tests for 'add-fore-now' request dashboard
    
    Add tests for status update and API failiure
    Add tests for mailto email contact

See https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/1618/ for more details.

note there is a typo in the commit message (add-fore-now)

Fixed the typo in the commit message

Build is green

Patch application report for D7451 (id=26985)

Rebasing onto f7281122f2...

First, rewinding head to replay your work on top of it...
Applying: Add missing cypress tests for 'add-forge-now' request dashboard
Changes applied before test
commit 4c4688ecc6a83ed0d911982f1f30a3da62773fdb
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Tue Mar 29 14:23:50 2022 +0200

    Add missing cypress tests for 'add-forge-now' request dashboard
    
    Add tests for status update and API failiure
    Add tests for mailto email contact

See https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/1622/ for more details.

anlambert added subscribers: ardumont, anlambert.
anlambert added inline comments.
cypress/integration/add-forge-now-request-dashboard.spec.js
147–150

Instead of using a cypress fixture, you should rather drop the add forge now database tables using the cypress task db:add_forge_now:delete added by @ardumont. It has the advantage to avoid mocking the HTTP request responses.

So you can replace these two lines by:

cy.intercept(`${this.Urls.api_1_add_forge_request_get(requestId)}**`
  .as('forgeAddRequest');
cy.intercept('POST', `${this.Urls.api_1_add_forge_request_update(requestId)}**`,
  .as('updateRequest');
cy.task('db:add_forge_now:delete');

I think you will also have to drop the add_forge_now_request_history in the db:add_forge_now:delete task implementation.

This revision now requires changes to proceed.Mar 29 2022, 2:49 PM

note there is a typo in the commit message (add-fore-now)

and "failiure"

cypress/integration/add-forge-now-request-dashboard.spec.js
147–150

So I managed to avoid using fixtures the following way using cy.request to create a new add forge request through a call to the Web API:

diff --git a/cypress/integration/add-forge-now-request-dashboard.spec.js b/cypress/integration/add-forge-now-request-dashboard.spec.js
index 282291c1..07db0a6c 100644
--- a/cypress/integration/add-forge-now-request-dashboard.spec.js
+++ b/cypress/integration/add-forge-now-request-dashboard.spec.js
@@ -101,16 +101,44 @@ describe('Test forge now request update', function() {
 
   beforeEach(function() {
     const url = this.Urls.add_forge_now_request_dashboard(requestId);
-    cy.adminLogin();
+    cy.intercept(`${this.Urls.api_1_add_forge_request_get(requestId)}**`)
+    .as('forgeAddRequest');
+    cy.intercept('POST', `${this.Urls.api_1_add_forge_request_update(requestId)}**`)
+    .as('updateRequest');
+    cy.task('db:add_forge_now:delete');
+
+    cy.userLogin();
+    cy.visit(url);
 
-    cy.intercept(`${this.Urls.api_1_add_forge_request_get(requestId)}**`,
-                 {fixture: 'add-forge-now-request'}).as('forgeAddRequest');
-    cy.intercept('POST', `${this.Urls.api_1_add_forge_request_update(requestId)}**`,
-                 {fixture: 'add-forge-now-request'}).as('updateRequest');
+    cy.getCookie('csrftoken').its('value').then((token) => {
+      cy.request({
+        method: 'POST',
+        url: this.Urls.api_1_add_forge_request_create(),
+        body: {
+          forge_type: 'bitbucket',
+          forge_url: 'test.com',
+          forge_contact_email: 'test@example.com',
+          forge_contact_name: 'test user',
+          submitter_forward_username: true,
+          forge_contact_comment: 'test comment'
+        },
+        headers: {
+          'X-CSRFToken': token
+        }
+      });
+    });
+
+    cy.contains('a', 'logout').click();
+
+    cy.adminLogin();
     cy.visit(url);
+
   });
 
   it('should post data on submit', function() {
+
     cy.get('#decisionOptions').select('WAITING_FOR_FEEDBACK');
     cy.get('#updateComment').type('This is an update comment');
     cy.get('#updateRequestForm').submit();
@@ -126,6 +154,7 @@ describe('Test forge now request update', function() {
   });
 
   it('should show an error on API failiure', function() {
+
     cy.intercept('POST',
                  `${this.Urls.api_1_add_forge_request_update(requestId)}**`,
                  {forceNetworkError: true})
diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js
index eeb7373b..3f66173c 100644
--- a/cypress/plugins/index.js
+++ b/cypress/plugins/index.js
@@ -150,7 +150,10 @@ module.exports = (on, config) => {
     'db:add_forge_now:delete': () => {
       const db = getDatabase();
       db.serialize(function() {
+        db.run('DELETE FROM add_forge_now_requesthistory');
+        db.run('DELETE FROM sqlite_sequence WHERE name="add_forge_now_requesthistory"');
         db.run('DELETE FROM add_forge_now_request');
+        db.run('DELETE FROM sqlite_sequence WHERE name="add_forge_now_request"');
       });
       db.close();
       return true;

I lost some debugging time on the request id as sqlite3 does not reset id sequences by default.

Addressing review comments; removed fixture to use real API calls

Build has FAILED

Patch application report for D7451 (id=27089)

Rebasing onto 0dc0765eed...

Current branch diff-target is up to date.
Changes applied before test
commit 3add2a70b3dacf3fa49f0e56f10bf270449b9338
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Wed Mar 30 11:45:42 2022 +0200

    Add missing cypress tests for 'add-forge-now' request dashboard
    
    Remove mock fixture from load tests.
    Add tests for status update and API failure.
    Add tests for mailto email contact.

Link to build: https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/1638/
See console output for more information: https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/1638/console

jayeshv marked an inline comment as done.

Fix test failure after rebase

Add extra event check to avoid sync error

Build is green

Patch application report for D7451 (id=27093)

Rebasing onto 0dc0765eed...

Current branch diff-target is up to date.
Changes applied before test
commit 9daf78d2be2e6b94372778d95c7c5bd1b7fa60c5
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Wed Mar 30 12:07:58 2022 +0200

    Add missing cypress tests for 'add-forge-now' request dashboard
    
    Remove mock fixture from load tests.
    Add tests for status update and API failure.
    Add tests for mailto email contact.

See https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/1639/ for more details.

Build is green

Patch application report for D7451 (id=27094)

Rebasing onto 0dc0765eed...

Current branch diff-target is up to date.
Changes applied before test
commit 5ea2dcd599074ea7b67b7c0124a5ee47d68fc1c2
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Wed Mar 30 12:19:19 2022 +0200

    Add missing cypress tests for 'add-forge-now' request dashboard
    
    Remove mock fixture from load tests.
    Add tests for status update and API failure.
    Add tests for mailto email contact.

See https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/1640/ for more details.

Looks good to me, thanks !

This revision is now accepted and ready to land.Mar 30 2022, 1:51 PM
vlorentz retitled this revision from Add missing cypress tests to 'add-fore-now' request dashboard to Add missing cypress tests to 'add-forge-now' request dashboard.Mar 30 2022, 1:52 PM
This revision was landed with ongoing or failed builds.Mar 30 2022, 2:09 PM
This revision was automatically updated to reflect the committed changes.

Build is green

Patch application report for D7451 (id=27106)

Rebasing onto cc4a82eb38...

First, rewinding head to replay your work on top of it...
Applying: Add missing cypress tests for 'add-forge-now' request dashboard
Changes applied before test
commit e6b1b66d03f796f6e4b0f43771e8d9ba699f694d
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Wed Mar 30 14:03:12 2022 +0200

    Add missing cypress tests for 'add-forge-now' request dashboard
    
    Remove mock fixture from load tests.
    Add tests for status update and API failure.
    Add tests for mailto email contact.

See https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/1641/ for more details.

Build is green

Patch application report for D7451 (id=27107)

Rebasing onto cc4a82eb38...

Current branch diff-target is up to date.
Changes applied before test
commit e28c8b5e78c776aebc12ff577ed50130d4822ca5
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Wed Mar 30 14:03:12 2022 +0200

    Add missing cypress tests for 'add-forge-now' request dashboard
    
    Remove mock fixture from load tests.
    Add tests for status update and API failure.
    Add tests for mailto email contact.

See https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/1642/ for more details.