Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mountler committed Feb 19, 2024
1 parent 747e77f commit 7098e29
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { async } from "q";
import DisplayLearningElementUseCase from "../../../../../Core/Application/UseCases/Adaptivity/DisplayLearningElementUseCase/DisplayLearningElementUseCase";
import DisplayLearningElementUseCase from "../../../../../Core/Application/UseCases/Adaptivity/DisplayAdaptivityHintLearningElement/DisplayAdaptivityHintLearningElementUseCase";
import CoreDIContainer from "../../../../../Core/DependencyInjection/CoreDIContainer";
import mock from "jest-mock-extended/lib/Mock";
import CORE_TYPES from "../../../../../Core/DependencyInjection/CoreTypes";
Expand All @@ -16,6 +16,7 @@ import { AdaptivityElementActionTypes } from "../../../../../Core/Domain/Types/A
import ICalculateLearningSpaceAvailabilityUseCase from "../../../../../Core/Application/UseCases/CalculateLearningSpaceAvailability/ICalculateLearningSpaceAvailabilityUseCase";
import LearningSpaceAvailabilityTO from "../../../../../Core/Application/DataTransferObjects/LearningSpaceAvailabilityTO";
import ILoadLearningElementUseCase from "../../../../../Core/Application/UseCases/LoadLearningElement/ILoadLearningElementUseCase";
import { LearningElementModelTypeEnums } from "../../../../../Core/Domain/LearningElementModels/LearningElementModelTypes";

const entityContainer = mock<IEntityContainer>();
const getUserLocationUseCaseMock = mock<IGetUserLocationUseCase>();
Expand Down Expand Up @@ -59,67 +60,95 @@ describe("DisplayLearningElementUseCase", () => {
systemUnderTest = CoreDIContainer.resolve(DisplayLearningElementUseCase);
});

test("should throw, if no space space is found", async () => {
entityContainer.getEntitiesOfType.mockReturnValue([]);
test("should throw, if user is not in space", async () => {
getUserLocationUseCaseMock.execute.mockReturnValue({
worldID: undefined,
spaceID: undefined,
} as UserLocationTO);

await expect(systemUnderTest.executeAsync(1)).rejects.toThrow(
`Could not find space in which external learning element is.`
`User not in a space!`
);
});

test("should throw, if no element is found", async () => {
entityContainer.getEntitiesOfType.mockReturnValue([
{ id: 0, elements: [{ id: 1 }] } as LearningSpaceEntity,
]);
entityContainer.filterEntitiesOfType.mockReturnValue([]);
getUserLocationUseCaseMock.execute.mockReturnValue({
worldID: 1,
spaceID: undefined,
} as UserLocationTO);

await expect(systemUnderTest.executeAsync(1)).rejects.toThrow(
"Could not find external element."
`User not in a space!`
);
});

test("should throw, if user is not in space", async () => {
entityContainer.getEntitiesOfType.mockReturnValue([
{ id: 0, elements: [{ id: 1 }] } as LearningSpaceEntity,
]);

entityContainer.filterEntitiesOfType.mockReturnValue([
{ id: 3 } as LearningElementEntity,
]);

getUserLocationUseCaseMock.execute.mockReturnValue({
worldID: undefined,
spaceID: undefined,
spaceID: 1,
} as UserLocationTO);

await expect(systemUnderTest.executeAsync(1)).rejects.toThrow(
`User not in a space!`
);
});

test("should throw, if no space space is found", async () => {
getUserLocationUseCaseMock.execute.mockReturnValue({
worldID: 1,
spaceID: undefined,
spaceID: 1,
} as UserLocationTO);

entityContainer.filterEntitiesOfType.mockReturnValue([]);

await expect(systemUnderTest.executeAsync(1)).rejects.toThrow(
`User not in a space!`
`Could not find space for currently active learning world.`
);
});

test("learning element in same space calls onAdaptivityElementUserHintInformed", async () => {
entityContainer.getEntitiesOfType.mockReturnValue([
{ id: 1, elements: [{ id: 1 }] } as LearningSpaceEntity,
]);
test("should throw, if no element is found", async () => {
getUserLocationUseCaseMock.execute.mockReturnValue({
worldID: 1,
spaceID: 1,
} as UserLocationTO);

entityContainer.filterEntitiesOfType.mockReturnValue([
{ id: 1, name: "test" } as LearningElementEntity,
entityContainer.filterEntitiesOfType.mockReturnValueOnce([
{ id: 0, elements: [{ id: 1 }] } as LearningSpaceEntity,
]);

entityContainer.filterEntitiesOfType.mockReturnValueOnce([]);

await expect(systemUnderTest.executeAsync(1)).rejects.toThrow(
"Could not find referenced learning element."
);
});

test("learning element in same space calls onAdaptivityElementUserHintInformed", async () => {
getUserLocationUseCaseMock.execute.mockReturnValue({
worldID: 1,
spaceID: 1,
} as UserLocationTO);

entityContainer.filterEntitiesOfType.mockReturnValueOnce([
{
id: 1,
elements: [
{
id: 1,
value: 3,
hasScored: false,
name: "",
description: "",
goals: [],
type: "text",
model:
LearningElementModelTypeEnums.TextElementModelTypes.Bookshelf1,
parentWorldID: 1,
},
] as LearningElementEntity[],
} as LearningSpaceEntity,
]);

entityContainer.filterEntitiesOfType.mockReturnValueOnce([
{ id: 1, name: "test" } as LearningElementEntity,
]);

await systemUnderTest.executeAsync(1);

expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ISubmitAdaptivityElementSelectionUseCase from "../../../../Core/Applicati
import ILearningWorldPort from "../../../../Core/Application/Ports/Interfaces/ILearningWorldPort";
import PORT_TYPES from "../../../../Core/DependencyInjection/Ports/PORT_TYPES";
import { AdaptivityElementActionTypes } from "../../../../Core/Domain/Types/Adaptivity/AdaptivityElementActionTypes";
import IDisplayLearningElementUseCase from "../../../../Core/Application/UseCases/Adaptivity/DisplayLearningElementUseCase/IDisplayLearningElementUseCase";
import IDisplayLearningElementUseCase from "../../../../Core/Application/UseCases/Adaptivity/DisplayAdaptivityHintLearningElement/IDisplayAdaptivityHintLearningElementUseCase";
import PRESENTATION_TYPES from "../../../../Core/DependencyInjection/Presentation/PRESENTATION_TYPES";

const submitSelectionUseCaseMock =
Expand Down Expand Up @@ -73,7 +73,7 @@ describe("AdaptivityElementController", () => {
worldPortMock
);
CoreDIContainer.rebind(
USECASE_TYPES.IDisplayLearningElementUseCase
USECASE_TYPES.IDisplayAdaptivityHintLearningElementUseCase
).toConstantValue(displayLearningElmentUseCaseMock);
CoreDIContainer.bind(
PRESENTATION_TYPES.IBottomTooltipPresenter
Expand Down

0 comments on commit 7098e29

Please sign in to comment.