This repository has been archived by the owner on Nov 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
soulbreak-bot-utils.test.js
102 lines (100 loc) · 4.07 KB
/
soulbreak-bot-utils.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
const rewire = require('rewire');
const assert = chai.assert;
const sinon = require('sinon');
const discord = require('discord.js');
const path = require('path');
const botUtilsPath = path.join(
__dirname, '..', 'utilities', 'soulbreak-bot-utils.js');
const botUtils = rewire(botUtilsPath);
describe('soulbreak bot utils testing', () => {
let sandbox;
let msg = sinon.createStubInstance(discord.Client);
msg.author = sinon.createStubInstance(discord.User);
msg.channel = sinon.createStubInstance(discord.TextChannel);
msg.author.username = null;
msg.author.discriminator = null;
describe('lookupSoulbreak', () => {
beforeEach( () => {
sandbox = sinon.sandbox.create();
});
afterEach( () => {
sandbox.restore();
});
it('should send a summary of a character\'s soul break', () => {
msg.channel.send = sandbox.stub().resolves(null);
let query = 'cloud';
let sbType = 'all';
soulbreakSummarySpy = sandbox.spy(botUtils,
'sendSoulbreakRichEmbedSummary');
botUtils.__set__('sendSoulbreakRichEmbedSummary',
soulbreakSummarySpy);
return botUtils.soulbreak(msg, query, sbType).then( () => {
assert.equal(soulbreakSummarySpy.calledOnce, true);
});
});
it('should send a plaintext summary of a character\'s soul breaks',
() => {
msg.channel.send = sandbox.stub().rejects('method stubbed out');
let query = 'tifa';
let sbType = 'all';
soulbreakSummarySpy = sandbox.spy(botUtils,
'sendSoulbreakRichEmbedSummary');
soulbreakPlaintextSpy = sandbox.spy(botUtils,
'sendSoulbreakPlaintextSummary');
botUtils.__set__({
'sendSoulbreakRichEmbedSummary': soulbreakSummarySpy,
'sendSoulbreakPlaintextSummary': soulbreakPlaintextSpy,
});
return botUtils.soulbreak(msg, query, sbType).catch( () => {
assert.equal(soulbreakSummarySpy.calledOnce, true);
assert.equal(soulbreakPlaintextSpy.calledOnce, true);
});
});
it('should inform when search query is less than two letters', () => {
let message = 'Character name must be at least two characters.';
msg.channel.send = sandbox.stub().resolves(null);
let query = 'b';
return botUtils.soulbreak(msg, query, 'all').then( () => {
assert.equal(msg.channel.send.calledOnce, true);
assert.equal(msg.channel.send.calledWith(message), true);
});
});
it('should inform when no results are found for a character', () => {
let message = `No results for 'Foobar' 'all'.`;
let query = 'foobar';
msg.channel.send = sandbox.stub().resolves(null);
return botUtils.soulbreak(msg, query, 'all').then( () => {
assert.equal(msg.channel.send.calledOnce, true);
assert.equal(msg.channel.send.calledWith(message), true);
});
});
it('should inform when a user has not put in a valid SB type', () => {
let message = 'Soulbreak type not one of: ' +
'All, Default, SB, SSB, BSB, USB, OSB, CSB, FSB, ' +
'UOSB, Glint, AOSB, AASB.';
msg.channel.send = sandbox.stub().resolves(null);
let query = 'tifa';
return botUtils.soulbreak(msg, query, 'aaaaaaa').then( () => {
assert.equal(msg.channel.send.calledOnce, true);
assert.equal(msg.channel.send.calledWith(message), true);
});
});
it('should send one RichEmbed for a default soulbreak', () => {
let query = 'tifa';
msg.channel.send = sandbox.stub().resolves(null);
return botUtils.soulbreak(msg, query, 'default').then( () => {
assert.equal(msg.channel.send.calledOnce, true);
});
});
it('should send multiple for characters with more than one SB', () => {
let query = 'garnet';
msg.channel.send = sandbox.stub().resolves(null);
return botUtils.soulbreak(msg, query, 'BSB').then( () => {
assert.isAbove(msg.channel.send.callCount, 1);
});
});
});
});