mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 03:23:29 +01:00
Basic test script setup
This commit is contained in:
122
test/lib-test.js
122
test/lib-test.js
@@ -4,6 +4,7 @@
|
|||||||
var Discord = require("../");
|
var Discord = require("../");
|
||||||
var client = new Discord.Client();
|
var client = new Discord.Client();
|
||||||
var colors = require("colors");
|
var colors = require("colors");
|
||||||
|
var fs = require("fs");
|
||||||
|
|
||||||
var passes = 0, fails = 0;
|
var passes = 0, fails = 0;
|
||||||
|
|
||||||
@@ -17,6 +18,7 @@ function pass(msg) {
|
|||||||
|
|
||||||
function err(msg) {
|
function err(msg) {
|
||||||
console.log(" ✗ ".red + msg);
|
console.log(" ✗ ".red + msg);
|
||||||
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Beginning Lib Test".yellow);
|
console.log("Beginning Lib Test".yellow);
|
||||||
@@ -95,15 +97,15 @@ function makeChannel() {
|
|||||||
pass("valid channel name & type");
|
pass("valid channel name & type");
|
||||||
|
|
||||||
channel = chann;
|
channel = chann;
|
||||||
|
|
||||||
editChannel();
|
editChannel();
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function editChannel() {
|
function editChannel() {
|
||||||
section("Channel Editting");
|
section("Channel Manipulation");
|
||||||
|
|
||||||
client.setChannelNameAndTopic(channel, "testing", "a testing channel - temporary").then(() => {
|
client.setChannelNameAndTopic(channel, "testing", "a testing channel - temporary").then(() => {
|
||||||
|
|
||||||
if (channel.name !== "testing" || channel.topic !== "a testing channel - temporary") {
|
if (channel.name !== "testing" || channel.topic !== "a testing channel - temporary") {
|
||||||
@@ -122,42 +124,136 @@ function editChannel() {
|
|||||||
|
|
||||||
function sendMsg() {
|
function sendMsg() {
|
||||||
section("Message Creation");
|
section("Message Creation");
|
||||||
|
|
||||||
client.sendMessage(channel, "test message!", { tts: true }).then(msg => {
|
client.sendMessage(channel, "test message!", { tts: true }).then(msg => {
|
||||||
|
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
err("message not passed");
|
err("message not passed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg.content !== "test message!" || !msg.sender.equals(client.user) || !msg.channel.equals(channel)) {
|
if (msg.content !== "test message!" || !msg.sender.equals(client.user) || !msg.channel.equals(channel)) {
|
||||||
err("invalid content, sender or channel assigned to message");
|
err("invalid content, sender or channel assigned to message");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!msg.tts) {
|
if (!msg.tts) {
|
||||||
err("message wasn't TTS on response, even though on request it was");
|
err("message wasn't TTS on response, even though on request it was");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pass("message successfully created");
|
pass("message successfully created");
|
||||||
pass("correct parameters in message");
|
pass("correct parameters in message");
|
||||||
|
|
||||||
message = msg;
|
message = msg;
|
||||||
|
|
||||||
editMsg();
|
editMsg();
|
||||||
|
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
err("error sending message: " + e)
|
err("error sending message: " + e)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function editMsg() {
|
function editMsg() {
|
||||||
|
|
||||||
section("Message Manipulation");
|
section("Message Manipulation");
|
||||||
|
|
||||||
client.updateMessage(message, client.user + channel + server).then(msg => {
|
client.updateMessage(message, client.user + channel + server).then(msg => {
|
||||||
|
|
||||||
|
if (!msg) {
|
||||||
|
err("message not passed back on update");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.content !== client.user.mention() + channel.mention() + server.name) {
|
||||||
|
err("message content not what expected");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pass("message updated");
|
||||||
|
pass("message content was as expected - complex");
|
||||||
|
|
||||||
|
client.deleteMessage(message).then(() => {
|
||||||
|
pass("message deleted");
|
||||||
|
sendFile();
|
||||||
|
}).catch(e => {
|
||||||
|
err("error deleting message: " + e)
|
||||||
|
});
|
||||||
|
|
||||||
|
}).catch(e => {
|
||||||
|
err("error updating message: " + e)
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendFile() {
|
||||||
|
section("File Sending & Deletion");
|
||||||
|
|
||||||
|
client.sendFile(channel, "./test/image.png", "image.png").then(file => {
|
||||||
|
|
||||||
|
if (!file) {
|
||||||
|
err("file not passed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file.attachments.length === 0) {
|
||||||
|
err("attachment not added");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pass("sent attachment file");
|
||||||
|
|
||||||
|
client.deleteMessage(file).then(() => {
|
||||||
|
pass("message deleted");
|
||||||
|
deleteAll();
|
||||||
|
}).catch(e => {
|
||||||
|
err("error deleting message: " + e)
|
||||||
|
});
|
||||||
|
|
||||||
|
}).catch(e => {
|
||||||
|
err("error sending file: " + e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteAll() {
|
||||||
|
|
||||||
|
section("Clean Up");
|
||||||
|
|
||||||
|
client.deleteChannel(channel).then(() => {
|
||||||
|
|
||||||
|
pass("deleted temporary channel");
|
||||||
|
|
||||||
|
client.leaveServer(server).then(() => {
|
||||||
|
|
||||||
|
pass("deleted temporary server");
|
||||||
|
|
||||||
|
exit();
|
||||||
|
|
||||||
|
}).catch(e => {
|
||||||
|
err("error deleting server: " + e);
|
||||||
|
});
|
||||||
|
|
||||||
|
}).catch(e => {
|
||||||
|
err("error deleting channel: " + e);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function exit() {
|
||||||
|
|
||||||
|
section("Exiting");
|
||||||
|
|
||||||
|
client.logout().then(() => {
|
||||||
|
pass("logged out");
|
||||||
|
done();
|
||||||
|
}).catch(e => {
|
||||||
|
err("couldn't log out: " + e);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function done() {
|
||||||
|
section("Report");
|
||||||
|
pass("all tests done");
|
||||||
|
process.exit(0);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user