add test file

This commit is contained in:
xfarrow 2024-02-21 12:51:33 +01:00
parent cfdac4872e
commit b1e41237a4
3 changed files with 52 additions and 0 deletions

View File

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

View File

@ -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('*')

View File

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