From 56eabc303e81ac735dcf280f765f1ca7d7da08e1 Mon Sep 17 00:00:00 2001 From: Aelita4 Date: Fri, 6 Sep 2024 20:54:51 +0200 Subject: [PATCH] Remove tests --- test/database.test.ts | 31 ------------- test/resourceManager.test.ts | 85 ------------------------------------ 2 files changed, 116 deletions(-) delete mode 100644 test/database.test.ts delete mode 100644 test/resourceManager.test.ts diff --git a/test/database.test.ts b/test/database.test.ts deleted file mode 100644 index 1d0e625..0000000 --- a/test/database.test.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { createUser, deleteUser, getUserByNickOrEmail } from '../src/lib/db/users'; -import { connect, disconnect } from '../src/lib/db/mongodb'; -import { verify } from 'argon2'; - -beforeEach(async () => { - await connect(); -}); - -afterEach(async () => { - await disconnect(); -}); - -describe('Test user database functions', () => { - test('getUserByNickOrEmail', async () => { - const user = await getUserByNickOrEmail("gargamel"); - expect(user).not.toBeNull(); - expect(user?.username).toBe("gargamel"); - expect(user?.email).toBe("gargamel@smerfy.pl"); - }); - - test('createAndVerifyUser', async () => { - await createUser("test", "test@example.com", "password"); - const user = await getUserByNickOrEmail("test"); - expect(user).not.toBeNull(); - if(!user) return; - expect(user?.username).toBe("test"); - expect(user?.email).toBe("test@example.com"); - expect(await verify(user?.password as string, "password")).toBe(true); - await deleteUser(user._id); - }); -}); diff --git a/test/resourceManager.test.ts b/test/resourceManager.test.ts deleted file mode 100644 index fe186c6..0000000 --- a/test/resourceManager.test.ts +++ /dev/null @@ -1,85 +0,0 @@ -import { connect, disconnect } from "../src/lib/db/mongodb"; -import { createUser, deleteUser } from "../src/lib/db/users"; -import { calculateCurrentAvailableResources, getUserResources, updateUserResources } from "../src/lib/utils/resourceManager"; -import User from "../src/types/User"; - -let user: User; - -describe('Test resource manager', () => { - beforeEach(async () => { - await connect(); - user = await createUser("test", "test@example.com", "password"); - }); - - afterEach(async () => { - await deleteUser(user._id); - await disconnect(); - }); - - describe('Test initial resources amount', () => { - test('initialResourcesAmount', async () => { - const resources = await getUserResources(user._id); - let i = 1; - resources.forEach(res => { - expect(res.amount).toBe(i * 11); - expect(res.perHourMiningRate).toBe(i * 11); - i++; - }); - }); - }); - - describe('Test calculation of available resources', () => { - test('calculationOfAvailableResources', async () => { - const resources = await getUserResources(user._id); - - resources.forEach(res => { - res.amount = 0; - res.lastUpdated = new Date(Date.now() - 1000 * 60 * 60); - }); - - await updateUserResources(user._id, resources); - const availableResources = await calculateCurrentAvailableResources(user._id); - let i = 1; - availableResources.forEach(res => { - expect(res.amount).toBeCloseTo(i * 11); - i++; - }); - - const resourcesAfter = await getUserResources(user._id); - i = 1; - resourcesAfter.forEach(res => { - expect(res.amount).toBeCloseTo(i * 11); - i++; - }); - }); - }); - - describe('Test taking resources', () => { - test('takingResources', async () => { - const resources = await getUserResources(user._id); - resources.forEach(res => { - res.amount = 10_000; - }); - - let i = 1; - - resources.forEach(res => { - res.amount -= i * 100; - i++; - }); - - await updateUserResources(user._id, resources); - - const resourcesAfter = await getUserResources(user._id); - i = 1; - resourcesAfter.forEach(res => { - expect(res.amount).toBeCloseTo(10_000 - i * 100); - i++; - }); - }); - }); -}); - - - -