Procházet zdrojové kódy

Fix JS Fortune Tests (#2674)

* Fix db host for mochiweb, enable db tests

Having the wrong db host was causing the server to crash, which made
the json and plaintext tests fail.

I enabled the four db-related tests since they seem to be implemented.
They all pass except fortunes.  Unfortunately that implementation
appears to live in another github repo (utkarshkukreti/erl_bench) so
we can't fix it.

I removed the sed line from setup.sh since the file it was targeting
(mochiweb_bench_sup.erl) didn't have any of the strings it was trying
to replace.

* Fix fortunes tests
Nate před 8 roky
rodič
revize
3d143cc15b

+ 1 - 1
frameworks/JavaScript/hapi/handlers/mongoose.js

@@ -69,7 +69,7 @@ module.exports = {
   Fortunes: (req, reply) => {
     promiseAllFortunes()
       .then((fortunes) => {
-        fortunes.push(h.ADDITIONAL_FORTUNE);
+        fortunes.push(h.additionalFortune());
         fortunes.sort((a, b) => a.message.localeCompare(b.message));
       
         reply.view('fortunes', {

+ 1 - 1
frameworks/JavaScript/hapi/handlers/sequelize-postgres.js

@@ -57,7 +57,7 @@ module.exports = {
 
   Fortunes: (req, reply) => {
     Fortunes.findAll().then((fortunes) => {
-      fortunes.push(h.ADDITIONAL_FORTUNE);
+      fortunes.push(h.additionalFortune());
       fortunes.sort((a, b) => a.message.localeCompare(b.message));
 
       reply.view('fortunes', { fortunes: fortunes })

+ 1 - 1
frameworks/JavaScript/hapi/handlers/sequelize.js

@@ -62,7 +62,7 @@ module.exports = {
 
   Fortunes: (req, reply) => {
     Fortunes.findAll().then((fortunes) => {
-      fortunes.push(h.ADDITIONAL_FORTUNE);
+      fortunes.push(h.additionalFortune());
       fortunes.sort((a, b) => a.message.localeCompare(b.message));
 
       reply.view('fortunes', { fortunes })

+ 2 - 2
frameworks/JavaScript/hapi/helper.js

@@ -21,9 +21,9 @@ module.exports = {
     return queries;
   },
 
-  ADDITIONAL_FORTUNE: {
+  additionalFortune: () => ({
     id: 0,
     message: 'Additional fortune added at request time.'
-  }
+  })
 
 };

+ 1 - 1
frameworks/JavaScript/nodejs/handlers/mongodb-raw.js

@@ -64,7 +64,7 @@ module.exports = {
     mongodbGetAllFortunes((err, fortunes) => {
       if (err) { return process.exit(1) }
 
-      fortunes.push(h.ADDITIONAL_FORTUNE);
+      fortunes.push(h.additionalFortune());
       fortunes.sort(function (a, b) {
         return a.message.localeCompare(b.message);
       });

+ 1 - 1
frameworks/JavaScript/nodejs/handlers/mongoose.js

@@ -57,7 +57,7 @@ module.exports = {
     mongooseGetAllFortunes((err, fortunes) => {
       if (err) { return process.exit(1); }
 
-      fortunes.push(h.ADDITIONAL_FORTUNE);
+      fortunes.push(h.additionalFortune());
       fortunes.sort((a, b) => {
         return a.message.localeCompare(b.message);
       });

+ 1 - 1
frameworks/JavaScript/nodejs/handlers/mysql-raw.js

@@ -69,7 +69,7 @@ module.exports = {
     mysqlGetAllFortunes((err, fortunes) => {
       if (err) { return process.exit(1); }
 
-      fortunes.push(h.ADDITIONAL_FORTUNE);
+      fortunes.push(h.additionalFortune());
       fortunes.sort((a, b) => a.message.localeCompare(b.message));
       h.addTfbHeaders(res, 'html');
       res.end(h.fortunesTemplate({

+ 1 - 1
frameworks/JavaScript/nodejs/handlers/sequelize-postgres.js

@@ -61,7 +61,7 @@ module.exports = {
 
   Fortunes: (req, res) => {
     Fortunes.findAll().then((fortunes) => {
-      fortunes.push(h.ADDITIONAL_FORTUNE);
+      fortunes.push(h.additionalFortune());
       fortunes.sort((a, b) => a.message.localeCompare(b.message));
 
       h.addTfbHeaders(res, 'html');

+ 1 - 1
frameworks/JavaScript/nodejs/handlers/sequelize.js

@@ -63,7 +63,7 @@ module.exports = {
 
   Fortunes: (req, res) => {
     Fortunes.findAll().then((fortunes) => {
-      fortunes.push(h.ADDITIONAL_FORTUNE);
+      fortunes.push(h.additionalFortune());
       fortunes.sort((a, b) => {
         return a.message.localeCompare(b.message);
       });

+ 2 - 2
frameworks/JavaScript/nodejs/helper.js

@@ -4,10 +4,10 @@ const GREETING = "Hello, World!";
 
 const self = module.exports = {
 
-  ADDITIONAL_FORTUNE: {
+  additionalFortune: () => ({
     id: 0,
     message: 'Additional fortune added at request time.'
-  },
+  }),
 
   fortunesTemplate: Handlebars.compile([
     "<!DOCTYPE html>",

+ 1 - 1
frameworks/JavaScript/sailsjs/api/controllers/RedisController.js

@@ -100,7 +100,7 @@ module.exports = {
   Fortunes: function(req, res) {
     redisGetAllFortunes()
       .then(function (fortunes) {
-        fortunes.push(h.ADDITIONAL_FORTUNE)
+        fortunes.push(h.additionalFortune())
         fortunes.sort(function (a, b) {
           return a.message.localeCompare(b.message)
         })

+ 1 - 1
frameworks/JavaScript/sailsjs/api/controllers/SequelizeMySQLController.js

@@ -120,7 +120,7 @@ module.exports = {
     Fortunes
       .findAll()
       .then(function (fortunes) {
-        fortunes.push(h.ADDITIONAL_FORTUNE)
+        fortunes.push(h.additionalFortune())
         fortunes.sort(function (a, b) {
           return a.message.localeCompare(b.message)
         })

+ 1 - 1
frameworks/JavaScript/sailsjs/api/controllers/SequelizePostgresController.js

@@ -121,7 +121,7 @@ module.exports = {
     Fortunes
       .findAll()
       .then(function (fortunes) {
-        fortunes.push(h.ADDITIONAL_FORTUNE)
+        fortunes.push(h.additionalFortune())
         fortunes.sort(function (a, b) {
           return a.message.localeCompare(b.message)
         })

+ 7 - 9
frameworks/JavaScript/sailsjs/api/services/helper.js

@@ -2,19 +2,17 @@
 
 module.exports = {
 
-  randomTfbNumber: function() {
-    return Math.floor(Math.random() * 10000) + 1
-  },
+  randomTfbNumber: () => Math.floor(Math.random() * 10000) + 1,
 
-  getQueries: function(req) {
-    var queries = req.param('queries')
-    queries = ~~(queries) || 1
+  getQueries: (req) => {
+    let queries = req.param('queries');
+    queries = ~~(queries) || 1;
     return Math.min(Math.max(queries, 1), 500)
   },
 
-  ADDITIONAL_FORTUNE: {
+  additionalFortune: () => ({
     id: 0,
     message: "Additional fortune added at request time."
-  }
+  })
 
-}
+};