@@ -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);
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
14
src/utils/clearDatabase.ts
Normal file
14
src/utils/clearDatabase.ts
Normal 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();
|
||||
});
|
||||
Reference in New Issue
Block a user