Skip to content

Commit

Permalink
Create MessageReactionManager.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Starman3787 committed Aug 24, 2024
1 parent e0c80fc commit f0697df
Showing 1 changed file with 164 additions and 0 deletions.
164 changes: 164 additions & 0 deletions test/managers/MessageReactionManager.js
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();
});
});
});

0 comments on commit f0697df

Please sign in to comment.