Passing local server tests
Some checks failed
Run Socket Server Tests / test (push) Failing after 30s
Some checks failed
Run Socket Server Tests / test (push) Failing after 30s
This commit is contained in:
@@ -17,15 +17,19 @@ app.get('/', (req, res) => {
|
|||||||
nodeIo.on('connection', (socket) => {
|
nodeIo.on('connection', (socket) => {
|
||||||
console.log('a user connected', socket.id);
|
console.log('a user connected', socket.id);
|
||||||
|
|
||||||
socket.on('node-login', (data) => {
|
socket.on('node-login', async (data) => {
|
||||||
nodeLoginWrapper(data, socket);
|
await nodeLoginWrapper(data, socket);
|
||||||
socket.emit('node-login-successful');
|
await socket.emit('node-login-successful');
|
||||||
})
|
})
|
||||||
|
|
||||||
socket.on('node-update', (data) => {
|
socket.on('node-update', async (data) => {
|
||||||
nodeUpdateWrapper(data.node);
|
let tempPromises = [];
|
||||||
nearbySystemsUpdateWraper(data.node.nuid, data.nearbySystems)
|
tempPromises.push(nodeUpdateWrapper(data.node));
|
||||||
socket.emit('node-update-successful')
|
tempPromises.push(nearbySystemsUpdateWraper(data.node.nuid, data.nearbySystems));
|
||||||
|
|
||||||
|
await Promise.all(tempPromises);
|
||||||
|
|
||||||
|
await socket.emit('node-update-successful')
|
||||||
})
|
})
|
||||||
|
|
||||||
socket.on('disconnect', () => {
|
socket.on('disconnect', () => {
|
||||||
|
|||||||
@@ -28,11 +28,14 @@ export const nodeLoginWrapper = async (data, socket) => {
|
|||||||
console.log("After grabbing", node);
|
console.log("After grabbing", node);
|
||||||
if (!node) {
|
if (!node) {
|
||||||
const insertedId = await createNode(data);
|
const insertedId = await createNode(data);
|
||||||
node = await getNodeByNuid(data.nuid);
|
|
||||||
console.log("Added new node to the database:", insertedId);
|
console.log("Added new node to the database:", insertedId);
|
||||||
|
} else {
|
||||||
|
// Check for updates
|
||||||
|
const updatedNode = await updateNodeByNuid(data.nuid, data)
|
||||||
|
console.log("Updated node:", updatedNode);
|
||||||
}
|
}
|
||||||
// Check for updates if so
|
|
||||||
// Check for System updates
|
node = await getNodeByNuid(data.nuid);
|
||||||
|
|
||||||
// Add the socket/node connection
|
// Add the socket/node connection
|
||||||
socket.node = node;
|
socket.node = node;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { expect } from 'chai';
|
|||||||
import ioClient from 'socket.io-client';
|
import ioClient from 'socket.io-client';
|
||||||
import { app, nodeIo, server } from '../modules/socketServer.mjs';
|
import { app, nodeIo, server } from '../modules/socketServer.mjs';
|
||||||
import { getNodeByNuid, deleteNodeByNuid } from '../modules/mongoNodesWrappers.mjs';
|
import { getNodeByNuid, deleteNodeByNuid } from '../modules/mongoNodesWrappers.mjs';
|
||||||
|
import { deleteSystemByName, getSystemByName } from '../modules/mongoSystemsWrappers.mjs';
|
||||||
import { logIntoServerWrapper } from '../../client/modules/socketClientWrappers.mjs';
|
import { logIntoServerWrapper } from '../../client/modules/socketClientWrappers.mjs';
|
||||||
|
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
@@ -10,6 +11,52 @@ dotenv.config()
|
|||||||
|
|
||||||
process.env.SERVER_PORT = 6000
|
process.env.SERVER_PORT = 6000
|
||||||
|
|
||||||
|
// Define necessary variables for testing, such as mocked database connections or socket instances
|
||||||
|
const localNodeConfig = {
|
||||||
|
serverIp: 'localhost',
|
||||||
|
serverPort: process.env.SERVER_PORT,
|
||||||
|
node: {
|
||||||
|
nuid: "4f29a6340901a12affc87047c0ac16b01b92496c460c880a2459abe8c7928374",
|
||||||
|
name: "testyv7",
|
||||||
|
location: "china",
|
||||||
|
capabilities: ["radio"]
|
||||||
|
},
|
||||||
|
nearbySystems: {
|
||||||
|
"Testing P25 System Name": {
|
||||||
|
"frequencies": [
|
||||||
|
155344000,
|
||||||
|
155444000,
|
||||||
|
155555000,
|
||||||
|
155588550
|
||||||
|
],
|
||||||
|
"mode": "p25",
|
||||||
|
"trunkFile": "trunk.tsv",
|
||||||
|
"whitelistFile": "whitelist.tsv"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const updatedLocalNodeConfig = {
|
||||||
|
node: {
|
||||||
|
nuid: localNodeConfig.node.nuid,
|
||||||
|
name: "updatedName",
|
||||||
|
location: "updatedLocation",
|
||||||
|
capabilities: ["radio", "weather"] // Updated capabilities
|
||||||
|
},
|
||||||
|
nearbySystems: {
|
||||||
|
"Testing P25 System Name": {
|
||||||
|
"frequencies": [
|
||||||
|
155444000,
|
||||||
|
155555000,
|
||||||
|
155500000
|
||||||
|
],
|
||||||
|
"mode": "p25",
|
||||||
|
"trunkFile": "trunk2.tsv",
|
||||||
|
"whitelistFile": "whitelist2.tsv"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Start the Socket.IO server before running tests
|
// Start the Socket.IO server before running tests
|
||||||
let clientSocket; // The socket client
|
let clientSocket; // The socket client
|
||||||
let serverClientSocket // The open client socket on the server
|
let serverClientSocket // The open client socket on the server
|
||||||
@@ -36,36 +83,12 @@ after(async () => {
|
|||||||
// Close the server
|
// Close the server
|
||||||
nodeIo.close();
|
nodeIo.close();
|
||||||
|
|
||||||
// Remove the test user
|
// Remove the test data
|
||||||
deleteNodeByNuid("4f29a6340901a12affc87047c0ac16b01b92496c460c880a2459abe8c7928595")
|
deleteNodeByNuid(localNodeConfig.node.nuid); // Delete the user
|
||||||
|
deleteSystemByName(Object.keys(localNodeConfig.nearbySystems)[0])
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Node Core Server Tests', () => {
|
describe('Node Core Server Tests', () => {
|
||||||
// Define necessary variables for testing, such as mocked database connections or socket instances
|
|
||||||
const localNodeConfig = {
|
|
||||||
serverIp: 'localhost',
|
|
||||||
serverPort: process.env.SERVER_PORT,
|
|
||||||
node: {
|
|
||||||
nuid: "4f29a6340901a12affc87047c0ac16b01b92496c460c880a2459abe8c7928595",
|
|
||||||
name: "testyv3",
|
|
||||||
location: "georgia",
|
|
||||||
capabilities: ["radio"]
|
|
||||||
},
|
|
||||||
nearbySystems: {
|
|
||||||
"Default P25 System Name": {
|
|
||||||
"frequencies": [
|
|
||||||
155344000,
|
|
||||||
155444000,
|
|
||||||
155555000,
|
|
||||||
155588550
|
|
||||||
],
|
|
||||||
"mode": "p25",
|
|
||||||
"trunkFile": "trunk.tsv",
|
|
||||||
"whitelistFile": "whitelist.tsv"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Test Node Login functionality
|
// Test Node Login functionality
|
||||||
describe('Node Login', () => {
|
describe('Node Login', () => {
|
||||||
it('should add a new node if it does not exist', async () => {
|
it('should add a new node if it does not exist', async () => {
|
||||||
@@ -102,12 +125,12 @@ describe('Node Core Server Tests', () => {
|
|||||||
expect(addedNode).to.have.property('location', localNodeConfig.node.location);
|
expect(addedNode).to.have.property('location', localNodeConfig.node.location);
|
||||||
expect(addedNode).to.have.deep.property('capabilities', localNodeConfig.node.capabilities);
|
expect(addedNode).to.have.deep.property('capabilities', localNodeConfig.node.capabilities);
|
||||||
})
|
})
|
||||||
it('should update a new node if it exists', async () => {
|
it('should update a node if it exists', async () => {
|
||||||
// Simulate a node login request
|
// Simulate a node login request
|
||||||
// Use the getNodeByNuid mock function to simulate checking if node exists
|
// Use the getNodeByNuid mock function to simulate checking if node exists
|
||||||
const existingNode = await getNodeByNuid(localNodeConfig.node.nuid);
|
const existingNode = await getNodeByNuid(localNodeConfig.node.nuid);
|
||||||
|
|
||||||
// Assert that existingNode is null before node login
|
// Assert that existingNode is matches the existing data before logging in
|
||||||
expect(existingNode).to.have.property('_id'); // Check if _id property exists
|
expect(existingNode).to.have.property('_id'); // Check if _id property exists
|
||||||
expect(existingNode).to.have.property('nuid', localNodeConfig.node.nuid);
|
expect(existingNode).to.have.property('nuid', localNodeConfig.node.nuid);
|
||||||
expect(existingNode).to.have.property('name', localNodeConfig.node.name);
|
expect(existingNode).to.have.property('name', localNodeConfig.node.name);
|
||||||
@@ -121,17 +144,8 @@ describe('Node Core Server Tests', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const updatedNodeConfig = {
|
|
||||||
node: {
|
|
||||||
nuid: localNodeConfig.node.nuid,
|
|
||||||
name: "updatedName",
|
|
||||||
location: "updatedLocation",
|
|
||||||
capabilities: ["radio", "weather"] // Updated capabilities
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Emit the login command
|
// Emit the login command
|
||||||
clientSocket.emit("node-login", updatedNodeConfig.node);
|
clientSocket.emit("node-login", updatedLocalNodeConfig.node);
|
||||||
|
|
||||||
// Wait for the successful login event
|
// Wait for the successful login event
|
||||||
await node_login;
|
await node_login;
|
||||||
@@ -144,50 +158,48 @@ describe('Node Core Server Tests', () => {
|
|||||||
|
|
||||||
// Assert that the node is added correctly
|
// Assert that the node is added correctly
|
||||||
expect(updatedNode).to.have.property('_id'); // Check if _id property exists
|
expect(updatedNode).to.have.property('_id'); // Check if _id property exists
|
||||||
expect(updatedNode).to.have.property('nuid', updatedNodeConfig.node.nuid);
|
expect(updatedNode).to.have.property('nuid', updatedLocalNodeConfig.node.nuid);
|
||||||
expect(updatedNode).to.have.property('name', updatedNodeConfig.node.name);
|
expect(updatedNode).to.have.property('name', updatedLocalNodeConfig.node.name);
|
||||||
expect(updatedNode).to.have.property('location', updatedNodeConfig.node.location);
|
expect(updatedNode).to.have.property('location', updatedLocalNodeConfig.node.location);
|
||||||
expect(updatedNode).to.have.deep.property('capabilities', updatedNodeConfig.node.capabilities);
|
expect(updatedNode).to.have.deep.property('capabilities', updatedLocalNodeConfig.node.capabilities);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
// Test Node Update functionality
|
// Test Node Update functionality
|
||||||
describe('Node Update', () => {
|
describe('Node Update', () => {
|
||||||
it('should update a new node if it exists', async () => {
|
it('should add a node\'s nearby systems', async () => {
|
||||||
// Simulate a node login request
|
// Simulate an update request sent from the client to the server
|
||||||
// Use the getNodeByNuid mock function to simulate checking if node exists
|
|
||||||
|
// Get the existing node in the database
|
||||||
const existingNode = await getNodeByNuid(localNodeConfig.node.nuid);
|
const existingNode = await getNodeByNuid(localNodeConfig.node.nuid);
|
||||||
|
|
||||||
// Assert that existingNode is null before node login
|
// Assert that existingNode matches the updatedLocalNodeConfig
|
||||||
expect(existingNode).to.have.property('_id'); // Check if _id property exists
|
expect(existingNode).to.have.property('_id'); // Check if _id property exists
|
||||||
expect(existingNode).to.have.property('nuid', localNodeConfig.node.nuid);
|
expect(existingNode).to.have.property('nuid', updatedLocalNodeConfig.node.nuid);
|
||||||
expect(existingNode).to.have.property('name', localNodeConfig.node.name);
|
expect(existingNode).to.have.property('name', updatedLocalNodeConfig.node.name);
|
||||||
expect(existingNode).to.have.property('location', localNodeConfig.node.location);
|
expect(existingNode).to.have.property('location', updatedLocalNodeConfig.node.location);
|
||||||
expect(existingNode).to.have.deep.property('capabilities', localNodeConfig.node.capabilities);
|
expect(existingNode).to.have.deep.property('capabilities', updatedLocalNodeConfig.node.capabilities);
|
||||||
|
|
||||||
|
// Get the system from the DB
|
||||||
|
const existsingSystem = await getSystemByName("Testing P25 System Name");
|
||||||
|
|
||||||
|
// Assert that there is no existing system in the DB
|
||||||
|
expect(existsingSystem).to.be.null;
|
||||||
|
|
||||||
// Wait for the update
|
// Wait for the update
|
||||||
const node_login = new Promise(res => {
|
const node_system_update = new Promise(res => {
|
||||||
clientSocket.on('node-update-successful', async () => {
|
clientSocket.on('node-update-successful', async () => {
|
||||||
res();
|
res();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const updatedNodeConfig = {
|
// Emit the update command
|
||||||
node: {
|
clientSocket.emit("node-update", updatedLocalNodeConfig);
|
||||||
nuid: localNodeConfig.node.nuid,
|
|
||||||
name: "updatedName",
|
|
||||||
location: "updatedLocation",
|
|
||||||
capabilities: ["radio", "weather"] // Updated capabilities
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Emit the login command
|
// Wait for the successful update event
|
||||||
clientSocket.emit("node-update", updatedNodeConfig.node);
|
await node_system_update;
|
||||||
|
|
||||||
// Wait for the successful login event
|
// Now we need to check if the system is added to the database
|
||||||
await node_login;
|
|
||||||
|
|
||||||
// Now we need to check if the node is added to the database
|
|
||||||
// We can use getNodeByNuid again to verify if the node was added correctly
|
// We can use getNodeByNuid again to verify if the node was added correctly
|
||||||
const updatedNode = await getNodeByNuid(localNodeConfig.node.nuid);
|
const updatedNode = await getNodeByNuid(localNodeConfig.node.nuid);
|
||||||
|
|
||||||
@@ -195,10 +207,78 @@ describe('Node Core Server Tests', () => {
|
|||||||
|
|
||||||
// Assert that the node is added correctly
|
// Assert that the node is added correctly
|
||||||
expect(updatedNode).to.have.property('_id'); // Check if _id property exists
|
expect(updatedNode).to.have.property('_id'); // Check if _id property exists
|
||||||
expect(updatedNode).to.have.property('nuid', updatedNodeConfig.node.nuid);
|
expect(updatedNode).to.have.property('nuid', updatedLocalNodeConfig.node.nuid);
|
||||||
expect(updatedNode).to.have.property('name', updatedNodeConfig.node.name);
|
expect(updatedNode).to.have.property('name', updatedLocalNodeConfig.node.name);
|
||||||
expect(updatedNode).to.have.property('location', updatedNodeConfig.node.location);
|
expect(updatedNode).to.have.property('location', updatedLocalNodeConfig.node.location);
|
||||||
expect(updatedNode).to.have.deep.property('capabilities', updatedNodeConfig.node.capabilities);
|
expect(updatedNode).to.have.deep.property('capabilities', updatedLocalNodeConfig.node.capabilities);
|
||||||
|
|
||||||
|
// Get the updated system
|
||||||
|
const addedSystem = await getSystemByName("Testing P25 System Name");
|
||||||
|
|
||||||
|
console.log("Added system:", addedSystem);
|
||||||
|
|
||||||
|
expect(addedSystem).to.have.property('_id'); // Check if _id property exists
|
||||||
|
expect(addedSystem).to.have.property('nodes'); // Check if nodes property exists
|
||||||
|
expect(addedSystem.nodes).to.include(updatedLocalNodeConfig.node.nuid) // Check if this node ID is in the nodes array
|
||||||
|
expect(addedSystem).to.have.deep.property('frequencies', updatedLocalNodeConfig.nearbySystems['Testing P25 System Name'].frequencies);
|
||||||
|
expect(addedSystem).to.have.property('mode', updatedLocalNodeConfig.nearbySystems['Testing P25 System Name'].mode);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should update a node and its nearby systems', async () => {
|
||||||
|
// Get the existing node in the database
|
||||||
|
const existingNode = await getNodeByNuid(localNodeConfig.node.nuid);
|
||||||
|
|
||||||
|
// Assert that existingNode matches the updatedLocalNodeConfig
|
||||||
|
expect(existingNode).to.have.property('_id'); // Check if _id property exists
|
||||||
|
expect(existingNode).to.have.property('nuid', updatedLocalNodeConfig.node.nuid);
|
||||||
|
expect(existingNode).to.have.property('name', updatedLocalNodeConfig.node.name);
|
||||||
|
expect(existingNode).to.have.property('location', updatedLocalNodeConfig.node.location);
|
||||||
|
expect(existingNode).to.have.deep.property('capabilities', updatedLocalNodeConfig.node.capabilities);
|
||||||
|
|
||||||
|
// Get the updated system
|
||||||
|
const existingSystem = await getSystemByName("Testing P25 System Name");
|
||||||
|
expect(existingSystem).to.have.property('_id'); // Check if _id property exists
|
||||||
|
expect(existingSystem).to.have.property('nodes'); // Check if nodes property exists
|
||||||
|
expect(existingSystem.nodes).to.include(updatedLocalNodeConfig.node.nuid) // Check if this node ID is in the nodes array
|
||||||
|
expect(existingSystem).to.have.deep.property('frequencies', updatedLocalNodeConfig.nearbySystems['Testing P25 System Name'].frequencies);
|
||||||
|
expect(existingSystem).to.have.property('mode', updatedLocalNodeConfig.nearbySystems['Testing P25 System Name'].mode);
|
||||||
|
|
||||||
|
|
||||||
|
// Wait for the update
|
||||||
|
const node_update = new Promise(res => {
|
||||||
|
clientSocket.on('node-update-successful', async () => {
|
||||||
|
res();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Emit the update command
|
||||||
|
clientSocket.emit("node-update", localNodeConfig);
|
||||||
|
|
||||||
|
// Wait for the successful update event
|
||||||
|
await node_update;
|
||||||
|
|
||||||
|
const updatedNode = await getNodeByNuid(localNodeConfig.node.nuid);
|
||||||
|
|
||||||
|
console.log("Updated Node:", updatedNode);
|
||||||
|
|
||||||
|
// Assert that the node is added correctly
|
||||||
|
expect(updatedNode).to.have.property('_id'); // Check if _id property exists
|
||||||
|
expect(updatedNode).to.have.property('nuid', localNodeConfig.node.nuid);
|
||||||
|
expect(updatedNode).to.have.property('name', localNodeConfig.node.name);
|
||||||
|
expect(updatedNode).to.have.property('location', localNodeConfig.node.location);
|
||||||
|
expect(updatedNode).to.have.deep.property('capabilities', localNodeConfig.node.capabilities);
|
||||||
|
|
||||||
|
// Get the updated system
|
||||||
|
const updatedSystem = await getSystemByName("Testing P25 System Name");
|
||||||
|
|
||||||
|
console.log("Updated system:", updatedSystem);
|
||||||
|
|
||||||
|
expect(updatedSystem).to.have.property('_id'); // Check if _id property exists
|
||||||
|
expect(updatedSystem).to.have.property('nodes'); // Check if nodes property exists
|
||||||
|
expect(updatedSystem.nodes).include(localNodeConfig.node.nuid) // Check if this node ID is in the nodes array
|
||||||
|
expect(updatedSystem).to.have.deep.property('frequencies', localNodeConfig.nearbySystems['Testing P25 System Name'].frequencies);
|
||||||
|
expect(updatedSystem).to.have.property('mode', localNodeConfig.nearbySystems['Testing P25 System Name'].mode);
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -209,13 +289,3 @@ describe('Node Core Server Tests', () => {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Node Systems Server Tests', () => {
|
|
||||||
// Test Nearby Systems Update functionality
|
|
||||||
describe('Nearby Systems Update', () => {
|
|
||||||
it('should update nearby systems correctly', async () => {
|
|
||||||
// Write test code to simulate nearby systems update
|
|
||||||
// Check if systems are added, updated, or removed appropriately based on the provided data
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user