# Description Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. - Create a separate moon counter to track how many moons a user has - This is so we can start a user at a specific counter - Added to the list command a counter to specify how many moons aren't being tracked with the bot #300 ## Type of change Please delete options that are not relevant. - [x] New feature (non-breaking change which adds functionality) # How Has This Been Tested? Please describe the tests that you ran to verify the changes. Provide instructions so we can reproduce. Please also list any relevant details to your test configuration. # Checklist - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that provide my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules Reviewed-on: #489 Reviewed-by: VylpesTester <tester@vylpes.com> Co-authored-by: Ethan Lane <ethan@vylpes.com> Co-committed-by: Ethan Lane <ethan@vylpes.com>
65 lines
1.9 KiB
TypeScript
65 lines
1.9 KiB
TypeScript
import AppDataSource from "../../../src/database/dataSources/appDataSource";
|
|
import UserSetting from "../../../src/database/entities/UserSetting";
|
|
|
|
describe("constructor", () => {
|
|
let userSetting: UserSetting;
|
|
|
|
beforeEach(() => {
|
|
userSetting = new UserSetting("userId", "key", "value");
|
|
});
|
|
|
|
test("EXPECT settings to be configured", () => {
|
|
expect(userSetting).toMatchSnapshot({
|
|
Id: expect.any(String),
|
|
WhenCreated: expect.any(Date),
|
|
WhenUpdated: expect.any(Date),
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("UpdateValue", () => {
|
|
let userSetting: UserSetting;
|
|
|
|
beforeEach(() => {
|
|
userSetting = new UserSetting("userId", "key", "value");
|
|
|
|
userSetting.UpdateValue("newValue");
|
|
});
|
|
|
|
test("EXPECT value to be updated", () => {
|
|
expect(userSetting.Value).toBe("newValue");
|
|
});
|
|
});
|
|
|
|
describe("FetchOneByKey", () => {
|
|
let result: UserSetting | null;
|
|
let userSetting: UserSetting;
|
|
|
|
let findOneMock: jest.Mock;
|
|
|
|
beforeEach(async () => {
|
|
userSetting = new UserSetting("userId", "key", "value");
|
|
|
|
findOneMock = jest.fn().mockResolvedValue(userSetting);
|
|
|
|
AppDataSource.getRepository = jest.fn().mockReturnValue({
|
|
findOne: findOneMock,
|
|
});
|
|
|
|
result = await UserSetting.FetchOneByKey("userId", "key");
|
|
});
|
|
|
|
test("EXPECT getRepository to have been called", () => {
|
|
expect(AppDataSource.getRepository).toHaveBeenCalledTimes(1);
|
|
expect(AppDataSource.getRepository).toHaveBeenCalledWith(UserSetting);
|
|
});
|
|
|
|
test("EXPECT repository.findOne to have been called", () => {
|
|
expect(findOneMock).toHaveBeenCalledTimes(1);
|
|
expect(findOneMock).toHaveBeenCalledWith({ where: { UserId: "userId", Key: "key" }, relations: {}});
|
|
})
|
|
|
|
test("EXPECT single entity returned", () => {
|
|
expect(result).toBe(userSetting);
|
|
});
|
|
});
|