-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0c80fc
commit f0697df
Showing
1 changed file
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
import { expect } from "chai"; | ||
import MessageReactionManager from "../../src/managers/MessageReactionManager.js"; | ||
import { TEST_CLIENTS, TEST_DATA, TEST_GUILDS } from "../../src/testData.js"; | ||
import { TO_JSON_TYPES_ENUM } from "../../src/constants.js"; | ||
|
||
describe("MessageReactionManager", function () { | ||
context("check import", function () { | ||
it("should be a function", function () { | ||
expect(MessageReactionManager).to.be.a("function"); | ||
}); | ||
}); | ||
|
||
context("check structure", function () { | ||
it("should create a new instance of MessageReactionManager with the correct options", function () { | ||
const client = TEST_CLIENTS.ALL_CACHES_ENABLED(); | ||
const guild = TEST_GUILDS.ALL_CACHES_ENABLED(client); | ||
const messageReactionManager = new MessageReactionManager( | ||
client, | ||
guild, | ||
{}, | ||
); | ||
expect(messageReactionManager).to.be.an.instanceOf( | ||
MessageReactionManager, | ||
); | ||
expect(messageReactionManager).to.have.property("_addReaction"); | ||
expect(messageReactionManager).to.have.property("_removeReaction"); | ||
expect(messageReactionManager).to.have.property("toJSON"); | ||
}); | ||
}); | ||
|
||
context("check _addReaction method", function () { | ||
it("should add a reaction to a message", function () { | ||
const client = TEST_CLIENTS.ALL_CACHES_ENABLED(); | ||
const guild = TEST_GUILDS.ALL_CACHES_ENABLED(client); | ||
const messageReactionManager = new MessageReactionManager( | ||
client, | ||
guild, | ||
{}, | ||
); | ||
messageReactionManager._addReaction( | ||
"123456", | ||
TEST_DATA.STANDARD_EMOJI.name, | ||
TEST_DATA.REACTION, | ||
); | ||
expect( | ||
messageReactionManager.toJSON(TO_JSON_TYPES_ENUM.CACHE_FORMAT), | ||
).to.have.property(TEST_DATA.STANDARD_EMOJI.name); | ||
}); | ||
it("should throw an error if userId is not a string", function () { | ||
const client = TEST_CLIENTS.ALL_CACHES_ENABLED(); | ||
const guild = TEST_GUILDS.ALL_CACHES_ENABLED(client); | ||
const messageReactionManager = new MessageReactionManager( | ||
client, | ||
guild, | ||
{}, | ||
); | ||
expect(() => | ||
messageReactionManager._addReaction( | ||
123456, | ||
TEST_DATA.STANDARD_EMOJI.name, | ||
TEST_DATA.REACTION, | ||
), | ||
).to.throw(TypeError, "GLUON: User ID must be a string."); | ||
}); | ||
it("should throw an error if emoji is not a string", function () { | ||
const client = TEST_CLIENTS.ALL_CACHES_ENABLED(); | ||
const guild = TEST_GUILDS.ALL_CACHES_ENABLED(client); | ||
const messageReactionManager = new MessageReactionManager( | ||
client, | ||
guild, | ||
{}, | ||
); | ||
expect(() => | ||
messageReactionManager._addReaction( | ||
"123456", | ||
123456, | ||
TEST_DATA.REACTION, | ||
), | ||
).to.throw(TypeError, "GLUON: Emoji must be a string."); | ||
}); | ||
it("should throw an error if data is not an object", function () { | ||
const client = TEST_CLIENTS.ALL_CACHES_ENABLED(); | ||
const guild = TEST_GUILDS.ALL_CACHES_ENABLED(client); | ||
const messageReactionManager = new MessageReactionManager( | ||
client, | ||
guild, | ||
{}, | ||
); | ||
expect(() => | ||
messageReactionManager._addReaction( | ||
"123456", | ||
TEST_DATA.STANDARD_EMOJI.name, | ||
123456, | ||
), | ||
).to.throw(TypeError, "GLUON: Data must be an object."); | ||
}); | ||
}); | ||
|
||
context("check _removeReaction method", function () { | ||
it("should remove a reaction from a message", function () { | ||
const client = TEST_CLIENTS.ALL_CACHES_ENABLED(); | ||
const guild = TEST_GUILDS.ALL_CACHES_ENABLED(client); | ||
const messageReactionManager = new MessageReactionManager( | ||
client, | ||
guild, | ||
{}, | ||
); | ||
messageReactionManager._addReaction( | ||
"123456", | ||
TEST_DATA.STANDARD_EMOJI.name, | ||
TEST_DATA.REACTION, | ||
); | ||
messageReactionManager._removeReaction( | ||
"123456", | ||
TEST_DATA.STANDARD_EMOJI.name, | ||
); | ||
expect( | ||
messageReactionManager.toJSON(TO_JSON_TYPES_ENUM.CACHE_FORMAT), | ||
).to.not.have.property(TEST_DATA.STANDARD_EMOJI.name); | ||
}); | ||
it("should throw an error if userId is not a string", function () { | ||
const client = TEST_CLIENTS.ALL_CACHES_ENABLED(); | ||
const guild = TEST_GUILDS.ALL_CACHES_ENABLED(client); | ||
const messageReactionManager = new MessageReactionManager( | ||
client, | ||
guild, | ||
{}, | ||
); | ||
expect(() => | ||
messageReactionManager._removeReaction( | ||
123456, | ||
TEST_DATA.STANDARD_EMOJI.name, | ||
), | ||
).to.throw(TypeError, "GLUON: User ID must be a string."); | ||
}); | ||
it("should throw an error if emoji is not a string", function () { | ||
const client = TEST_CLIENTS.ALL_CACHES_ENABLED(); | ||
const guild = TEST_GUILDS.ALL_CACHES_ENABLED(client); | ||
const messageReactionManager = new MessageReactionManager( | ||
client, | ||
guild, | ||
{}, | ||
); | ||
expect(() => | ||
messageReactionManager._removeReaction("123456", 123456), | ||
).to.throw(TypeError, "GLUON: Emoji must be a string."); | ||
}); | ||
it("should not throw an error if the reaction does not exist", function () { | ||
const client = TEST_CLIENTS.ALL_CACHES_ENABLED(); | ||
const guild = TEST_GUILDS.ALL_CACHES_ENABLED(client); | ||
const messageReactionManager = new MessageReactionManager( | ||
client, | ||
guild, | ||
{}, | ||
); | ||
expect(() => | ||
messageReactionManager._removeReaction( | ||
"123456", | ||
TEST_DATA.STANDARD_EMOJI.name, | ||
), | ||
).to.not.throw(); | ||
}); | ||
}); | ||
}); |