Skip to content

Commit

Permalink
add to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Starman3787 committed Aug 24, 2024
1 parent bb8716e commit 7d439e1
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/managers/UserManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ class UserManager extends BaseCacheManager {

/**
* Fetches a particular user.
* @param {String} user_id The id of the user to fetch.
* @param {String} userId The id of the user to fetch.
* @returns {Promise<User>} The fetched user.
* @public
* @async
* @method
* @throws {TypeError | Error}
*/
async fetch(user_id) {
if (typeof user_id !== "string")
async fetch(userId) {
if (typeof userId !== "string")
throw new TypeError("GLUON: User ID must be a string.");

const cached = await this.get(user_id);
const cached = await this.get(userId);
if (cached) return cached;

const data = await this.#_client.request.makeRequest("getUser", [user_id]);
const data = await this.#_client.request.makeRequest("getUser", [userId]);

return new User(this.#_client, data);
}
Expand Down
36 changes: 36 additions & 0 deletions test/managers/ChannelMessageManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ describe("ChannelMessageManager", function () {
expect(channelMessageManager).to.have.property("guild");
expect(channelMessageManager).to.have.property("fetch");
expect(channelMessageManager).to.have.property("fetchPinned");
expect(channelMessageManager).to.have.property("set");
expect(channelMessageManager).to.have.property("guild");
expect(ChannelMessageManager).to.have.property("getCacheManager");
expect(ChannelMessageManager).to.have.property("fetchMessage");
expect(ChannelMessageManager).to.have.property("getMessage");
Expand All @@ -53,6 +55,40 @@ describe("ChannelMessageManager", function () {
});
});

context("check set", function () {
it("should set the correct value", function () {
const client = TEST_CLIENTS.ALL_CACHES_ENABLED();
const guild = TEST_GUILDS.ALL_CACHES_ENABLED(client);
const channel = TEST_CHANNELS.TEXT_CHANNEL_ALL_CACHES_ENABLED(client);
const channelMessageManager = new ChannelMessageManager(
client,
guild,
channel,
);
const message = new Message(client, TEST_DATA.MESSAGE, {
channelId: channel.id,
guildId: guild.id,
});
channelMessageManager.set(TEST_DATA.MESSAGE_ID, message);
expect(channelMessageManager.get(TEST_DATA.MESSAGE_ID)).to.deep.equal(
message,
);
});
it("should throw an error when the message is not a Message instance", function () {
const client = TEST_CLIENTS.ALL_CACHES_ENABLED();
const guild = TEST_GUILDS.ALL_CACHES_ENABLED(client);
const channel = TEST_CHANNELS.TEXT_CHANNEL_ALL_CACHES_ENABLED(client);
const channelMessageManager = new ChannelMessageManager(
client,
guild,
channel,
);
expect(() =>
channelMessageManager.set(TEST_DATA.MESSAGE_ID, {}),
).to.throw(TypeError, "GLUON: Message must be a Message instance.");
});
});

context("check fetch", function () {
it("should be a function", function () {
const client = TEST_CLIENTS.ALL_CACHES_ENABLED();
Expand Down
11 changes: 11 additions & 0 deletions test/managers/GuildChannelsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ describe("GuildChannelsManager", function () {
const channel = channelsManager.get(textChannel.id);
expect(channel).to.be.an.instanceOf(TextChannel);
});
it("should throw an error when the channel is not a TextChannel instance", function () {
const client = TEST_CLIENTS.ALL_CACHES_ENABLED();
const guild = TEST_GUILDS.ALL_CACHES_ENABLED(client);
const channelsManager = new GuildChannelsManager(client, guild);
expect(() => {
channelsManager.set("123456", {});
}).to.throw(
TypeError,
"GLUON: Channel must be a VoiceChannel, TextChannel, CategoryChannel, Channel or Thread instance.",
);
});
});

context("check fetch method", function () {
Expand Down
8 changes: 8 additions & 0 deletions test/managers/GuildManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ describe("GuildManager", function () {
guildManager.set("123456", guild);
expect(guildManager.get("123456")).to.deep.equal(guild);
});
it("should throw an error if guild is not a Guild instance", function () {
const client = TEST_CLIENTS.ALL_CACHES_ENABLED();
const guildManager = new GuildManager(client);
expect(() => guildManager.set("123456", {})).to.throw(
TypeError,
"GLUON: Guild must be an instance of Guild.",
);
});
});

context("check getCacheManager method", function () {
Expand Down

0 comments on commit 7d439e1

Please sign in to comment.