Create effects concept #402
1 changed files with 79 additions and 16 deletions
|
@ -1,41 +1,104 @@
|
|||
import AppDataSource from "../../../../src/database/dataSources/appDataSource";
|
||||
import UserEffect from "../../../../src/database/entities/app/UserEffect";
|
||||
|
||||
let userEffect: UserEffect;
|
||||
const now = new Date();
|
||||
|
||||
beforeEach(() => {
|
||||
userEffect = new UserEffect("name", "userId", 1);
|
||||
});
|
||||
|
||||
describe("AddUnused", () => {
|
||||
test.todo("EXPECT unused to be the amount more");
|
||||
beforeEach(() => {
|
||||
userEffect.AddUnused(1);
|
||||
});
|
||||
|
||||
test("EXPECT unused to be the amount more", () => {
|
||||
expect(userEffect.Unused).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("UseEffect", () => {
|
||||
describe("GIVEN Unused is 0", () => {
|
||||
test.todo("EXPECT false returned");
|
||||
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", () => {
|
||||
test.todo("EXPECT true returned");
|
||||
let result: boolean;
|
||||
|
||||
test.todo("EXPECT Unused to be subtracted by 1");
|
||||
beforeEach(() => {
|
||||
result = userEffect.UseEffect(now);
|
||||
});
|
||||
|
||||
test.todo("EXPECT WhenExpires to be set");
|
||||
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", () => {
|
||||
test.todo("EXPECT false returned");
|
||||
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", () => {
|
||||
test.todo("EXPECT false returned");
|
||||
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", () => {
|
||||
test.todo("EXPECT true returned");
|
||||
let result: boolean;
|
||||
|
||||
beforeEach(() => {
|
||||
userEffect.WhenExpires = new Date(now.getTime() + 100);
|
||||
|
||||
result = userEffect.IsEffectActive();
|
||||
});
|
||||
|
||||
test("EXPECT true returned", () => {
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("FetchOneByUserIdAndName", () => {
|
||||
test.todo("EXPECT entity to be returned");
|
||||
|
||||
test.todo("EXPECT AppDataSource.getRepository to have been called");
|
||||
|
||||
test.todo("EXPECT repository.findOne to have been called");
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue