1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-12-25 09:44:22 +03:00

test(server): add minimal e2e tests for over HTTP

This commit is contained in:
louistiti 2022-02-03 21:44:49 +08:00
parent aa0136baec
commit 58f5f2d21c
No known key found for this signature in database
GPG Key ID: 0A1C3B043E70C77D
2 changed files with 34 additions and 1 deletions

View File

@ -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",

View File

@ -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)
})
})