Ethan Lane
d7a5472759
# 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. #378 ## 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 provde 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: #402 Reviewed-by: VylpesTester <tester@vylpes.com> Co-authored-by: Ethan Lane <ethan@vylpes.com> Co-committed-by: Ethan Lane <ethan@vylpes.com>
103 lines
2.5 KiB
TypeScript
103 lines
2.5 KiB
TypeScript
import UserEffect from "../../../../src/database/entities/app/UserEffect";
|
|
|
|
let userEffect: UserEffect;
|
|
const now = new Date();
|
|
|
|
beforeEach(() => {
|
|
userEffect = new UserEffect("name", "userId", 1);
|
|
});
|
|
|
|
describe("AddUnused", () => {
|
|
beforeEach(() => {
|
|
userEffect.AddUnused(1);
|
|
});
|
|
|
|
test("EXPECT unused to be the amount more", () => {
|
|
expect(userEffect.Unused).toBe(2);
|
|
});
|
|
});
|
|
|
|
describe("UseEffect", () => {
|
|
describe("GIVEN Unused is 0", () => {
|
|
let result: boolean;
|
|
|
|
beforeEach(() => {
|
|
userEffect.Unused = 0;
|
|
|
|
result = userEffect.UseEffect(now);
|
|
});
|
|
|
|
test("EXPECT false returned", () => {
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
test("EXPECT details not to be changed", () => {
|
|
expect(userEffect.Unused).toBe(0);
|
|
expect(userEffect.WhenExpires).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
describe("GIVEN Unused is greater than 0", () => {
|
|
let result: boolean;
|
|
|
|
beforeEach(() => {
|
|
result = userEffect.UseEffect(now);
|
|
});
|
|
|
|
test("EXPECT true returned", () => {
|
|
expect(result).toBe(true);
|
|
});
|
|
|
|
test("EXPECT Unused to be subtracted by 1", () => {
|
|
expect(userEffect.Unused).toBe(0);
|
|
});
|
|
|
|
test("EXPECT WhenExpires to be set", () => {
|
|
expect(userEffect.WhenExpires).toBe(now);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("IsEffectActive", () => {
|
|
describe("GIVEN WhenExpires is null", () => {
|
|
let result: boolean;
|
|
|
|
beforeEach(() => {
|
|
result = userEffect.IsEffectActive();
|
|
});
|
|
|
|
test("EXPECT false returned", () => {
|
|
expect(result).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("GIVEN WhenExpires is defined", () => {
|
|
describe("AND WhenExpires is in the past", () => {
|
|
let result: boolean;
|
|
|
|
beforeEach(() => {
|
|
userEffect.WhenExpires = new Date(now.getTime() - 100);
|
|
|
|
result = userEffect.IsEffectActive();
|
|
});
|
|
|
|
test("EXPECT false returned", () => {
|
|
expect(result).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("AND WhenExpires is in the future", () => {
|
|
let result: boolean;
|
|
|
|
beforeEach(() => {
|
|
userEffect.WhenExpires = new Date(now.getTime() + 100);
|
|
|
|
result = userEffect.IsEffectActive();
|
|
});
|
|
|
|
test("EXPECT true returned", () => {
|
|
expect(result).toBe(true);
|
|
});
|
|
});
|
|
});
|
|
});
|