diff --git a/backend/apis/nodejs/package.json b/backend/apis/nodejs/package.json new file mode 100644 index 0000000..7fdd765 --- /dev/null +++ b/backend/apis/nodejs/package.json @@ -0,0 +1,17 @@ +{ + "name": "blink_api", + "version": "1.0.0", + "description": "APIs for the Blink service", + "main": "./src/app.js", + "directories": { + "test": "tests" + }, + "scripts": { + "test": "jest" + }, + "author": "xfarrow", + "license": "GPL-3.0-or-later", + "dependencies": { + "path": "^0.12.7" + } +} diff --git a/backend/apis/nodejs/src/models/person_model.js b/backend/apis/nodejs/src/models/person_model.js index a143c6a..e949c7f 100644 --- a/backend/apis/nodejs/src/models/person_model.js +++ b/backend/apis/nodejs/src/models/person_model.js @@ -49,6 +49,11 @@ async function getPersonByEmail(email){ .first(); } +/** + * Get Person by Id + * @param {*} id - The id to look the person for + * @returns + */ async function getPersonById(id){ return await knex('Person') .select('*') diff --git a/backend/apis/nodejs/tests/person.test.js b/backend/apis/nodejs/tests/person.test.js new file mode 100644 index 0000000..8710f90 --- /dev/null +++ b/backend/apis/nodejs/tests/person.test.js @@ -0,0 +1,30 @@ +// Run me with "npm test" + +const request = require('supertest'); +const app = require('../src/app'); +require('dotenv').config({ path: '../src/.env' }); + +describe('Person Tests', () => { + test('Correct registration', async () => { + const response = await request(app) + .post('/api/register') + .send({ + email : "johntestdoe@mail.org", + password : "password", + display_name : "John Doe" + }) + expect(response.status).toBe(200); + expect(response.body).toEqual({ activationLink: expect.any(String) }); + }); + + test('Incorrect registration', async () => { + const response = await request(app) + .post('/api/register') + .send({ + email : "this is not an email", + password : "password", + display_name : "John Doe" + }) + expect(response.status).toBe(400); + }); +});