Update PDAB tests
Some checks failed
DRB Build Tests / drb_build_and_test (push) Failing after 58s

- These new tests will likely not run in actions due to pyaudio
This commit is contained in:
Logan Cusano
2024-04-27 23:34:30 -04:00
parent e7229322e4
commit 6cae18e70c
3 changed files with 342 additions and 22 deletions

View File

@@ -1,6 +1,10 @@
// Import necessary modules for testing
import { expect } from 'chai';
import { use, expect } from 'chai'
import chaiHttp from 'chai-http'
const chai = use(chaiHttp)
import io from 'socket.io-client';
const ioClient = io;
import dotenv from 'dotenv';
dotenv.config()
@@ -15,32 +19,31 @@ before(async done => {
});
after(async () => {
// Any teardown needed after tests
try{
await socket.close();
}
catch {
console.log("Socket already closed");
}
console.log('Closing PDAB Socker Server');
await closePdabSocketServer();
});
})
describe('Socket Server Tests', done => {
after(async () => {
// Any teardown needed after tests
try {
await socket.close();
}
catch {
console.log("Socket already closed");
}
console.log('Closing PDAB Socker Server');
});
describe('Python Discord Bot Socket IPC Tests', done => {
it('Should open a socket server and callback when the client is connected and ready', done => {
let clientConnected = false;
const clientId = process.env.DISCORD_CLIENT_ID;
const callback = () => {
clientConnected = true;
expect(clientConnected).to.be.true;
done();
};
initDiscordBotClient(clientId, callback);
initDiscordBotClient(clientId, callback, false);
socket = io.connect(`http://localhost:${process.env.PDAB_PORT}`);
socket = ioClient.connect(`http://localhost:${process.env.PDAB_PORT}`);
socket.on('connect', () => {
socket.emit('discord_ready')
@@ -69,7 +72,7 @@ describe('Python Discord Bot Socket IPC Tests', done => {
expect(data).to.deep.equal({ guildId: process.env.TEST_GUILD_ID });
callback(false, false);
});
// Simulate emitting 'leave_server' event
const openStatus = await leaveVoiceChannel(process.env.TEST_GUILD_ID);
@@ -95,19 +98,19 @@ describe('Python Discord Bot Socket IPC Tests', done => {
socket.on('request_discord_username', (data, callback) => {
console.log('Username Check data:', data);
expect(data).to.deep.equal({ guildId: process.env.TEST_GUILD_ID });
callback('!bot-username');
callback(process.env.EXPECTED_USERNAME);
});
// Simulate emitting 'request_discord_username' event
const username = await requestDiscordUsername(process.env.TEST_GUILD_ID);
// Assert the username returned from the server
expect(username).to.equal("!bot-username");
expect(username).to.equal(process.env.EXPECTED_USERNAME);
});
it('Should emit command for and return discord client ID', async () => {
socket.on('request_discord_id', (callback) => {
callback(process.env.EXPECTED_CLIENT_ID);
});
});
// Simulate emitting 'request_discord_id' event
const clientId = await requestDiscordID();
@@ -124,4 +127,88 @@ describe('Python Discord Bot Socket IPC Tests', done => {
requestDiscordClientClose();
});
});
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 => {
let clientConnected = false;
const clientId = process.env.DISCORD_CLIENT_ID;
const callback = () => {
clientConnected = true;
expect(clientConnected).to.be.true;
done();
};
initDiscordBotClient(clientId, callback);
});
it('Should emit command for and return status from join server', async () => {
// Simulate emitting 'join_server' event
const status = await connectToChannel(process.env.TEST_CHANNEL_ID);
// Check the server sent the expected info
// Assert the status returned from the server
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 () => {
// Simulate emitting 'check_discord_vc_connected' event
const isConnected = await checkIfConnectedToVC(process.env.TEST_GUILD_ID);
// Assert the connection status returned from the server
expect(isConnected).to.be.true;
});
it('Should emit command for and return username for request discord username', async () => {
// Simulate emitting 'request_discord_username' event
const username = await requestDiscordUsername(process.env.TEST_GUILD_ID);
// Assert the username returned from the server
expect(username).to.equal(process.env.EXPECTED_USERNAME);
});
it('Should emit command for and return discord client ID', async () => {
// Simulate emitting 'request_discord_id' event
const clientId = await requestDiscordID();
console.log("type of client id", typeof clientId, typeof process.env.EXPECTED_CLIENT_ID);
// Assert the client ID returned from the server
expect(clientId).to.equal(Number(process.env.EXPECTED_CLIENT_ID));
});
it('Should emit command for and return open status for leave server', async () => {
// Simulate emitting 'leave_server' event
const openStatus = await leaveVoiceChannel(process.env.TEST_GUILD_ID);
// Assert the open status returned from the server
expect(openStatus).to.be.false;
});
it('Should emit command for discord client to close', async () => {
// Simulate emitting 'request_client_close' event
await requestDiscordClientClose();
});
});