Remove tests

This commit is contained in:
Aelita4 2024-09-06 20:54:51 +02:00
parent b13a116cd4
commit 56eabc303e
Signed by: Aelita4
GPG Key ID: E44490C2025906C1
2 changed files with 0 additions and 116 deletions

View File

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

View File

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