Mholloway has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/365425 )
Change subject: Offline compilations endpoint groundwork ...................................................................... Offline compilations endpoint groundwork Lays the groundwork for the forthcoming offline compilations endopint. A formal spec is forthcoming and this will need updating when that's finalized. (Marked with todos where applicable.) The endpoint path will need finalizing as well. Bug: T170732 Change-Id: I6713ccc027fe37434081c7eccf511fb8af8f14f2 --- M lib/mobile-util.js A routes/compilations.js M spec.yaml A test/features/compilations/compilations.js 4 files changed, 122 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps refs/changes/25/365425/1 diff --git a/lib/mobile-util.js b/lib/mobile-util.js index eee8f56..ce36582 100644 --- a/lib/mobile-util.js +++ b/lib/mobile-util.js @@ -9,13 +9,10 @@ mUtil.CONTENT_TYPES = { mobileSections: { name: 'mobile-sections', version: '0.11.0' }, definition: { name: 'definition', version: '0.7.2' }, - random: { name: 'random', version: '0.6.0' }, - announcements: { name: 'announcements', version: '0.1.0' }, - + compilations: { name: 'compilations', version: '0.1.0' }, onthisday: { name: 'onthisday', version: '0.2.0' }, - unpublished: { name: 'unpublished', version: '0.0.0' } }; diff --git a/routes/compilations.js b/routes/compilations.js new file mode 100644 index 0000000..5a66487 --- /dev/null +++ b/routes/compilations.js @@ -0,0 +1,36 @@ +'use strict'; + +const sUtil = require('../lib/util'); +const mUtil = require('../lib/mobile-util'); + +/** + * The main router object + */ +const router = sUtil.router(); + +// todo: populate after we've decided what offline compilations to serve. (T169905) +function getCompilations() { return []; } + +/** + * GET /compilations + * Gets information about the available offline compilations + */ +router.get('/compilations', (req, res) => { + const response = { compilations: getCompilations() }; + const hash = mUtil.hashCode(JSON.stringify(response)); + + res.status(200); + mUtil.setContentType(res, mUtil.CONTENT_TYPES.compilations); + mUtil.setETag(res, hash); + res.set('cache-control', 'public, max-age=7200, s-maxage=14400'); + res.json(response); +}); + +module.exports = function() { + return { + // todo: update when endpoint path is finalized + path: '/', + api_version: 1, + router + }; +}; diff --git a/spec.yaml b/spec.yaml index 3618cf5..0991300 100644 --- a/spec.yaml +++ b/spec.yaml @@ -923,6 +923,50 @@ - text - countries + compilations: + type: object + properties: + compilations: + type: array + description: list of available offline article compilations + items: + $ref: '#/definitions/compilation' + required: + - compilations + + compilation: + type: object + properties: + filename: + type: string + description: The compilation filename + summary: + type: string + description: A short description of the compilation's contents + description: + type: string + description: A detailed description of the compilation's contents + thumb_url: + type: string + description: The URL for a thumbnail icon representing the collection + image_url: + type: string + description: The URL for a full-size image representing the collection + article_count: + type: integer + description: The number of articles included in the compilation + size: + type: integer + description: The size of the compilation, in bytes + timestamp: + type: integer + description: A timestamp for the compilation file creation date (expressed in ms since midnight 1/1/70 UTC) + required: + - filename + - article_count + - size + - timestamp + action: type: object properties: diff --git a/test/features/compilations/compilations.js b/test/features/compilations/compilations.js new file mode 100644 index 0000000..2f9c4f9 --- /dev/null +++ b/test/features/compilations/compilations.js @@ -0,0 +1,41 @@ +'use strict'; + +const preq = require('preq'); +const assert = require('../../utils/assert.js'); +const server = require('../../utils/server.js'); +const headers = require('../../utils/headers.js'); + +describe('compilations', function() { + + this.timeout(20000); // eslint-disable-line no-invalid-this + + before(() => { + return server.start(); + }); + + it('should respond to GET request with expected headers, incl. CORS and CSP headers', () => { + return headers.checkHeaders(`${server.config.uri}en.wikipedia.org/v1/feed/announcements`); + }); + + // todo: update when spec is finalized + it('should return a valid response', () => { + return preq.get({ uri: `${server.config.uri}en.wikipedia.org/v1/feed/announcements` }) + .then((res) => { + assert.status(res, 200); + assert.equal(res.headers['cache-control'], 'public, max-age=7200, s-maxage=14400'); + res.body.announce.forEach((elem) => { + assert.ok(elem.filename, 'filename should be present'); + assert.ok(typeof elem.article_count === 'number', 'article_count present'); + assert.ok(typeof elem.size === 'number', 'size should be present & valid'); + assert.ok(typeof elem.timestamp === 'number', 'timestamp should be present'); + }); + }); + }); + + it('should return 0 compilations', () => { + return preq.get({ uri: `${server.config.uri}en.wikipedia.org/v1/compilations` }) + .then((res) => { + assert.ok(res.body.compilations.length === 0); + }); + }); +}); -- To view, visit https://gerrit.wikimedia.org/r/365425 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6713ccc027fe37434081c7eccf511fb8af8f14f2 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/mobileapps Gerrit-Branch: master Gerrit-Owner: Mholloway <mhollo...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits