You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2018/03/19 18:19:21 UTC

[GitHub] garrensmith closed pull request #1060: Remove all uses of JQuery from the verifyinstall addon

garrensmith closed pull request #1060: Remove all uses of JQuery from the verifyinstall addon
URL: https://github.com/apache/couchdb-fauxton/pull/1060
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/app/addons/verifyinstall/actions.js b/app/addons/verifyinstall/actions.js
index c8acc551f..80f6e6a95 100644
--- a/app/addons/verifyinstall/actions.js
+++ b/app/addons/verifyinstall/actions.js
@@ -17,16 +17,20 @@ import ActionTypes from "./actiontypes";
 
 
 // helper function to publish success/fail result of a single test having been ran
-var testPassed = function (test) {
-  FauxtonAPI.dispatch({
-    type: ActionTypes.VERIFY_INSTALL_SINGLE_TEST_COMPLETE,
-    test: test,
-    success: true
-  });
+const testPassed = function (test) {
+  return function () {
+    FauxtonAPI.dispatch({
+      type: ActionTypes.VERIFY_INSTALL_SINGLE_TEST_COMPLETE,
+      test: test,
+      success: true
+    });
+  };
 };
 
-var testFailed = function (test) {
+let allTestsPassed = true;
+const testFailed = function (test) {
   return function (xhr) {
+    allTestsPassed = false;
     if (!xhr) { return; }
 
     FauxtonAPI.dispatch({
@@ -34,9 +38,14 @@ var testFailed = function (test) {
       test: test,
       success: false
     });
-
+    let reason = 'n/a';
+    if (xhr.responseText) {
+      reason = JSON.parse(xhr.responseText).reason;
+    } else if (xhr.message) {
+      reason = xhr.message;
+    }
     FauxtonAPI.addNotification({
-      msg: 'Error: ' + JSON.parse(xhr.responseText).reason,
+      msg: 'Error: ' + reason,
       type: 'error'
     });
   };
@@ -56,47 +65,41 @@ export default {
     var testProcess = VerifyInstall.testProcess;
 
     testProcess.setup()
-      .then(function () {
-        return testProcess.saveDB();
+      .then(() => {
+        return testProcess.saveDB().then(testPassed(Constants.TESTS.CREATE_DATABASE));
+      }, testFailed(Constants.TESTS.CREATE_DATABASE))
+      .then(() => {
+        return testProcess.saveDoc().then(testPassed(Constants.TESTS.CREATE_DOCUMENT));
       }, testFailed(Constants.TESTS.CREATE_DATABASE))
-      .then(function () {
-        testPassed(Constants.TESTS.CREATE_DATABASE);
-        return testProcess.saveDoc();
+      .then(() => {
+        return testProcess.updateDoc().then(testPassed(Constants.TESTS.UPDATE_DOCUMENT));
       }, testFailed(Constants.TESTS.CREATE_DOCUMENT))
-      .then(function () {
-        testPassed(Constants.TESTS.CREATE_DOCUMENT);
-        return testProcess.updateDoc();
+      .then(() => {
+        return testProcess.destroyDoc().then(testPassed(Constants.TESTS.DELETE_DOCUMENT));
       }, testFailed(Constants.TESTS.UPDATE_DOCUMENT))
-      .then(function () {
-        testPassed(Constants.TESTS.UPDATE_DOCUMENT);
-        return testProcess.destroyDoc();
+      .then(() => {
+        return testProcess.setupView().then(() => {
+          return testProcess.testView().then(testPassed(Constants.TESTS.CREATE_VIEW));
+        });
       }, testFailed(Constants.TESTS.DELETE_DOCUMENT))
-      .then(function () {
-        testPassed(Constants.TESTS.DELETE_DOCUMENT);
-        return testProcess.setupView();
-      }, testFailed(Constants.TESTS.CREATE_VIEW))
-      .then(function () {
-        return testProcess.testView();
-      }, testFailed(Constants.TESTS.CREATE_VIEW))
-      .then(function () {
-        testPassed(Constants.TESTS.CREATE_VIEW);
-        return testProcess.setupReplicate();
+      .then(() => {
+        return testProcess.setupReplicate().then(() => {
+          return testProcess.testReplicate().then(testPassed(Constants.TESTS.REPLICATION));
+        });
       }, testFailed(Constants.TESTS.CREATE_VIEW))
-      .then(function () {
-        return testProcess.testReplicate();
-      }, testFailed(Constants.TESTS.REPLICATION))
-      .then(function () {
-        testPassed(Constants.TESTS.REPLICATION);
-
+      .then(() => {}, testFailed(Constants.TESTS.REPLICATION))
+      .then(() => {
         // now announce the tests have been ran
         FauxtonAPI.dispatch({ type: ActionTypes.VERIFY_INSTALL_ALL_TESTS_COMPLETE });
 
-        FauxtonAPI.addNotification({
-          msg: 'Success! Your CouchDB installation is working. Time to Relax.',
-          type: 'success'
-        });
+        if (allTestsPassed) {
+          FauxtonAPI.addNotification({
+            msg: 'Success! Your CouchDB installation is working. Time to Relax.',
+            type: 'success'
+          });
+        }
 
         testProcess.removeDBs();
-      }, testFailed(Constants.TESTS.REPLICATION));
+      });
   }
 };
diff --git a/app/addons/verifyinstall/resources.js b/app/addons/verifyinstall/resources.js
index af78fdd27..569066079 100644
--- a/app/addons/verifyinstall/resources.js
+++ b/app/addons/verifyinstall/resources.js
@@ -12,21 +12,22 @@
 
 import app from "../../app";
 import FauxtonAPI from "../../core/api";
+import { get, post } from "../../core/ajax";
 import Databases from "../databases/resources";
 import Documents from "../documents/resources";
-var Verifyinstall = FauxtonAPI.addon();
+const Verifyinstall = FauxtonAPI.addon();
 
-var db = new Databases.Model({
+const db = new Databases.Model({
   id: 'verifytestdb',
   name: 'verifytestdb'
 });
 
-var dbReplicate = new Databases.Model({
+const dbReplicate = new Databases.Model({
   id: 'verifytestdb_replicate',
   name: 'verifytestdb_replicate'
 });
 
-var doc, viewDoc;
+let doc, viewDoc;
 
 Verifyinstall.testProcess = {
   saveDoc: function () {
@@ -51,55 +52,56 @@ Verifyinstall.testProcess = {
   },
 
   setupDB: function (db) {
-    var deferred = FauxtonAPI.Deferred();
-    db.fetch()
-      .then(function () {
+    const promise = new FauxtonAPI.Promise((resolve, reject) => {
+      db.fetch().then(() => {
         return db.destroy();
-      }, function () {
-        deferred.resolve();
-      })
-      .then(function () {
-        deferred.resolve();
-      }, function (xhr, error, reason) {
-        if (reason === 'Unauthorized') {
-          deferred.reject(xhr, error, reason);
-        }
+      }, () => {
+        resolve();
+      }).then(() => {
+        resolve();
+      }, (xhr, error, reason) => {
+        reject(new Error(reason));
       });
-
-    return deferred;
+    });
+    return promise;
   },
 
   setup: function () {
-    return FauxtonAPI.when([
+    return FauxtonAPI.Promise.all([
       this.setupDB(db),
       this.setupDB(dbReplicate)
     ]);
   },
 
   testView: function () {
-    var deferred = FauxtonAPI.Deferred();
-    var promise = $.get(viewDoc.url() + '/_view/testview');
+    let resolve, reject;
+    const promise = new FauxtonAPI.Promise(function(res, rej) {
+      resolve = res;
+      reject = rej;
+    });
+    const getPromise = get(viewDoc.url() + '/_view/testview').then(res => {
+      if (res.error) {
+        throw new Error(res.reason || res.error);
+      }
+      return res;
+    });
 
-    promise.then(function (resp) {
+    getPromise.then(function (resp) {
       resp = _.isString(resp) ? JSON.parse(resp) : resp;
-      var row = resp.rows[0];
+      const row = resp.rows[0];
       if (row.value === 6) {
-        return deferred.resolve();
+        resolve();
       }
-      var reason = {
-        reason: 'Values expect 6, got ' + row.value
-      };
-
-      deferred.reject({responseText: JSON.stringify(reason)});
-    }, deferred.reject);
+      reject(new Error('Values expect 6, got ' + row.value));
+    }, reject);
 
-    return deferred;
+    return promise;
   },
 
   setupView: function () {
-    var doc1 = new Documents.Doc({_id: 'test_doc_10', a: 1}, { database: db });
-    var doc2 = new Documents.Doc({_id: 'test_doc_20', a: 2}, { database: db });
-    var doc3 = new Documents.Doc({_id: 'test_doc_30', a: 3}, { database: db });
+    const doc1 = new Documents.Doc({_id: 'test_doc_10', a: 1}, { database: db });
+    const doc2 = new Documents.Doc({_id: 'test_doc_20', a: 2}, { database: db });
+    const doc3 = new Documents.Doc({_id: 'test_doc_30', a: 3}, { database: db });
 
     viewDoc = new Documents.Doc({
       _id: '_design/view_check',
@@ -113,43 +115,40 @@ Verifyinstall.testProcess = {
       database: db
     });
 
-    return FauxtonAPI.when([doc1.save(), doc2.save(), doc3.save(), viewDoc.save()]);
+    return FauxtonAPI.Promise.all([doc1.save(), doc2.save(), doc3.save(), viewDoc.save()]);
   },
 
   setupReplicate: function () {
-    return $.ajax({
-      url: app.host + '/_replicate',
-      contentType: 'application/json',
-      type: 'POST',
-      dataType: 'json',
-      processData: false,
-      data: JSON.stringify({
-        create_target: true,
-        source: 'verifytestdb',
-        target: 'verifytestdb_replicate'
-      })
+    const body = {
+      create_target: true,
+      source: 'verifytestdb',
+      target: 'verifytestdb_replicate'
+    };
+    return post(
+      app.host + '/_replicate',
+      body
+    ).then(res => {
+      if (res.error) {
+        throw new Error(res.reason || res.error);
+      }
+      return res;
     });
   },
 
   testReplicate: function () {
-    var deferred = FauxtonAPI.Deferred();
-    var promise = dbReplicate.fetch();
-
-    promise.then(function () {
-      var docCount = dbReplicate.get('doc_count');
-      if (docCount === 4) {
-        deferred.resolve();
-        return;
-      }
-
-      var reason = {
-        reason: 'Replication Failed, expected 4 docs got ' + docCount
-      };
-
-      deferred.reject({responseText: JSON.stringify(reason)});
-    }, deferred.reject);
+    const promise = new FauxtonAPI.Promise((resolve, reject) => {
+      dbReplicate.fetch().then(() => {
+        const docCount = dbReplicate.get('doc_count');
+        if (docCount === 4) {
+          resolve();
+          return;
+        }
+        const reason = 'Replication Failed, expected 4 docs got ' + docCount;
+        reject(new Error(reason));
+      }, reject);
+    });
 
-    return deferred;
+    return promise;
   },
 
   removeDBs: function () {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services