-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add delete dialog tests (#1109)
- Loading branch information
Showing
2 changed files
with
88 additions
and
5 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...n.Application.Integration.Tests/Features/V1/EndUser/Dialogs/Queries/DeletedDialogTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Net; | ||
using Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Dialogs.Queries.Get; | ||
using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Commands.Delete; | ||
using Digdir.Domain.Dialogporten.Application.Integration.Tests.Common; | ||
using Digdir.Tool.Dialogporten.GenerateFakeData; | ||
using FluentAssertions; | ||
|
||
namespace Digdir.Domain.Dialogporten.Application.Integration.Tests.Features.V1.EndUser.Dialogs.Queries; | ||
|
||
[Collection(nameof(DialogCqrsCollectionFixture))] | ||
public class DeletedDialogTests(DialogApplication application) : ApplicationCollectionFixture(application) | ||
{ | ||
[Fact] | ||
public async Task Fetching_Deleted_Dialog_Should_Return_Gone() | ||
{ | ||
// Arrange | ||
var createDialogCommand = DialogGenerator.GenerateSimpleFakeDialog(); | ||
var createDialogResponse = await Application.Send(createDialogCommand); | ||
|
||
var dialogId = createDialogResponse.AsT0.Value; | ||
var deleteDialogCommand = new DeleteDialogCommand { Id = dialogId }; | ||
await Application.Send(deleteDialogCommand); | ||
|
||
// Act | ||
var getDialogQuery = new GetDialogQuery { DialogId = dialogId }; | ||
var getDialogResponse = await Application.Send(getDialogQuery); | ||
|
||
// Assert | ||
getDialogResponse.TryPickT2(out var entityDeleted, out _).Should().BeTrue(); | ||
entityDeleted.Should().NotBeNull(); | ||
entityDeleted.Message.Should().Contain("is removed"); | ||
entityDeleted.Message.Should().Contain(dialogId.ToString()); | ||
} | ||
} |
59 changes: 54 additions & 5 deletions
59
...lication.Integration.Tests/Features/V1/ServiceOwner/Dialogs/Commands/DeleteDialogTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,62 @@ | ||
using Digdir.Domain.Dialogporten.Application.Integration.Tests.Common; | ||
using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Commands.Delete; | ||
using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Commands.Update; | ||
using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Queries.Get; | ||
using Digdir.Domain.Dialogporten.Application.Integration.Tests.Common; | ||
using Digdir.Tool.Dialogporten.GenerateFakeData; | ||
using FluentAssertions; | ||
|
||
namespace Digdir.Domain.Dialogporten.Application.Integration.Tests.Features.V1.ServiceOwner.Dialogs.Commands; | ||
|
||
[Collection(nameof(DialogCqrsCollectionFixture))] | ||
public class DeleteDialogTests : ApplicationCollectionFixture | ||
public class DeleteDialogTests(DialogApplication application) : ApplicationCollectionFixture(application) | ||
{ | ||
public DeleteDialogTests(DialogApplication application) : base(application) | ||
[Fact] | ||
public async Task Deleting_Dialog_Should_Set_DeletedAt() | ||
{ | ||
// Arrange | ||
var createDialogCommand = DialogGenerator.GenerateSimpleFakeDialog(); | ||
var createDialogResponse = await Application.Send(createDialogCommand); | ||
|
||
// Act | ||
var dialogId = createDialogResponse.AsT0.Value; | ||
var deleteDialogCommand = new DeleteDialogCommand { Id = dialogId }; | ||
await Application.Send(deleteDialogCommand); | ||
|
||
var getDialogQuery = new GetDialogQuery { DialogId = dialogId }; | ||
var getDialogResponse = await Application.Send(getDialogQuery); | ||
|
||
// Assert | ||
getDialogResponse.TryPickT0(out var dialog, out _).Should().BeTrue(); | ||
dialog.Should().NotBeNull(); | ||
dialog.DeletedAt.Should().BeCloseTo(DateTimeOffset.UtcNow, precision: TimeSpan.FromSeconds(1)); | ||
} | ||
// TODO: Add tests | ||
} | ||
|
||
[Fact] | ||
public async Task Updating_Deleted_Dialog_Should_Return_BadRequest() | ||
{ | ||
// Arrange | ||
var createDialogCommand = DialogGenerator.GenerateSimpleFakeDialog(); | ||
var createDialogResponse = await Application.Send(createDialogCommand); | ||
|
||
var dialogId = createDialogResponse.AsT0.Value; | ||
var deleteDialogCommand = new DeleteDialogCommand { Id = dialogId }; | ||
await Application.Send(deleteDialogCommand); | ||
|
||
var getDialogQuery = new GetDialogQuery { DialogId = dialogId }; | ||
var getDialogResponse = await Application.Send(getDialogQuery); | ||
getDialogResponse.TryPickT0(out var dialog, out _).Should().BeTrue(); | ||
|
||
var mapper = Application.GetMapper(); | ||
var updateDialogDto = mapper.Map<UpdateDialogDto>(dialog); | ||
|
||
// Act | ||
var updateDialogCommand = new UpdateDialogCommand { Id = dialogId, Dto = updateDialogDto }; | ||
var updateDialogResponse = await Application.Send(updateDialogCommand); | ||
|
||
// Assert | ||
updateDialogResponse.TryPickT2(out var validationError, out _).Should().BeTrue(); | ||
validationError.Should().NotBeNull(); | ||
validationError.Reasons.Should().Contain(e => e.Contains("cannot be updated")); | ||
validationError.Reasons.Should().Contain(e => e.Contains(dialogId.ToString())); | ||
} | ||
} |