Skip to content

Commit

Permalink
more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Starman3787 committed Jul 17, 2024
1 parent 5d7f0d9 commit 4735384
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 19 deletions.
139 changes: 139 additions & 0 deletions test/util/builder/buttonBuilder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
let expect;
before(async () => {
expect = (await import("chai")).expect;
});
const { COMPONENT_TYPES } = require("../../../src/constants");
const Button = require("../../../src/util/builder/buttonBuilder");

describe("ButtonBuilder", () => {
context("check import", function () {
it("should be an object", function () {
const button = new Button();
expect(button).to.be.an("object");
});
});

context("check setLabel", function () {
it("should have method setLabel", function () {
const button = new Button();
expect(button).to.respondTo("setLabel");
});
it("should set the label of the button", function () {
const button = new Button();
button.setLabel("test");
expect(button.label).to.equal("test");
});
it("should throw an error if no label is provided", function () {
const button = new Button();
expect(() => button.setLabel()).to.throw(
TypeError,
"GLUON: Button label must be provided."
);
});
});

context("check setEmoji", function () {
it("should have method setEmoji", function () {
const button = new Button();
expect(button).to.respondTo("setEmoji");
});
it("should set the emoji of the button", function () {
const button = new Button();
button.setEmoji("👍");
expect(button.emoji.name).to.equal("👍");
});
it("should set the emoji id of the button", function () {
const button = new Button();
button.setEmoji("<:bitcoin:844240546246950922>");
expect(button.emoji.id).to.equal("844240546246950922");
expect(button.emoji.name).to.equal("bitcoin");
expect(button.emoji.animated).to.equal(false);
});
it("should throw an error if no emoji is provided", function () {
const button = new Button();
expect(() => button.setEmoji()).to.throw(
TypeError,
"GLUON: The emoji must be a string."
);
});
it("should throw an error if string is not an emoji", function () {
const button = new Button();
expect(() => button.setEmoji("test")).to.throw(
TypeError,
"GLUON: Button emoji must be provided."
);
});
});

context("check setStyle", function () {
it("should have method setStyle", function () {
const button = new Button();
expect(button).to.respondTo("setStyle");
});
it("should set the style of the button", function () {
const button = new Button();
button.setStyle(1);
expect(button.style).to.equal(1);
});
});

context("check setCustomID", function () {
it("should have method setCustomID", function () {
const button = new Button();
expect(button).to.respondTo("setCustomID");
});
it("should set the custom id of the button", function () {
const button = new Button();
button.setCustomID("custom_id");
expect(button.custom_id).to.equal("custom_id");
});
});

context("check setURL", function () {
it("should have method setURL", function () {
const button = new Button();
expect(button).to.respondTo("setURL");
});
it("should set the url of the button", function () {
const button = new Button();
button.setURL("https://example.com");
expect(button.url).to.equal("https://example.com");
});
});

context("check setDisabled", function () {
it("should have method setDisabled", function () {
const button = new Button();
expect(button).to.respondTo("setDisabled");
});
it("should set the disabled status of the button", function () {
const button = new Button();
button.setDisabled(true);
expect(button.disabled).to.equal(true);
});
});

context("check toJSON", function () {
it("should have method toJSON", function () {
const button = new Button();
expect(button).to.respondTo("toJSON");
});
it("should return the button as an object", function () {
const button = new Button()
.setCustomID("custom_id")
.setLabel("test")
.setDisabled(true)
.setEmoji("👍")
.setStyle(1);
expect(button.toJSON()).to.deep.equal({
type: COMPONENT_TYPES.BUTTON,
disabled: true,
label: "test",
style: 1,
emoji: { name: "👍", id: null },
url: undefined,
custom_id: "custom_id",
});
});
});
});
38 changes: 19 additions & 19 deletions test/util/builder/embedBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ describe("Embed", function () {
});
it("should set the url of the embed", function () {
const embed = new Embed();
embed.setURL("url");
expect(embed.url).to.equal("url");
embed.setURL("https://example.com");
expect(embed.url).to.equal("https://example.com");
});
it("should throw an error if the url is empty", function () {
const embed = new Embed();
Expand Down Expand Up @@ -115,14 +115,14 @@ describe("Embed", function () {
});
it("should set the footer of the embed", function () {
const embed = new Embed();
embed.setFooter("footer", "icon");
embed.setFooter("footer", "https://example.com");
expect(embed.footer.text).to.equal("footer");
expect(embed.footer.icon_url).to.equal("icon");
expect(embed.footer.icon_url).to.equal("https://example.com");
});
it("should throw an error if the text is empty", function () {
const embed = new Embed();
expect(() => {
embed.setFooter(undefined, "icon");
embed.setFooter(undefined, "https://example.com");
}).to.throw(TypeError, "GLUON: Embed footer text must be provided.");
});
it("should not allow the character limit to be exceeded", function () {
Expand All @@ -139,8 +139,8 @@ describe("Embed", function () {
});
it("should set the image of the embed", function () {
const embed = new Embed();
embed.setImage("image");
expect(embed.image.url).to.equal("image");
embed.setImage("https://example.com");
expect(embed.image.url).to.equal("https://example.com");
});
});

Expand All @@ -151,8 +151,8 @@ describe("Embed", function () {
});
it("should set the thumbnail of the embed", function () {
const embed = new Embed();
embed.setThumbnail("thumbnail");
expect(embed.thumbnail.url).to.equal("thumbnail");
embed.setThumbnail("https://example.com");
expect(embed.thumbnail.url).to.equal("https://example.com");
});
it("should throw an error if the url is empty", function () {
const embed = new Embed();
Expand Down Expand Up @@ -180,8 +180,8 @@ describe("Embed", function () {
});
it("should set the author url of the embed", function () {
const embed = new Embed();
embed.setAuthor("author", "url");
expect(embed.author.url).to.equal("url");
embed.setAuthor("author", "https://example.com");
expect(embed.author.url).to.equal("https://example.com");
});
it("should not allow the character limit to be exceeded", function () {
const embed = new Embed();
Expand Down Expand Up @@ -263,7 +263,7 @@ describe("Embed", function () {
const embed = new Embed();
embed.setTitle("title");
embed.setDescription("description");
embed.setURL("url");
embed.setURL("https://example.com");
embed.setColor("color");
embed.setTimestamp(123456);
embed.setFooter("footer");
Expand All @@ -282,7 +282,7 @@ describe("Embed", function () {
const embed = new Embed();
embed.setTitle("title");
embed.setDescription("description");
embed.setURL("url");
embed.setURL("https://example.com");
embed.setColor("color");
embed.setTimestamp(123456);
embed.setFooter("footer");
Expand All @@ -303,29 +303,29 @@ describe("Embed", function () {
const embed = new Embed();
embed.setTitle("title");
embed.setDescription("description");
embed.setURL("url");
embed.setURL("https://example.com");
embed.setColor("color");
embed.setTimestamp(123456);
embed.setFooter("footer");
embed.setImage("image");
embed.setThumbnail("thumbnail");
embed.setImage("https://example.com");
embed.setThumbnail("https://example.com");
embed.setAuthor("author");
embed.addField("field", "fieldValue");
expect(embed.toJSON()).to.deep.equal({
type: "rich",
title: "title",
description: "description",
url: "url",
url: "https://example.com",
color: hexToInt("color"),
timestamp: new Date(123456 * 1000).toISOString(),
footer: {
text: "footer",
},
image: {
url: "image",
url: "https://example.com",
},
thumbnail: {
url: "thumbnail",
url: "https://example.com",
},
author: {
name: "author",
Expand Down

0 comments on commit 4735384

Please sign in to comment.