235 lines
8.3 KiB
TypeScript
235 lines
8.3 KiB
TypeScript
import { getUserById, getUserByNickOrEmail } from '../../src/lib/db/users';
|
|
import { connect } from '../../src/lib/db/mongodb';
|
|
import { ObjectId } from 'mongodb';
|
|
import { getAllSystems, getSystemById } from '../../src/lib/db/systems';
|
|
import { getAllStructures, getStructureById } from '../../src/lib/db/structures';
|
|
import { getSpyReportById, getSpyReportBySystemId } from '../../src/lib/db/spyReports';
|
|
import { getAllShips, getShipById } from '../../src/lib/db/ships';
|
|
import { getAllSectors, getSectorById } from '../../src/lib/db/sectors';
|
|
import { getAllResources, getResourceById } from '../../src/lib/db/resources';
|
|
import { getAllResearch, getResearchById } from '../../src/lib/db/research';
|
|
import { getAllPlanets, getPlanetById } from '../../src/lib/db/planets';
|
|
import { getMailById, getMailsByTo } from '../../src/lib/db/mails';
|
|
import { getAllGalaxies, getGalaxyById } from '../../src/lib/db/galaxies';
|
|
import { getAllFleet, getAllFleetByUser } from '../../src/lib/db/fleet';
|
|
import { getAllDefenses, getDefenseById } from '../../src/lib/db/defenses';
|
|
import { getAllBuildings, getBuildingById } from '../../src/lib/db/buildings';
|
|
import { getAccessToken } from '../../src/lib/db/accessTokens';
|
|
import { createHash } from 'crypto';
|
|
|
|
beforeEach(async () => {
|
|
await connect();
|
|
});
|
|
|
|
describe('db_users', () => {
|
|
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('getUserById', async () => {
|
|
const user = await getUserById(new ObjectId("653e9677e5c3d36b15ba74eb"));
|
|
expect(user).not.toBeNull();
|
|
expect(user?.username).toBe("gargamel");
|
|
expect(user?.email).toBe("gargamel@smerfy.pl");
|
|
});
|
|
});
|
|
|
|
describe('db_systems', () => {
|
|
test('getAllSystems', async () => {
|
|
const systems = await getAllSystems();
|
|
expect(systems).not.toBeNull();
|
|
expect(systems.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
test('getSystemById', async () => {
|
|
const system = await getSystemById(new ObjectId("66cf55650df1e5fe8a5c20d1"));
|
|
expect(system).not.toBeNull();
|
|
expect(system?.name).toBe("HelioNad");
|
|
});
|
|
});
|
|
|
|
describe('db_structures', () => {
|
|
test('getAllStructures', async () => {
|
|
const structures = await getAllStructures();
|
|
expect(structures).not.toBeNull();
|
|
expect(structures.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
test('getStructureById', async () => {
|
|
const structure = await getStructureById("dyson-sphere");
|
|
expect(structure).not.toBeNull();
|
|
});
|
|
});
|
|
|
|
describe('db_spyReports', () => {
|
|
test('getSpyReportById', async () => {
|
|
const spyReport = await getSpyReportById(new ObjectId("67aa16abb3cf8ee89d0f00d9"));
|
|
expect(spyReport).not.toBeNull();
|
|
expect(spyReport.victimId).toStrictEqual(new ObjectId("653e9677e5c3d36b15ba74eb"));
|
|
});
|
|
|
|
test('getSpyReportBySystemId', async () => {
|
|
const spyReport = await getSpyReportBySystemId(new ObjectId("66cf55650df1e5fe8a5c20d1"));
|
|
expect(spyReport).not.toBeNull();
|
|
expect(spyReport.victimId).toStrictEqual(new ObjectId("653e9677e5c3d36b15ba74eb"));
|
|
});
|
|
});
|
|
|
|
describe('db_ships', () => {
|
|
test('getAllShips', async () => {
|
|
const ships = await getAllShips();
|
|
expect(ships).not.toBeNull();
|
|
expect(ships.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
test('getShipById', async () => {
|
|
const ship = await getShipById("transporter");
|
|
expect(ship).not.toBeNull();
|
|
});
|
|
});
|
|
|
|
describe('db_sectors', () => {
|
|
test('getAllSectors', async () => {
|
|
const sectors = await getAllSectors();
|
|
expect(sectors).not.toBeNull();
|
|
expect(sectors.length).toBe(32);
|
|
});
|
|
|
|
test('getSectorById', async () => {
|
|
const sector = await getSectorById(new ObjectId("66cf55f20df1e5fe8a5c20d3"));
|
|
expect(sector).not.toBeNull();
|
|
expect(sector.name).toBe("Voidcaller Reach");
|
|
});
|
|
});
|
|
|
|
describe('db_resources', () => {
|
|
test('getAllResources', async () => {
|
|
const resources = await getAllResources();
|
|
expect(resources).not.toBeNull();
|
|
expect(resources.length).toBe(15);
|
|
});
|
|
|
|
test('getResourceById', async () => {
|
|
const resource = await getResourceById("coal");
|
|
expect(resource).not.toBeNull();
|
|
expect(resource.type).toBe("solid");
|
|
expect(resource.icon).toBe("/images/resources/coal.png");
|
|
});
|
|
});
|
|
|
|
describe('db_research', () => {
|
|
test('getAllResearch', async () => {
|
|
const research = await getAllResearch();
|
|
expect(research).not.toBeNull();
|
|
expect(research.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
test('getResearchById', async () => {
|
|
const research = await getResearchById("combat-utilities");
|
|
expect(research).not.toBeNull();
|
|
expect(research.onetime).not.toBeTruthy();
|
|
});
|
|
});
|
|
|
|
describe('db_planets', () => {
|
|
test('getAllPlanets', async () => {
|
|
const planets = await getAllPlanets();
|
|
expect(planets).not.toBeNull();
|
|
expect(planets.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
test('getPlanetById', async () => {
|
|
const planet = await getPlanetById(new ObjectId("661d1163567111a5b4be8829"));
|
|
expect(planet).not.toBeNull();
|
|
expect(planet.name).toBe("Lyoko");
|
|
expect(planet.owner).toStrictEqual(new ObjectId("653e9677e5c3d36b15ba74eb"));
|
|
});
|
|
});
|
|
|
|
describe('db_mails', () => {
|
|
test('getMailById', async () => {
|
|
const mail = await getMailById(new ObjectId("673f16a8e140c989f59f54c3"));
|
|
expect(mail).not.toBeNull();
|
|
expect(mail.from).toStrictEqual(new ObjectId("65401221e5c3d36b15ba74ed"));
|
|
expect(mail.to).toStrictEqual(new ObjectId("653e9677e5c3d36b15ba74eb"));
|
|
expect(mail.subject).toBe("Shrek is love, Shrek is life");
|
|
});
|
|
|
|
test('getMailsByTo', async () => {
|
|
const mails = await getMailsByTo(new ObjectId("653e9677e5c3d36b15ba74eb"));
|
|
expect(mails).not.toBeNull();
|
|
expect(mails.length).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
|
|
describe('db_galaxies', () => {
|
|
test('getAllGalaxies', async () => {
|
|
const galaxies = await getAllGalaxies();
|
|
expect(galaxies).not.toBeNull();
|
|
expect(galaxies.length).toBe(4);
|
|
});
|
|
|
|
test('getGalaxyById', async () => {
|
|
const galaxy = await getGalaxyById(new ObjectId("66cf553a0df1e5fe8a5c20cc"));
|
|
expect(galaxy).not.toBeNull();
|
|
expect(galaxy.name).toBe("Luminara");
|
|
});
|
|
});
|
|
|
|
describe('db_fleet', () => {
|
|
test('getAllFleet', async () => {
|
|
const fleet = await getAllFleet();
|
|
expect(fleet).not.toBeNull();
|
|
expect(fleet.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
test('getAllFleetByUser', async () => {
|
|
const fleet = await getAllFleetByUser(new ObjectId("653e9677e5c3d36b15ba74eb"));
|
|
expect(fleet).not.toBeNull();
|
|
expect(fleet.length).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
|
|
describe('db_defenses', () => {
|
|
test('getAllDefenses', async () => {
|
|
const defenses = await getAllDefenses();
|
|
expect(defenses).not.toBeNull();
|
|
expect(defenses.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
test('getDefenseById', async () => {
|
|
const defense = await getDefenseById("laser-turret");
|
|
expect(defense).not.toBeNull();
|
|
});
|
|
});
|
|
|
|
describe('db_buildings', () => {
|
|
test('getAllBuildings', async () => {
|
|
const buildings = await getAllBuildings();
|
|
expect(buildings).not.toBeNull();
|
|
expect(buildings.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
test('getBuildingById', async () => {
|
|
const building = await getBuildingById("iron-mine");
|
|
expect(building).not.toBeNull();
|
|
expect(building.category).toBe("mines");
|
|
});
|
|
});
|
|
|
|
describe('db_accessTokens', () => {
|
|
test('getAccessToken', async () => {
|
|
const rawToken = "A.MTczOTY1ODI1NTA5MA.NjUzZTk2NzdlNWMzZDM2YjE1YmE3NGVi.hQW5wy0J1siFhTYvdU5GJw";
|
|
const token = await getAccessToken(rawToken);
|
|
expect(token).not.toBeNull();
|
|
expect(token?.type).toBe("A");
|
|
expect(token?.user).toStrictEqual(new ObjectId("653e9677e5c3d36b15ba74eb"));
|
|
expect(token?.createdFrom).toBe("loginForm");
|
|
const random = rawToken.split(".")[3];
|
|
const hash = createHash("sha256").update(random).digest("hex");
|
|
expect(token?.entropy).toBe(hash);
|
|
});
|
|
}); |