Improvements to tests and from testing
- Moved OP25 start outside of PDAB start callback - Added more logging - Set the pdabProcess variable to false when closing the discord client - Update test variable names - Added new WIP pdabWrappers tests to test the full wrappers as the client would
This commit is contained in:
@@ -120,6 +120,7 @@ export const requestDiscordID = () => {
|
|||||||
export const requestDiscordClientClose = () => {
|
export const requestDiscordClientClose = () => {
|
||||||
return new Promise((res) => {
|
return new Promise((res) => {
|
||||||
io.timeout(25000).emit('request_client_close');
|
io.timeout(25000).emit('request_client_close');
|
||||||
|
pdabProcess = false;
|
||||||
res();
|
res();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -8,16 +8,22 @@ let activeDiscordClient = undefined;
|
|||||||
* @param {object} joinData The object containing all the information to join the server
|
* @param {object} joinData The object containing all the information to join the server
|
||||||
*/
|
*/
|
||||||
export const joinDiscordVC = async (joinData) => {
|
export const joinDiscordVC = async (joinData) => {
|
||||||
console.log("Join requested: ", joinData)
|
console.log("Join requested: ", joinData);
|
||||||
const connection = await new Promise(async (res) => {
|
const connection = await new Promise(async (res) => {
|
||||||
// Check if a client already exists
|
// Check if a client already exists
|
||||||
|
console.log("Checking if there is a client open");
|
||||||
if (!await checkIfClientIsOpen()) {
|
if (!await checkIfClientIsOpen()) {
|
||||||
|
console.log("There is no open client, starting it now");
|
||||||
|
// Open an instance of OP25
|
||||||
|
console.log("Starting OP25")
|
||||||
|
openOP25(joinData.system);
|
||||||
|
|
||||||
// Open a new client and join the requested channel with the requested ID
|
// Open a new client and join the requested channel with the requested ID
|
||||||
initDiscordBotClient(joinData.clientID, () => {
|
initDiscordBotClient(joinData.clientID, () => {
|
||||||
// Open an instance of OP25
|
console.log("Started PDAB")
|
||||||
openOP25(joinData.system);
|
|
||||||
|
|
||||||
// Add the client object to the IO instance
|
// Add the client object to the IO instance
|
||||||
|
console.log("Connecting to channel")
|
||||||
connectToChannel(joinData.channelID, (connectionStatus) => {
|
connectToChannel(joinData.channelID, (connectionStatus) => {
|
||||||
console.log("Bot Connected to VC:", connectionStatus);
|
console.log("Bot Connected to VC:", connectionStatus);
|
||||||
res(connectionStatus);
|
res(connectionStatus);
|
||||||
@@ -25,7 +31,9 @@ export const joinDiscordVC = async (joinData) => {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Join the requested channel with the requested ID
|
// Join the requested channel with the requested ID
|
||||||
// Add the client object to the IO instance
|
console.log("There is an open client");
|
||||||
|
|
||||||
|
console.log("Connecting to channel")
|
||||||
const connection = connectToChannel(joinData.channelID);
|
const connection = connectToChannel(joinData.channelID);
|
||||||
console.log("Bot Connected to VC::");
|
console.log("Bot Connected to VC::");
|
||||||
res(connection);
|
res(connection);
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
// Import necessary modules for testing
|
// Import necessary modules for testing
|
||||||
import { use, expect } from 'chai'
|
import { expect } from 'chai'
|
||||||
import chaiHttp from 'chai-http'
|
|
||||||
const chai = use(chaiHttp)
|
|
||||||
|
|
||||||
import io from 'socket.io-client';
|
import io from 'socket.io-client';
|
||||||
const ioClient = io;
|
const ioClient = io;
|
||||||
|
|
||||||
@@ -35,7 +32,7 @@ describe('Socket Server Tests', done => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Should open a socket server and callback when the client is connected and ready', done => {
|
it('Should open a socket server and callback when the client is connected and ready', done => {
|
||||||
const clientId = process.env.DISCORD_CLIENT_ID;
|
const clientId = process.env.TEST_CLIENT_TOKEN;
|
||||||
|
|
||||||
const callback = () => {
|
const callback = () => {
|
||||||
done();
|
done();
|
||||||
@@ -130,19 +127,9 @@ describe('Socket Server Tests', done => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Socket Client & Python IPC Tests', done => {
|
describe('Socket Client & Python IPC Tests', done => {
|
||||||
after(async () => {
|
|
||||||
// Any teardown needed after tests
|
|
||||||
try {
|
|
||||||
await socket.close();
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
console.log("Socket already closed");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should open a socket server and callback when the client is connected and ready', done => {
|
it('Should open a socket server and callback when the client is connected and ready', done => {
|
||||||
let clientConnected = false;
|
let clientConnected = false;
|
||||||
const clientId = process.env.DISCORD_CLIENT_ID;
|
const clientId = process.env.TEST_CLIENT_TOKEN;
|
||||||
|
|
||||||
const callback = () => {
|
const callback = () => {
|
||||||
clientConnected = true;
|
clientConnected = true;
|
||||||
@@ -165,13 +152,6 @@ describe('Socket Client & Python IPC Tests', done => {
|
|||||||
expect(status).to.be.true;
|
expect(status).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should have opened OP25', async () => {
|
|
||||||
// Assuming your server is running on localhost:8081
|
|
||||||
const res = await chai.request('http://localhost:8081').get('/');
|
|
||||||
expect(res).to.have.status(200); // Assuming 200 is the expected status code
|
|
||||||
// Add more assertions if needed
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should emit command for and return status if connected to voice channel', async () => {
|
it('Should emit command for and return status if connected to voice channel', async () => {
|
||||||
// Simulate emitting 'check_discord_vc_connected' event
|
// Simulate emitting 'check_discord_vc_connected' event
|
||||||
const isConnected = await checkIfConnectedToVC(process.env.TEST_GUILD_ID);
|
const isConnected = await checkIfConnectedToVC(process.env.TEST_GUILD_ID);
|
||||||
|
|||||||
40
client/test/pdabWrappers.test.js.bak
Normal file
40
client/test/pdabWrappers.test.js.bak
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import { use } from 'chai';
|
||||||
|
import chaiHttp from 'chai-http';
|
||||||
|
const chai = use(chaiHttp)
|
||||||
|
chai.should();
|
||||||
|
|
||||||
|
import dotenv from 'dotenv';
|
||||||
|
dotenv.config()
|
||||||
|
|
||||||
|
import { joinDiscordVC, leaveDiscordVC } from '../discordAudioBot/pdabWrappers.mjs'
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
// Any setup needed before tests
|
||||||
|
});
|
||||||
|
|
||||||
|
after(async () => {
|
||||||
|
// Any teardown needed after tests
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('PDAB Wrapper Tests', () => {
|
||||||
|
it('Should open the discord bot, and join the first server when requested', async () => {
|
||||||
|
// Test case
|
||||||
|
const joinData = {
|
||||||
|
channelID: process.env.TEST_CHANNEL_ID,
|
||||||
|
clientID: process.env.TEST_CLIENT_TOKEN,
|
||||||
|
system: process.env.TEST_SYSTEM,
|
||||||
|
};
|
||||||
|
const connection = await joinDiscordVC(joinData);
|
||||||
|
console.log("Connection:", connection);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should open OP25', async () => {
|
||||||
|
const res = await chai.request('http://localhost:8081').get('/');
|
||||||
|
expect(res).to.have.status(200); // Assuming 200 is the expected status code
|
||||||
|
// Add more assertions if needed
|
||||||
|
})
|
||||||
|
|
||||||
|
it("Should disconnect from the discord server", async () => {
|
||||||
|
await leaveDiscordVC(process.env.TEST_GUILD_ID);
|
||||||
|
})
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user