Skip to content

Commit

Permalink
Add WorldId to CreateWorldResponse and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
philgei committed Dec 5, 2023
1 parent 5cf5ff1 commit fafafde
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using AdLerBackend.Application.LMS.GetUserData;
using AdLerBackend.Application.World.WorldManagement.UploadWorld;
using AdLerBackend.Domain.Entities;
using AdLerBackend.Domain.UnitTests.TestingUtils;
using AdLerBackend.Infrastructure.Services;
using AutoBogus;
using MediatR;
Expand All @@ -31,7 +32,8 @@ public class UploadWorldUseCaseTest
[SetUp]
public void Setup()
{
_configuration = Options.Create(new BackendConfig {MoodleUrl = "http://localhost"});
_configuration = Options.Create(new BackendConfig
{MoodleUrl = "http://localhost", AdLerEngineUrl = "http://localhost"});

_lmsBackupProcessor = Substitute.For<ILmsBackupProcessor>();
_mediator = Substitute.For<IMediator>();
Expand Down Expand Up @@ -89,6 +91,9 @@ public async Task Handle_Valid_TriggersUpload()
ElementUuid = "path1"
};

_worldRepository.AddAsync(Arg.Any<WorldEntity>())
.Returns(WorldEntityFactory.CreateWorldEntity(id: 1));

_lmsBackupProcessor.GetWorldDescriptionFromBackup(Arg.Any<Stream>()).Returns(fakedDsl);

_lmsBackupProcessor.GetH5PFilesFromBackup(Arg.Any<Stream>()).Returns(new List<H5PDto>
Expand Down Expand Up @@ -118,7 +123,7 @@ public async Task Handle_Valid_TriggersUpload()
atfStream.Position = 0;

// Act
await systemUnderTest.Handle(new UploadWorldCommand
var result = await systemUnderTest.Handle(new UploadWorldCommand
{
BackupFileStream = new MemoryStream(),
ATFFileStream = atfStream,
Expand All @@ -128,6 +133,11 @@ await systemUnderTest.Handle(new UploadWorldCommand
// Assert that AddAsync has been called with the Correct entity
await _worldRepository.Received(1)
.AddAsync(Arg.Is<WorldEntity>(x => x.Name == "TESTNAME"));

Assert.That(result, Is.Not.Null);
Assert.That(result.WorldId, Is.EqualTo(1));
Assert.That(result.World3DUrl, Is.EqualTo("http://localhost"));
Assert.That(result.WorldLmsUrl, Is.EqualTo("http://localhost/course/view.php?id=1337"));
}


Expand All @@ -146,6 +156,9 @@ public async Task Handle_ValidNoH5p_TriggersUpload()
UserId = 1337
});

_worldRepository.AddAsync(Arg.Any<WorldEntity>())
.Returns(WorldEntityFactory.CreateWorldEntity(id: 1));

var fakedDsl = AutoFaker.Generate<WorldAtfResponse>();

_ilms.UploadCourseWorldToLMS(Arg.Any<string>(), Arg.Any<Stream>()).Returns(new LMSCourseCreationResponse
Expand All @@ -166,7 +179,7 @@ public async Task Handle_ValidNoH5p_TriggersUpload()


// Act
await systemUnderTest.Handle(new UploadWorldCommand
var result = await systemUnderTest.Handle(new UploadWorldCommand
{
BackupFileStream = new MemoryStream(),
ATFFileStream = new MemoryStream(),
Expand All @@ -176,5 +189,10 @@ await systemUnderTest.Handle(new UploadWorldCommand
// Assert that AddAsync has been called with the Correct entity
await _worldRepository.Received(1)
.AddAsync(Arg.Is<WorldEntity>(x => x.Name == "TESTNAME"));

Assert.That(result, Is.Not.Null);
Assert.That(result.WorldId, Is.EqualTo(1));
Assert.That(result.World3DUrl, Is.EqualTo("http://localhost"));
Assert.That(result.WorldLmsUrl, Is.EqualTo("http://localhost/course/view.php?id=1337"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public class CreateWorldResponse
{
public int WorldId { get; set; }
public string WorldNameInLms { get; set; }

Check warning on line 6 in AdLerBackend.Application/Common/Responses/World/CreateWorldResponse.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04)

Non-nullable property 'WorldNameInLms' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 6 in AdLerBackend.Application/Common/Responses/World/CreateWorldResponse.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Non-nullable property 'WorldNameInLms' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 6 in AdLerBackend.Application/Common/Responses/World/CreateWorldResponse.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Non-nullable property 'WorldNameInLms' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 6 in AdLerBackend.Application/Common/Responses/World/CreateWorldResponse.cs

View workflow job for this annotation

GitHub Actions / test (ubuntu-20.04)

Non-nullable property 'WorldNameInLms' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 6 in AdLerBackend.Application/Common/Responses/World/CreateWorldResponse.cs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

Non-nullable property 'WorldNameInLms' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 6 in AdLerBackend.Application/Common/Responses/World/CreateWorldResponse.cs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

Non-nullable property 'WorldNameInLms' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public string WorldLmsUrl { get; set; }

Check warning on line 7 in AdLerBackend.Application/Common/Responses/World/CreateWorldResponse.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04)

Non-nullable property 'WorldLmsUrl' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 7 in AdLerBackend.Application/Common/Responses/World/CreateWorldResponse.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Non-nullable property 'WorldLmsUrl' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 7 in AdLerBackend.Application/Common/Responses/World/CreateWorldResponse.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Non-nullable property 'WorldLmsUrl' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 7 in AdLerBackend.Application/Common/Responses/World/CreateWorldResponse.cs

View workflow job for this annotation

GitHub Actions / test (ubuntu-20.04)

Non-nullable property 'WorldLmsUrl' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 7 in AdLerBackend.Application/Common/Responses/World/CreateWorldResponse.cs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

Non-nullable property 'WorldLmsUrl' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 7 in AdLerBackend.Application/Common/Responses/World/CreateWorldResponse.cs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

Non-nullable property 'WorldLmsUrl' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public string World3DUrl { get; set; } = "Coming soon :)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ public async Task<CreateWorldResponse> Handle(UploadWorldCommand request, Cancel
lmsCourseCreationResponse.CourseLmsId
);

await _worldRepository.AddAsync(courseEntity);
var createdEntity = await _worldRepository.AddAsync(courseEntity);

return new CreateWorldResponse
{
// When the world is created, the id is set
WorldId = createdEntity.Id!.Value,
World3DUrl = _configuration.AdLerEngineUrl ?? "Adler Engine URL not set",
WorldLmsUrl = _configuration.MoodleUrl + "/course/view.php?id=" + lmsCourseCreationResponse.CourseLmsId,
WorldNameInLms = courseEntity.Name
Expand Down

0 comments on commit fafafde

Please sign in to comment.