Skip to content

Commit

Permalink
add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Starman3787 committed Aug 24, 2024
1 parent 7d439e1 commit e812e92
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions test/managers/UserManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { expect } from "chai";
import { spy } from "sinon";
import { UserManager } from "../../src/structures.js";
import { TEST_CLIENTS, TEST_DATA } from "../../src/testData.js";
import { User } from "../../src/structures.js";

describe("UserManager", function () {
context("check import", function () {
it("should be a function", function () {
expect(UserManager).to.be.a("function");
});
});

context("check structure", function () {
it("should create a new instance of UserManager with the correct options", function () {
const client = TEST_CLIENTS.ALL_CACHES_ENABLED();
const userManager = new UserManager(client);
expect(userManager).to.be.an.instanceOf(UserManager);
expect(userManager).to.have.property("set");
expect(userManager).to.have.property("fetch");
});
});

context("check set method", function () {
it("should set the correct values", function () {
const client = TEST_CLIENTS.ALL_CACHES_ENABLED();
const userManager = new UserManager(client);
const user = new User(client, TEST_DATA.USER);
userManager.set("123456", user);
expect(userManager.get("123456")).to.deep.equal(user);
});
it("should throw an error if user is not a User instance", function () {
const client = TEST_CLIENTS.ALL_CACHES_ENABLED();
const userManager = new UserManager(client);
expect(() => userManager.set("123456", {})).to.throw(
TypeError,
"GLUON: User must be an instance of User.",
);
});
});

context("check fetch method", function () {
it("should fetch the correct user", async function () {
const client = TEST_CLIENTS.ALL_CACHES_ENABLED();
const userManager = new UserManager(client);
const user = new User(client, TEST_DATA.USER);
const fetchedUser = await userManager.fetch("123456");
expect(fetchedUser).to.deep.equal(user);
});
it("should call makeRequest with the correct arguments", async function () {
const client = TEST_CLIENTS.ALL_CACHES_ENABLED();
const userManager = new UserManager(client);
const request = spy(client.request, "makeRequest");
await userManager.fetch("123456");
expect(request).to.be.calledOnce;
expect(request).to.be.calledOnceWith("getUser", ["123456"]);
expect(request.firstCall.args[2]).to.be.undefined;
});
it("should throw an error if userId is not a string", async function () {
const client = TEST_CLIENTS.ALL_CACHES_ENABLED();
const userManager = new UserManager(client);
await expect(userManager.fetch(123456)).to.be.rejectedWith(
TypeError,
"GLUON: User ID must be a string.",
);
});
});
});

0 comments on commit e812e92

Please sign in to comment.