From be5943e9d4e978d29e7edd023470804ec106203c Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Wed, 3 Apr 2024 02:20:30 -0400 Subject: [PATCH] Adding basic tests --- .gitea/workflows/server_tests.yaml | 26 ++++++++ server/tests/socketServerWrappers.test.js | 76 +++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 .gitea/workflows/server_tests.yaml create mode 100644 server/tests/socketServerWrappers.test.js diff --git a/.gitea/workflows/server_tests.yaml b/.gitea/workflows/server_tests.yaml new file mode 100644 index 0000000..8e6be81 --- /dev/null +++ b/.gitea/workflows/server_tests.yaml @@ -0,0 +1,26 @@ +name: Run Socket Server Tests + +on: + push: + branches: + - all + # You can adjust the branches as needed + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' + + - name: Install dependencies + run: npm install + + - name: Run tests + run: npm test \ No newline at end of file diff --git a/server/tests/socketServerWrappers.test.js b/server/tests/socketServerWrappers.test.js new file mode 100644 index 0000000..7272b49 --- /dev/null +++ b/server/tests/socketServerWrappers.test.js @@ -0,0 +1,76 @@ +import { expect } from 'chai'; +import { createNode, getNodeByNuid, updateNodeByNuid } from '../modules/mongoNodesWrappers'; // Import necessary functions from your wrappers +import { nodeLoginWrapper, nodeUpdateWrapper, nearbySystemsUpdateWraper } from '../modules/socketServerWrappers'; // Import the functions you want to test +import { ClientNodeObject, ClientNodeConfig } from '../../client/modules/clientObjectDefinitions.mjs'; // Import the objects definitions + +describe('Socket Server Wrappers', function() { + describe('nodeLoginWrapper', function() { + it('should create a new node if it does not exist', async function() { + const socket = { + node: undefined, // Initialize a socket with no node + id: 'mockSocketId' // Mock socket id + }; + + // Mock data using ClientNodeConfig object + const config = new ClientNodeConfig({ + _nuid: 'mockNuid', + _name: 'mockName', + _location: 'mockLocation', + _capabilities: { /* mock capabilities */ } + }); + + await nodeLoginWrapper(config, socket); + + // Check if the node was created + const createdNode = await getNodeByNuid('mockNuid'); + expect(createdNode).to.exist; + }); + + // Add more test cases as needed + }); + + describe('nodeUpdateWrapper', function() { + it('should update the node data in the database', async function() { + // Mock node data using ClientNodeObject + const nodeData = new ClientNodeObject({ + _nuid: 'mockNuid', + _name: 'mockName', + _location: 'mockLocation', + _capabilities: { /* mock capabilities */ } + }); + + await nodeUpdateWrapper(nodeData); + + // Check if the node was updated in the database + const updatedNode = await getNodeByNuid('mockNuid'); + // Assert that the node has been updated with the new data + expect(updatedNode).to.deep.include({ + nuid: 'mockNuid', + name: 'mockName', + location: 'mockLocation', + capabilities: { /* mock capabilities */ } + }); + }); + + // Add more test cases as needed + }); + + describe('nearbySystemsUpdateWraper', function() { + it('should update nearby systems in the database', async function() { + // Mock nearby systems data + const nearbySystems = { + // Mock nearby systems data + }; + const nuid = 'mockNuid'; // Mock nuid + + await nearbySystemsUpdateWraper(nuid, nearbySystems); + + // Perform assertions to ensure nearby systems are updated correctly + // You may need to check the database for updated nearby systems + }); + + // Add more test cases as needed + }); + + // Add more describe blocks for other functions and their respective test cases +});