diff --git a/lib/operations/headstart.js b/lib/operations/headstart.js new file mode 100644 index 0000000..988106c --- /dev/null +++ b/lib/operations/headstart.js @@ -0,0 +1,15 @@ +module.exports = { + name: "head start", + url: "/headstart/:name/:from", + fields: [ + { name: "Name", field: "name" }, + { name: "From", field: "from" }, + ], + register(app, output) { + return app.get("/headstart/:name/:from", function (req, res) { + const message = `${req.params.name}, if you started fucking off now, you would have a head start`; + const subtitle = `- ${req.params.from}`; + return output(req, res, message, subtitle); + }); + }, +}; diff --git a/package-lock.json b/package-lock.json index 5cbd420..2e1dc77 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "foaas", - "version": "2.3.0", + "version": "2.3.1", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "2.3.0", + "version": "2.3.1", "license": "WTFPL", "dependencies": { "body-parser": "^1.19.0", diff --git a/spec/operations/headstart_spec.js b/spec/operations/headstart_spec.js new file mode 100644 index 0000000..8c3ee29 --- /dev/null +++ b/spec/operations/headstart_spec.js @@ -0,0 +1,53 @@ +// TODO: This file was created by bulk-decaffeinate. +// Sanity-check the conversion and remove this comment. +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +const operation = require('../../lib/operations/headstart') + +describe('/headstart', function () { + it('should have the correct name', () => expect(operation.name).toEqual('head start')) + + it('should have the correct url', () => expect(operation.url).toEqual('/headstart/:name/:from')) + + it('should have the correct fields', () => + expect(operation.fields).toEqual([ + { name: 'Name', field: 'name' }, + { name: 'From', field: 'from' } + ]) + ) + + return describe('register', function () { + it('should call app.get with correct url', function () { + const app = + { get: jasmine.createSpy() } + + operation.register(app, null) + + expect(app.get).toHaveBeenCalledWith('/headstart/:name/:from', jasmine.any(Function)) + }) + + return it('should call output with correct params', function () { + let func = null + const app = + { get (url, fn) { return func = fn } } + const output = jasmine.createSpy() + operation.register(app, output) + + const req = { + params: { + company: 'TESTCOMPANY', + from: 'TESTFROM' + } + } + + const message = `${req.params.name}, if you started fucking off now, you would have a head start` + const subtitle = `- ${req.params.from}` + + func(req, 'RES') + return expect(output).toHaveBeenCalledWith(req, 'RES', message, subtitle) + }) + }) +})