Skip to content

Commit

Permalink
test: Add Remove installed kitchen equipment action tests
Browse files Browse the repository at this point in the history
  • Loading branch information
upa-r-upa committed Apr 15, 2024
1 parent 142af6e commit 26e2119
Showing 1 changed file with 106 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
namespace Savor22b.Tests.Action;

using System;
using System.Collections.Immutable;
using Libplanet.State;
using Savor22b.Action;
using Savor22b.Action.Exceptions;
using Savor22b.Model;
using Savor22b.States;
using Xunit;

public class RemoveInstalledKitchenEquipmentActionTests : ActionTests
{
public RemoveInstalledKitchenEquipmentActionTests() { }

private readonly Guid EquipmentStateId = new();

[Fact]
public void Execute_Success_Normal()
{
IAccountStateDelta beforeState = new DummyState();
RootState beforeRootState = new RootState(
new InventoryState(
ImmutableList<SeedState>.Empty,
ImmutableList<RefrigeratorState>.Empty,
ImmutableList<KitchenEquipmentState>.Empty.Add(
new KitchenEquipmentState(EquipmentStateId, 1, 1)
),
ImmutableList<ItemState>.Empty
),
new UserDungeonState(),
new VillageState(new HouseState(1, 1, 1, new KitchenState()))
);
beforeRootState.VillageState!.HouseState.KitchenState.InstallKitchenEquipment(
new KitchenEquipmentState(EquipmentStateId, 1, 1),
1
);

beforeState = beforeState.SetState(SignerAddress(), beforeRootState.Serialize());

var action = new RemoveInstalledKitchenEquipmentAction(
beforeRootState.InventoryState.KitchenEquipmentStateList[0].StateID
);

var afterState = action.Execute(
new DummyActionContext
{
PreviousStates = beforeState,
Signer = SignerAddress(),
Random = random,
Rehearsal = false,
BlockIndex = 1,
}
);

var afterRootStateEncoded = afterState.GetState(SignerAddress());
RootState afterRootState = afterRootStateEncoded is Bencodex.Types.Dictionary bdict
? new RootState(bdict)
: throw new Exception();

Assert.Null(
afterRootState
.VillageState!
.HouseState
.KitchenState
.FirstApplianceSpace
.InstalledKitchenEquipmentStateId
);
Assert.Single(afterRootState.InventoryState.KitchenEquipmentStateList);
}

[Fact]
public void Execute_Failure_NotInstalledKitchenEquipment()
{
IAccountStateDelta beforeState = new DummyState();

RootState beforeRootState = new RootState(
new InventoryState(
ImmutableList<SeedState>.Empty,
ImmutableList<RefrigeratorState>.Empty,
ImmutableList<KitchenEquipmentState>.Empty,
ImmutableList<ItemState>.Empty
),
new UserDungeonState(),
new VillageState(new HouseState(1, 1, 1, new KitchenState()))
);

beforeState = beforeState.SetState(SignerAddress(), beforeRootState.Serialize());

var action = new RemoveInstalledKitchenEquipmentAction(Guid.NewGuid());

Assert.Throws<InvalidValueException>(() =>
{
action.Execute(
new DummyActionContext
{
PreviousStates = beforeState,
Signer = SignerAddress(),
Random = random,
Rehearsal = false,
BlockIndex = 1,
}
);
});
}
}

0 comments on commit 26e2119

Please sign in to comment.