Skip to content

Commit

Permalink
Initial Pass
Browse files Browse the repository at this point in the history
Work for #122. WIP
  • Loading branch information
Ian Mitchell committed Jan 13, 2016
1 parent fe86f83 commit 275d066
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 179 deletions.
50 changes: 24 additions & 26 deletions test/commands/test_choose.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,55 @@ describe('Choose', () => {
describe('Triggers', () => {
it('should respond to .c trigger', () => {
return choose.message('Mocha', '#test', '.c this, that').then(() => {
assert(client.lastMessage);
assert(client.lastMessage, 'Bot did not send message to channel');
});
});

it('should respond to .choose trigger', () => {
return choose.message('Mocha', '#test', '.choose one, two').then(() => {
assert(client.lastMessage);
assert(client.lastMessage, 'Bot did not send message to channel');
});
});

it('should respond to .erande trigger', () => {
return choose.message('Mocha', '#test', '.erande one, two').then(() => {
assert(client.lastMessage);
assert(client.lastMessage, 'Bot did not send message to channel');
});
});

it('should respond to .選んで trigger', () => {
return choose.message('Mocha', '#test', '.選んで one, two').then(() => {
assert(client.lastMessage);
assert(client.lastMessage, 'Bot did not send message to channel');
});
});

it('should respond to .選ぶがよい trigger', () => {
return choose.message('Mocha', '#test', '.選ぶがよい one, two').then(() => {
assert(client.lastMessage);
assert(client.lastMessage, 'Bot did not send message to channel');
});
});

it('should not respond to .choo trigger', () => {
return choose.message('Mocha', '#test', '.choo one, two').then(() => {
assert.equal(null, client.lastMessage);
assert(!client.lastMessage, 'Bot sent message to channel');
});
});

it('should activate in beginning of phrase', () => {
return choose.message('Mocha', '#test', '.c this, that').then(() => {
assert.notEqual(null, client.lastMessage);
assert(client.lastMessage, 'Bot did not send message to channel');
});
});

it('should not activate in middle of phrase', () => {
return choose.message('Mocha', '#test', 'test .c this, that').then(() => {
assert.equal(null, client.lastMessage);
assert(!client.lastMessage, 'Bot sent message to channel');
});
});

it('should not activate with an empty list', () => {
return choose.message('Mocha', '#test', '.c').then(() => {
assert.equal(null, client.lastMessage);
assert.equal(client.lastMessage, null);
});
});

Expand All @@ -72,49 +72,49 @@ describe('Choose', () => {
];

return choose.message('Mocha', '#test', '.c ,, , ,,').then(() => {
assert(outputs.includes(client.lastMessage));
assert(outputs.includes(client.lastMessage), 'Invalid option chosen');
});
});

it('should activate with a single commas', () => {
return choose.message('Mocha', '#test', '.c , ').then(() => {
assert.equal('Mocha: ,', client.lastMessage);
assert.equal(client.lastMessage, 'Mocha: ,');
});
});

it('should be case insensitive', () => {
return choose.message('Mocha', '#test', '.CHOOSE A').then(() => {
assert.equal('Mocha: A', client.lastMessage);
assert.equal(client.lastMessage, 'Mocha: A');
});
});
});

describe('General Usage', () => {
it('should respond in correct channel', () => {
return choose.message('Mocha', '#test', '.c this, that').then(() => {
assert.equal('#test', client.lastTarget);
assert.equal(client.lastTarget, '#test');
});
});

it("should include user's name", () => {
return choose.message('Mocha', '#test', '.choose this, that').then(() => {
assert(client.lastMessage.startsWith('Mocha: '));
assert(client.lastMessage.startsWith('Mocha: '), 'Invalid username prefix');
});
});
});

describe('Comma Delimited List', () => {
it('should choose from the list', () => {
return choose.message('Mocha', '#test', '.choose that, that').then(() => {
assert.equal('Mocha: that', client.lastMessage);
assert.equal(client.lastMessage, 'Mocha: that');
});
});
});

describe('Space Delimited List', () => {
it('should choose from the list', () => {
return choose.message('Mocha', '#test', '.c commie commie').then(() => {
assert.equal('Mocha: commie', client.lastMessage);
assert.equal(client.lastMessage, 'Mocha: commie');
});
});
});
Expand All @@ -128,8 +128,8 @@ describe('Choose', () => {
for (let i = 0; i < 20; i++) {
choose.message('Mocha', '#test', `.c ${range}`);
const value = client.lastMessage.replace('Mocha: ', '');
assert(value >= lowerBound);
assert(value <= upperBound);
assert(value >= lowerBound, 'Value less than lower bound');
assert(value <= upperBound, 'Value greater than upper bound');
}
});

Expand All @@ -138,11 +138,10 @@ describe('Choose', () => {
const upperBound = 5;
const range = `${upperBound}-${lowerBound}`;


return choose.message('Mocha', '#test', `.c ${range}`).then(() => {
const value = client.lastMessage.replace('Mocha: ', '');
assert(value <= upperBound);
assert(value >= lowerBound);
assert(value >= lowerBound, 'Value less than lower bound');
assert(value <= upperBound, 'Value greater than upper bound');
});
});

Expand All @@ -151,11 +150,10 @@ describe('Choose', () => {
const upperBound = -5;
const range = `${lowerBound}-${upperBound}`;


return choose.message('Mocha', '#test', `.c ${range}`).then(() => {
const value = client.lastMessage.replace('Mocha: ', '');
assert(value <= upperBound);
assert(value >= lowerBound);
assert(value >= lowerBound, 'Value less than lower bound');
assert(value <= upperBound, 'Value greater than upper bound');
});
});

Expand Down Expand Up @@ -189,8 +187,8 @@ describe('Choose', () => {
}
}
}).then(() => {
assert(lowerBoundChosen);
assert(upperBoundChosen);
assert(lowerBoundChosen, 'Lower bound not chosen (possible)');
assert(upperBoundChosen, 'Upper bound not chosen (possible)');
});
});
});
Expand Down
8 changes: 4 additions & 4 deletions test/commands/test_command.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ describe('Command', () => {
describe('Blacklist', () => {
it('should block .ly links', () => {
command.send('#test', 'Desch: http://bit.ly link');
assert.equal('Blacklist triggered.', client.lastMessage);
assert.equal(client.lastMessage, 'Blacklist triggered.');
});

it('should block .lewd', () => {
command.send('#test', 'Desch: .lewd');
assert.equal('Blacklist triggered.', client.lastMessage);
assert.equal(client.lastMessage, 'Blacklist triggered.');
});

it('should block `xd`', () => {
command.send('#test', 'Desch: xd');
assert.equal('Blacklist triggered.', client.lastMessage);
assert.equal(client.lastMessage, 'Blacklist triggered.');
});

it('should not block xdcc', () => {
command.send('#test', 'Desch: xdcc');
assert.equal('Desch: xdcc', client.lastMessage);
assert.equal(client.lastMessage, 'Desch: xdcc');
});
});
});
20 changes: 10 additions & 10 deletions test/commands/test_imgur.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,41 @@ describe('Imgur', () => {
describe('Triggers', () => {
it('should activate anywhere in phrase with Gallery URL', () => {
return imgur.message('Mocha', '#test0', `ARX-7 ${link}!`).then(() => {
assert(client.lastMessage);
assert.notEqual(client.lastMessage, null);
});
});

it('should activate anywhere in phrase with Standard URL', () => {
return imgur.message('Mocha', '#test', `ARX-7 ${standard}!`).then(() => {
assert(client.lastMessage);
assert.notEqual(client.lastMessage, null);
});
});

it('should activate anywhere in phrase with Direct URL', () => {
return imgur.message('Mocha', '#test4', `ARX-7 ${direct}!`).then(() => {
assert(client.lastMessage);
assert.notEqual(client.lastMessage, null);
});
});

it('should log and handle malformed links', () => {
return imgur.message('Mocha', '#test', `${malformed}`).catch(error => {
assert(error instanceof Error);
assert(error.message.startsWith('Imgur Info'));
assert.equal('Sorry, could not find Imgur info.', client.lastMessage);
assert(error instanceof Error, 'Incorrect Error returned');
assert(error.message.startsWith('Imgur Info'), 'Incorrect Error message');
assert.equal(client.lastMessage, 'Sorry, could not find Imgur info.');
});
});
});

describe('General Usage', () => {
it('should respond in correct channel', () => {
return imgur.message('Mocha', '#test', link).then(() => {
assert.equal('#test', client.lastTarget);
assert.equal(client.lastTarget, '#test');
});
});

it('should include [Imgur]', () => {
return imgur.message('Mocha', '#test', link).then(() => {
assert(client.lastMessage.startsWith('[Imgur] '));
assert(client.lastMessage.startsWith('[Imgur] '), 'Message not properly tagged');
});
});
});
Expand All @@ -72,14 +72,14 @@ describe('Imgur', () => {

it('should display correct title', () => {
return imgur.message('Mocha', '#test', link).then(() => {
assert(client.lastMessage.includes(title));
assert(client.lastMessage.includes(title), 'Message does not include title');
});
});

it('should include view count', () => {
return imgur.message('Mocha', '#test', link).then(() => {
const views = client.lastMessage.split('Views: ')[1];
assert((parseInt(views, 10) > 300));
assert((parseInt(views, 10) > 300), 'Message contains invalid view amount');
});
});
});
Expand Down
Loading

0 comments on commit 275d066

Please sign in to comment.