From bcdfd4673e80e6f2eb9aec6c04468a7f4e0c0cb5 Mon Sep 17 00:00:00 2001 From: RabsRincon Date: Fri, 20 Apr 2018 23:23:01 +0200 Subject: [PATCH] Add list formatters handler test --- lib/handlers/api.js | 2 +- test/handlers/api-tests.js | 40 ++++++++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/lib/handlers/api.js b/lib/handlers/api.js index c1fafb74f..bc3caa68b 100644 --- a/lib/handlers/api.js +++ b/lib/handlers/api.js @@ -49,7 +49,7 @@ class ApiHandler { const formatter = new FormatterHandler(ceProps); this.handle.post('/format/:tool', formatter.formatHandler.bind(formatter)); - this.handle.get('/format', formatter.listHandler.bind(formatter)); + this.handle.get('/formats', formatter.listHandler.bind(formatter)); } handleLanguages(req, res) { diff --git a/test/handlers/api-tests.js b/test/handlers/api-tests.js index fa1c7444a..6c11da8ad 100644 --- a/test/handlers/api-tests.js +++ b/test/handlers/api-tests.js @@ -53,10 +53,18 @@ chai.should(); describe('API handling', () => { const app = express(); const apiHandler = new ApiHandler({ - handle: (res, req, next) => { + handle: res => { res.end("compile"); } - }, () => ""); + }, (key, def) => { + switch (key) { + case "formatters": return "formatt"; + case "formatter.formatt.exe": return "echo"; + case "formatter.formatt.version": return "Release"; + case "formatter.formatt.name": return "FormatT"; + default: return def; + } + }); app.use('/api', apiHandler.handle); const compilers = [{ id: "gcc900", @@ -86,7 +94,7 @@ describe('API handling', () => { res.text.should.contain("gcc900"); res.text.should.contain("GCC 9.0.0"); }) - .catch(function (err) { + .catch(err => { throw err; }); }); @@ -99,7 +107,7 @@ describe('API handling', () => { res.should.be.json; res.body.should.deep.equals(compilers); }) - .catch(function (err) { + .catch(err => { throw err; }); }); @@ -112,7 +120,7 @@ describe('API handling', () => { res.should.be.json; res.body.found.should.be.true; }) - .catch(function (err) { + .catch(err => { throw err; }); }); @@ -125,7 +133,7 @@ describe('API handling', () => { res.should.be.json; res.body.should.deep.equals([compilers[0], compilers[2]]); }) - .catch(function (err) { + .catch(err => { throw err; }); }); @@ -138,7 +146,7 @@ describe('API handling', () => { res.should.be.json; res.body.should.deep.equals([compilers[1]]); }) - .catch(function (err) { + .catch(err => { throw err; }); }); @@ -146,7 +154,6 @@ describe('API handling', () => { return chai.request(app) .get('/api/languages') .then(res => { - console.log(res.text); res.should.have.status(200); res.should.be.text; res.text.should.contain("Name"); @@ -155,7 +162,7 @@ describe('API handling', () => { // We should not list languages for which there are no compilers res.text.should.not.contain("Haskell"); }) - .catch(function (err) { + .catch(err => { throw err; }); }); @@ -168,8 +175,21 @@ describe('API handling', () => { res.should.be.json; res.body.should.deep.equals([languages['c++'], languages.pascal]); }) - .catch(function (err) { + .catch(err => { throw err; }); }); + it('should list the formatters', () => { + return chai.request(app) + .get('/api/formats') + .set('Accept', 'application/json') + .then(res => { + res.should.have.status(200); + res.should.be.json; + res.body.should.deep.equals([{name: "FormatT", version: "Release"}]); + }) + .catch(err => { + throw err; + }) + }); });