Adding basic tests

This commit is contained in:
Logan Cusano
2024-04-03 02:20:30 -04:00
parent 64edc612df
commit be5943e9d4
2 changed files with 102 additions and 0 deletions

View File

@@ -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

View File

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