feat: added Prisma
This commit is contained in:
Riccardo Senica
2023-08-05 17:23:34 +02:00
committed by GitHub
parent 9c01101c1b
commit 392e0db67b
17 changed files with 181 additions and 18 deletions

View File

@@ -1,8 +1,17 @@
import { randomUUID } from 'crypto';
import { addition } from './addition';
jest.mock('../database/database', () => ({
createAddition: jest.fn((value: number) => ({
id: randomUUID(),
datetime: new Date(),
value
}))
}));
describe('call', () => {
it('returns the input value increased by one', async () => {
const response = addition(3);
const response = await addition(3);
expect(response).toBe(4);
});

View File

@@ -1,11 +1,14 @@
import { createAddition } from '../database/database';
import { logger } from './logger';
/**
* Format a response message containing a user input.
* Increase the user imput value by one, and creates an Addition record with that value.
* @param number - The user input value.
* @returns The value increased by one.
*/
export function addition(value: number) {
export async function addition(value: number) {
logger.info(`addition(${value})`);
await createAddition(value);
return value + 1;
}

View File

@@ -0,0 +1,14 @@
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
/**
* Clear the database of all records.
*/
export const clearDatabase = async () => {
await prisma.addition.deleteMany({});
};
global.beforeAll(async () => {
await clearDatabase();
});