Mobrovac has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/323148

Change subject: Clean up relics from the service template
......................................................................

Clean up relics from the service template

Remove the example route files and tests and expose the correct
information in the Swagger spec.

Change-Id: Id9f3ad87a0bec7981fd0ac4b95549cb45dcd1c56
---
D routes/empty.js.template
D routes/ex.js
M spec.yaml
D test/features/ex/errors.js
4 files changed, 6 insertions(+), 347 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/trending-edits 
refs/changes/48/323148/1

diff --git a/routes/empty.js.template b/routes/empty.js.template
deleted file mode 100644
index 97cff86..0000000
--- a/routes/empty.js.template
+++ /dev/null
@@ -1,39 +0,0 @@
-'use strict';
-
-
-var BBPromise = require('bluebird');
-var preq = require('preq');
-var sUtil = require('../lib/util');
-
-// shortcut
-var HTTPError = sUtil.HTTPError;
-
-
-/**
- * The main router object
- */
-var router = sUtil.router();
-
-/**
- * The main application object reported when this module is require()d
- */
-var app;
-
-
-/** ROUTE DECLARATIONS GO HERE **/
-
-
-module.exports = function(appObj) {
-
-    app = appObj;
-
-    // the returned object mounts the routes on
-    // /{domain}/vX/mount/path
-    return {
-        path: '/mount/path',
-        api_version: X,  // must be a number!
-        router: router
-    };
-
-};
-
diff --git a/routes/ex.js b/routes/ex.js
deleted file mode 100644
index 6cd4f62..0000000
--- a/routes/ex.js
+++ /dev/null
@@ -1,132 +0,0 @@
-'use strict';
-
-
-var BBPromise = require('bluebird');
-var preq = require('preq');
-var sUtil = require('../lib/util');
-var fs = BBPromise.promisifyAll(require('fs'));
-
-// shortcut
-var HTTPError = sUtil.HTTPError;
-
-
-/**
- * The main router object
- */
-var router = sUtil.router();
-
-/**
- * The main application object reported when this module is require()d
- */
-var app;
-
-
-/********************
- *  ERROR EXAMPLES  *
- ********************/
-
-
-/**
- * GET /err/array
- * An example route creating an invalid array to show generic,
- * direct error handling
- */
-router.get('/err/array', function(req, res) {
-
-    // let's create an array with -1 elems!
-    var arr = new Array(-1);
-    // this is never reached
-    res.send(arr.join());
-
-});
-
-
-/**
- * GET /err/file
- * Showcases promise error handling. The function is trying to
- * read a non-existent file, which will produce an error,
- * automatically handled by the template.
- */
-router.get('/err/file', function(req, res) {
-
-    // NOTE the return statement here, the promise
-    // must be returned!
-    // read the file
-    return fs.readFileAsync('../mushrooms.txt')
-    // and then send it back to the caller
-    .then(function(text) {
-        // note that this point is never reached
-        res.send(text);
-    });
-
-});
-
-
-/**
- * GET /err/manual/error
- * Throws a generic error manually
- */
-router.get('/err/manual/error', function(req, res) {
-
-    // simulate a constraint check
-    var max = 50;
-    if (max > 10) {
-        throw new Error('A maximum value of 10 is expected, ' + max + ' 
given!');
-    }
-
-});
-
-
-/**
- * GET /err/manual/deny
- * Denies access to this resource endpoint
- */
-router.get('/err/manual/deny', function(req, res) {
-
-    // don't allow access
-    throw new HTTPError({
-        status: 403,
-        type: 'access_denied',
-        title: 'Access denied',
-        detail: 'No access is allowed to this endpoint'
-    });
-
-});
-
-
-/**
- * GET /err/manual/auth
- */
-router.get('/err/manual/auth', function(req, res) {
-
-    // pretend to read a token file
-    // again, note the return statement
-    return fs.readFileAsync(__dirname + '/../static/index.html')
-    // and pretend to compare it with what the user sent
-    .then(function(token) {
-        if (!req.params || req.params.token !== token) {
-            // nope, not authorised to be here, sorry
-            throw new HTTPError({
-                status: 401,
-                type: 'unauthorized',
-                title: 'Unauthorized',
-                detail: 'You are not authorized to fetch this endpoint!'
-            });
-        }
-    });
-
-});
-
-
-module.exports = function(appObj) {
-
-    app = appObj;
-
-    return {
-        path: '/ex',
-        skip_domain: true,
-        router: router
-    };
-
-};
-
diff --git a/spec.yaml b/spec.yaml
index 7fb64a4..3d47729 100644
--- a/spec.yaml
+++ b/spec.yaml
@@ -1,12 +1,12 @@
 swagger: '2.0'
 info:
-  version: 0.4.0
-  title: WMF Node.JS Service Template
-  description: A template for creating Node.JS services
+  version: 0.1.0
+  title: Trending Edits Service
+  description: A trending REST API service based on edits
   termsOfService: https://wikimediafoundation.org/wiki/Terms_of_Use
   contact:
-    name: the Wikimedia Services team
-    url: http://mediawiki.org/wiki/Services
+    name: Wikimedia Reading Team
+    url: http://mediawiki.org/wiki/Reading
   license:
     name: Apache2
     url: http://www.apache.org/licenses/LICENSE-2.0
@@ -52,7 +52,7 @@
               fooo: true
           response:
             status: 404
-  # from routes/v1.js
+  # from routes/trending-v1.js
   /{domain}/v1/feed/trending-edits/:
     get:
       tags:
@@ -136,84 +136,3 @@
           request: {}
           response:
             status: 301
-  # from routes/ex.js
-  /ex/err/array:
-    get:
-      tags:
-        - Example
-        - Error
-        - Internal error
-      description: Generates an internal error due to a wrong array declaration
-      produces:
-        - application/json
-      x-amples:
-        - title: wrong array declaration example
-          request: {}
-          response:
-            status: 500
-            headers:
-              content-type: application/json
-  /ex/err/file:
-    get:
-      tags:
-        - Example
-        - Error
-        - Internal error
-      description: Generates an internal error due to a non-existing file
-      produces:
-        - application/json
-      x-amples:
-        - title: non-existing file example
-          request: {}
-          response:
-            status: 500
-            headers:
-              content-type: application/json
-  /ex/err/manual/error:
-    get:
-      tags:
-        - Example
-        - Error
-        - Internal error
-      description: Generates an internal error due to a user-thrown error
-      produces:
-        - application/json
-      x-amples:
-        - title: user error example
-          request: {}
-          response:
-            status: 500
-            headers:
-              content-type: application/json
-  /ex/err/manual/deny:
-    get:
-      tags:
-        - Example
-        - Error
-        - Access denied
-      description: Generates an access-denied error
-      produces:
-        - application/json
-      x-amples:
-        - title: access denied error example
-          request: {}
-          response:
-            status: 403
-            headers:
-              content-type: application/json
-  /ex/err/manual/auth:
-    get:
-      tags:
-        - Example
-        - Error
-        - Unauthorised access
-      description: Generates an unauthorised error
-      produces:
-        - application/json
-      x-amples:
-        - title: unauthorised error example
-          request: {}
-          response:
-            status: 401
-            headers:
-              content-type: application/json
diff --git a/test/features/ex/errors.js b/test/features/ex/errors.js
deleted file mode 100644
index 4e7ec44..0000000
--- a/test/features/ex/errors.js
+++ /dev/null
@@ -1,89 +0,0 @@
-'use strict';
-
-
-var preq   = require('preq');
-var assert = require('../../utils/assert.js');
-var server = require('../../utils/server.js');
-
-
-describe('errors', function() {
-
-    this.timeout(20000);
-
-    before(function () { return server.start(); });
-
-    // common URI prefix for the errors
-    var uri = server.config.uri + 'ex/err/';
-
-    it('array creation error', function() {
-        return preq.get({
-            uri: uri + 'array'
-        }).then(function(res) {
-            // if we are here, no error was thrown, not good
-            throw new Error('Expected an error to be thrown, got status: ' + 
res.status);
-        }, function(err) {
-            // inspect the status
-            assert.deepEqual(err.status, 500);
-            // check the error title
-            assert.deepEqual(err.body.title, 'RangeError');
-        });
-    });
-
-    it('file read error', function() {
-        return preq.get({
-            uri: uri + 'file'
-        }).then(function(res) {
-            // if we are here, no error was thrown, not good
-            throw new Error('Expected an error to be thrown, got status: ' + 
res.status);
-        }, function(err) {
-            // inspect the status
-            assert.deepEqual(err.status, 500);
-            // check the error title
-            assert.deepEqual(err.body.title, 'Error');
-        });
-    });
-
-    it('constraint check error', function() {
-        return preq.get({
-            uri: uri + 'manual/error'
-        }).then(function(res) {
-            // if we are here, no error was thrown, not good
-            throw new Error('Expected an error to be thrown, got status: ' + 
res.status);
-        }, function(err) {
-            // inspect the status
-            assert.deepEqual(err.status, 500);
-            // check the error title
-            assert.deepEqual(err.body.title, 'Error');
-        });
-    });
-
-    it('access denied error', function() {
-        return preq.get({
-            uri: uri + 'manual/deny'
-        }).then(function(res) {
-            // if we are here, no error was thrown, not good
-            throw new Error('Expected an error to be thrown, got status: ' + 
res.status);
-        }, function(err) {
-            // inspect the status
-            assert.deepEqual(err.status, 403);
-            // check the error title
-            assert.deepEqual(err.body.type, 'access_denied');
-        });
-    });
-
-    it('authorisation error', function() {
-        return preq.get({
-            uri: uri + 'manual/auth'
-        }).then(function(res) {
-            // if we are here, no error was thrown, not good
-            throw new Error('Expected an error to be thrown, got status: ' + 
res.status);
-        }, function(err) {
-            // inspect the status
-            assert.deepEqual(err.status, 401);
-            // check the error title
-            assert.deepEqual(err.body.type, 'unauthorized');
-        });
-    });
-
-});
-

-- 
To view, visit https://gerrit.wikimedia.org/r/323148
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id9f3ad87a0bec7981fd0ac4b95549cb45dcd1c56
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/trending-edits
Gerrit-Branch: master
Gerrit-Owner: Mobrovac <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to