diff --git a/package.json b/package.json index 89501e7f..49922c76 100644 --- a/package.json +++ b/package.json @@ -22,12 +22,13 @@ }, "scripts": { "lint": "babel-node scripts/lint.js", - "test": "npm run test:json && npm run test:unit && npm run test:e2e", + "test": "npm run test:json && npm run test:over-http && npm run test:unit && npm run test:e2e", "test:unit": "npm run train en && cross-env PIPENV_PIPFILE=bridges/python/Pipfile LEON_NODE_ENV=testing jest --forceExit --silent --projects test/unit/unit.jest.json && npm run train", "test:e2e": "npm run test:e2e:nlp-modules && npm run test:e2e:modules", "test:e2e:modules": "babel-node scripts/run-clean-test-dbs.js && npm run train en && cross-env PIPENV_PIPFILE=bridges/python/Pipfile LEON_NODE_ENV=testing jest --forceExit --silent --verbose --projects test/e2e/modules/e2e.modules.jest.json && babel-node scripts/run-clean-test-dbs.js && npm run train", "test:e2e:nlp-modules": "npm run train en && cross-env PIPENV_PIPFILE=bridges/python/Pipfile LEON_NODE_ENV=testing jest --forceExit --silent --verbose --setupTestFrameworkScriptFile=./test/paths.setup.js test/e2e/nlp-modules.spec.js && npm run train", "test:json": "jest --silent --projects test/json/json.jest.json", + "test:over-http": "npm run generate:pkgs-endpoints && cross-env PIPENV_PIPFILE=bridges/python/Pipfile LEON_NODE_ENV=testing LEON_HOST=http://localhost LEON_PORT=1338 LEON_HTTP_API_KEY=72aeb5ba324580963114481144385d7179c106fc jest --forceExit --silent --verbose --notify=false --bail --collectCoverage=false test/e2e/over-http.spec.js", "test:module": "babel-node scripts/test-module.js", "setup:offline": "babel-node scripts/setup-offline/setup-offline.js", "setup:offline-stt": "babel-node scripts/setup-offline/run-setup-stt.js", diff --git a/test/e2e/over-http.spec.js b/test/e2e/over-http.spec.js new file mode 100644 index 00000000..4da7addf --- /dev/null +++ b/test/e2e/over-http.spec.js @@ -0,0 +1,32 @@ +import superagent from 'superagent' + +import server from '@/core/http-server/server' + +const urlPrefix = `${process.env.LEON_HOST}:${process.env.LEON_PORT}/api` +const queryUrl = `${urlPrefix}/query` +const actionModuleUrl = `${urlPrefix}/p/leon/randomnumber/run`; + +/** + * Test a simple module action over HTTP + */ + +(async () => { + await server.init() +})() + +describe('Over HTTP', () => { + test(`Request query endpoint POST ${queryUrl}`, async () => { + const { body } = await superagent.post(queryUrl) + .send({ query: 'Hello' }) + .set('X-API-Key', process.env.LEON_HTTP_API_KEY) + + expect(body).toHaveProperty('success', true) + }) + + test(`Request an action module: GET ${actionModuleUrl}`, async () => { + const { body } = await superagent.get(actionModuleUrl) + .set('X-API-Key', process.env.LEON_HTTP_API_KEY) + + expect(body).toHaveProperty('success', true) + }) +})