Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: command provenance should be set after idempotency check #335

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public ApproveStreetName ToCommand()
return new ApproveStreetName(
this.MunicipalityPersistentLocalId(),
new PersistentLocalId(StreetNamePersistentLocalId),
CommandProvenance);
Provenance);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public ChangeStreetNameNames ToCommand()
this.MunicipalityPersistentLocalId(),
new PersistentLocalId(StreetNamePersistentLocalId),
names,
CommandProvenance);
Provenance);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public CorrectStreetNameApproval ToCommand()
return new CorrectStreetNameApproval(
this.MunicipalityPersistentLocalId(),
new PersistentLocalId(StreetNamePersistentLocalId),
CommandProvenance);
Provenance);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public CorrectStreetNameHomonymAdditions ToCommand()
new PersistentLocalId(StreetNamePersistentLocalId),
homonymAdditionsToCorrect,
homonymsToRemove,
CommandProvenance);
Provenance);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public CorrectStreetNameNames ToCommand()
this.MunicipalityPersistentLocalId(),
new PersistentLocalId(StreetNamePersistentLocalId),
names,
CommandProvenance);
Provenance);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public CorrectStreetNameRejection ToCommand()
return new CorrectStreetNameRejection(
this.MunicipalityPersistentLocalId(),
new PersistentLocalId(StreetNamePersistentLocalId),
CommandProvenance);
Provenance);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public CorrectStreetNameRetirement ToCommand()
return new CorrectStreetNameRetirement(
this.MunicipalityPersistentLocalId(),
new PersistentLocalId(StreetNamePersistentLocalId),
CommandProvenance);
Provenance);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ProposeStreetName ToCommand()
this.MunicipalityPersistentLocalId(),
names,
PersistentLocalId,
CommandProvenance);
Provenance);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public RejectStreetName ToCommand(PersistentLocalId streetNamePersistentLocalId)
return new RejectStreetName(
this.MunicipalityPersistentLocalId(),
streetNamePersistentLocalId,
CommandProvenance);
Provenance);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public RemoveStreetName ToCommand()
return new RemoveStreetName(
this.MunicipalityPersistentLocalId(),
new PersistentLocalId(StreetNamePersistentLocalId),
CommandProvenance);
Provenance);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public RenameStreetName ToCommand()
this.MunicipalityPersistentLocalId(),
new PersistentLocalId(StreetNamePersistentLocalId),
new PersistentLocalId(identifier.Value),
CommandProvenance);
Provenance);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public RetireStreetName ToCommand(PersistentLocalId streetNamePersistentLocalId)
return new RetireStreetName(
this.MunicipalityPersistentLocalId(),
streetNamePersistentLocalId,
CommandProvenance);
Provenance);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{
using Be.Vlaanderen.Basisregisters.GrAr.Provenance;
using Be.Vlaanderen.Basisregisters.Sqs.Lambda.Requests;
using NodaTime;

public abstract record StreetNameLambdaRequest : SqsLambdaRequest
{
Expand All @@ -14,13 +13,5 @@ protected StreetNameLambdaRequest(
IDictionary<string, object?> metadata)
: base(messageGroupId, ticketId, ifMatchHeaderValue, provenance, metadata)
{ }

protected Provenance CommandProvenance => new Provenance(
SystemClock.Instance.GetCurrentInstant(),
Provenance.Application,
Provenance.Reason,
Provenance.Operator,
Provenance.Modification,
Provenance.Organisation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace StreetNameRegistry.Municipality
{
using System;
using Be.Vlaanderen.Basisregisters.GrAr.Provenance;
using NodaTime;

public sealed class StreetNameProvenanceFactory : IProvenanceFactory<Municipality>
{
Expand All @@ -14,7 +15,13 @@ public Provenance CreateFrom(object provenanceHolder, Municipality aggregate)
throw new InvalidOperationException($"Cannot create provenance from {provenanceHolder.GetType().Name}");
}

return provenance.Provenance;
return new Provenance(
SystemClock.Instance.GetCurrentInstant(),
provenance.Provenance.Application,
provenance.Provenance.Reason,
provenance.Provenance.Operator,
provenance.Provenance.Modification,
provenance.Provenance.Organisation);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace StreetNameRegistry.Tests.AggregateTests.SnapshotTests
using Municipality.Events;
using Newtonsoft.Json;
using Extensions;
using NodaTime;
using Testing;
using Xunit;
using Xunit.Abstractions;
Expand Down Expand Up @@ -69,6 +70,18 @@ public async Task ThenSnapshotWasCreated()
proposeNewStreetName.PersistentLocalId);
((ISetProvenance)newStreetNameWasProposed).SetProvenance(provenance);

Assert(new Scenario()
.Given(_streamId,
municipalityWasImported,
municipalityBecameCurrent,
officialLanguageWasAdded,
officialLanguageWasAdded2,
facilityLanguageWasAdded,
existingStreetNameWasProposed)
.When(proposeNewStreetName)
.Then(new Fact(_streamId,
newStreetNameWasProposed)));

var existingStreetName = new MunicipalityStreetName(o => { });
existingStreetName.Route(existingStreetNameWasProposed);
var newStreetName = new MunicipalityStreetName(o => { });
Expand All @@ -82,33 +95,22 @@ public async Task ThenSnapshotWasCreated()
new List<Language> { Language.English },
new MunicipalityStreetNames
{
existingStreetName,
newStreetName
existingStreetName,
newStreetName
});

Assert(new Scenario()
.Given(_streamId,
municipalityWasImported,
municipalityBecameCurrent,
officialLanguageWasAdded,
officialLanguageWasAdded2,
facilityLanguageWasAdded,
existingStreetNameWasProposed)
.When(proposeNewStreetName)
.Then(new Fact(_streamId,
newStreetNameWasProposed)));

var snapshotStore = (ISnapshotStore)Container.Resolve(typeof(ISnapshotStore));
var latestSnapshot = await snapshotStore.FindLatestSnapshotAsync(_streamId, CancellationToken.None);

latestSnapshot.Should().NotBeNull();
latestSnapshot
.Should()
.BeEquivalentTo(
Build(
expectedSnapshot,
6,
EventSerializerSettings));
var snapshot = JsonConvert.DeserializeObject<MunicipalitySnapshot>(latestSnapshot!.Data, EventSerializerSettings);

snapshot.Should().BeEquivalentTo(expectedSnapshot, options =>
{
options.Excluding(x => x.Path.EndsWith("LastEventHash"));
options.Excluding(x => x.Type == typeof(Instant));
return options;
});
}

private static SnapshotContainer Build(
Expand Down
Loading