Tests and CI #44
2 changed files with 169 additions and 1 deletions
|
@ -70,7 +70,7 @@ export class Util {
|
|||
} else {
|
||||
return {
|
||||
valid: false,
|
||||
message: "Comamnd folder does not exist",
|
||||
message: "Command folder does not exist",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,5 +66,173 @@ test('LoadCommand_GivenSuccessfulExection_ExpectSuccessfulResult', () => {
|
|||
|
||||
expect(result.valid).toBeTruthy();
|
||||
|
||||
client.destroy();
|
||||
});
|
||||
|
||||
test('LoadCommand_GivenMemberIsNull_ExpectFailedResult', () => {
|
||||
process.env = {
|
||||
BOT_TOKEN: 'TOKEN',
|
||||
BOT_PREFIX: '!',
|
||||
FOLDERS_COMMANDS: 'commands',
|
||||
FOLDERS_EVENTS: 'events',
|
||||
}
|
||||
|
||||
process.cwd = jest.fn().mockReturnValue("../../tests/__mocks");
|
||||
fs.existsSync = jest.fn().mockReturnValue(true);
|
||||
|
||||
const util = new Util();
|
||||
|
||||
let client = new Client();
|
||||
let user = new User(client, {
|
||||
id: SnowflakeUtil.generate(),
|
||||
username: "test-user",
|
||||
discriminator: 1234,
|
||||
});
|
||||
let guild = new Guild(client, {
|
||||
id: SnowflakeUtil.generate(),
|
||||
});
|
||||
let message = new Message(
|
||||
client,
|
||||
{
|
||||
content: "!test first",
|
||||
id: "test",
|
||||
type: 0,
|
||||
author: user,
|
||||
},
|
||||
new TextChannel(guild, {
|
||||
client: client,
|
||||
guild: guild,
|
||||
id: "channel-id",
|
||||
}),
|
||||
);
|
||||
|
||||
const result = util.loadCommand("name", [ "first" ], message);
|
||||
|
||||
expect(result.valid).toBeFalsy();
|
||||
expect(result.message).toBe("Member is not part of message");
|
||||
|
||||
client.destroy();
|
||||
});
|
||||
|
||||
test('LoadCommand_GivenFolderDoesNotExist_ExpectFailedResult', () => {
|
||||
process.env = {
|
||||
BOT_TOKEN: 'TOKEN',
|
||||
BOT_PREFIX: '!',
|
||||
FOLDERS_COMMANDS: 'commands',
|
||||
FOLDERS_EVENTS: 'events',
|
||||
}
|
||||
|
||||
process.cwd = jest.fn().mockReturnValue("../../tests/__mocks");
|
||||
fs.existsSync = jest.fn().mockReturnValue(false);
|
||||
|
||||
const util = new Util();
|
||||
|
||||
let client = new Client();
|
||||
let user = new User(client, {
|
||||
id: SnowflakeUtil.generate(),
|
||||
username: "test-user",
|
||||
discriminator: 1234,
|
||||
});
|
||||
let guild = new Guild(client, {
|
||||
id: SnowflakeUtil.generate(),
|
||||
members: [{
|
||||
user: user,
|
||||
nick: "Test User",
|
||||
roles: [],
|
||||
joined_at: "2015-04-26T06:26:56.936000+00:00",
|
||||
deaf: false,
|
||||
mute: false
|
||||
}]
|
||||
});
|
||||
let message = new Message(
|
||||
client,
|
||||
{
|
||||
content: "!test first",
|
||||
id: "test",
|
||||
member: {
|
||||
user: user,
|
||||
nick: "NOT API SUPPORT",
|
||||
roles: [],
|
||||
joined_at: "2015-04-26T06:26:56.936000+00:00",
|
||||
deaf: false,
|
||||
mute: false
|
||||
},
|
||||
type: 0,
|
||||
author: user,
|
||||
},
|
||||
new TextChannel(guild, {
|
||||
client: client,
|
||||
guild: guild,
|
||||
id: "channel-id",
|
||||
}),
|
||||
);
|
||||
|
||||
const result = util.loadCommand("name", [ "first" ], message);
|
||||
|
||||
expect(result.valid).toBeFalsy();
|
||||
expect(result.message).toBe("Command folder does not exist");
|
||||
|
||||
client.destroy();
|
||||
});
|
||||
|
||||
test('LoadCommand_GivenFileDoesNotExist_ExpectFailedResult', () => {
|
||||
process.env = {
|
||||
BOT_TOKEN: 'TOKEN',
|
||||
BOT_PREFIX: '!',
|
||||
FOLDERS_COMMANDS: 'commands',
|
||||
FOLDERS_EVENTS: 'events',
|
||||
}
|
||||
|
||||
process.cwd = jest.fn().mockReturnValue("../../tests/__mocks");
|
||||
fs.existsSync = jest.fn().mockReturnValueOnce(true)
|
||||
.mockReturnValue(false);
|
||||
|
||||
const util = new Util();
|
||||
|
||||
let client = new Client();
|
||||
let user = new User(client, {
|
||||
id: SnowflakeUtil.generate(),
|
||||
username: "test-user",
|
||||
discriminator: 1234,
|
||||
});
|
||||
let guild = new Guild(client, {
|
||||
id: SnowflakeUtil.generate(),
|
||||
members: [{
|
||||
user: user,
|
||||
nick: "Test User",
|
||||
roles: [],
|
||||
joined_at: "2015-04-26T06:26:56.936000+00:00",
|
||||
deaf: false,
|
||||
mute: false
|
||||
}]
|
||||
});
|
||||
let message = new Message(
|
||||
client,
|
||||
{
|
||||
content: "!test first",
|
||||
id: "test",
|
||||
member: {
|
||||
user: user,
|
||||
nick: "NOT API SUPPORT",
|
||||
roles: [],
|
||||
joined_at: "2015-04-26T06:26:56.936000+00:00",
|
||||
deaf: false,
|
||||
mute: false
|
||||
},
|
||||
type: 0,
|
||||
author: user,
|
||||
},
|
||||
new TextChannel(guild, {
|
||||
client: client,
|
||||
guild: guild,
|
||||
id: "channel-id",
|
||||
}),
|
||||
);
|
||||
|
||||
const result = util.loadCommand("name", [ "first" ], message);
|
||||
|
||||
expect(result.valid).toBeFalsy();
|
||||
expect(result.message).toBe("File does not exist");
|
||||
|
||||
client.destroy();
|
||||
});
|
Reference in a new issue