Skip to content

Commit

Permalink
Added tryToPreventOrphanSeats flag when selecting best available obje…
Browse files Browse the repository at this point in the history
…cts (#81)

* Added tryToPreventOrphanSeats flag when selecting best available objects

* Fixed tests
  • Loading branch information
mroloux authored May 8, 2023
1 parent 2f5eca7 commit f2f81bd
Show file tree
Hide file tree
Showing 4 changed files with 398 additions and 118 deletions.
58 changes: 35 additions & 23 deletions SeatsioDotNet.Test/Events/ChangeBestAvailableObjectStatusTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void Number()
var bestAvailableResult = Client.Events.ChangeObjectStatus(evnt.Key, new BestAvailable(3), "foo");

Assert.True(bestAvailableResult.NextToEachOther);
Assert.Equal(new[] {"B-4", "B-5", "B-6"}, bestAvailableResult.Objects);
Assert.Equal(new[] {"A-4", "A-5", "A-6"}, bestAvailableResult.Objects);
}

[Fact]
Expand All @@ -27,10 +27,10 @@ public void ObjectDetails()

var bestAvailableResult = Client.Events.ChangeObjectStatus(evnt.Key, new BestAvailable(2), "foo");

var reportItem = bestAvailableResult.ObjectDetails["B-4"];
Assert.Equal("B-4", reportItem.Label);
reportItem.Labels.Should().BeEquivalentTo(new Labels("4", "seat", "B", "row"));
reportItem.IDs.Should().BeEquivalentTo(new IDs("4", "B", null));
var reportItem = bestAvailableResult.ObjectDetails["A-4"];
Assert.Equal("A-4", reportItem.Label);
reportItem.Labels.Should().BeEquivalentTo(new Labels("4", "seat", "A", "row"));
reportItem.IDs.Should().BeEquivalentTo(new IDs("4", "A", null));
Assert.Equal("foo", reportItem.Status);
Assert.Equal("Cat1", reportItem.CategoryLabel);
Assert.Equal("9", reportItem.CategoryKey);
Expand All @@ -42,8 +42,8 @@ public void ObjectDetails()
Assert.Null(reportItem.Entrance);
Assert.Null(reportItem.NumBooked);
Assert.Null(reportItem.Capacity);
Assert.Equal("B-3", reportItem.LeftNeighbour);
Assert.Equal("B-5", reportItem.RightNeighbour);
Assert.Equal("A-3", reportItem.LeftNeighbour);
Assert.Equal("A-5", reportItem.RightNeighbour);
}

[Fact]
Expand Down Expand Up @@ -71,9 +71,21 @@ public void ExtraData()

var bestAvailableResult = Client.Events.ChangeObjectStatus(evnt.Key, new BestAvailable(2, extraData: extraData), "foo");

Assert.Equal(new[] {"B-4", "B-5"}, bestAvailableResult.Objects);
Assert.Equal(new Dictionary<string, object> {{"foo", "bar"}}, Client.Events.RetrieveObjectInfo(evnt.Key, "B-4").ExtraData);
Assert.Equal(new Dictionary<string, object> {{"foo", "baz"}}, Client.Events.RetrieveObjectInfo(evnt.Key, "B-5").ExtraData);
Assert.Equal(new[] {"A-4", "A-5"}, bestAvailableResult.Objects);
Assert.Equal(new Dictionary<string, object> {{"foo", "bar"}}, Client.Events.RetrieveObjectInfo(evnt.Key, "A-4").ExtraData);
Assert.Equal(new Dictionary<string, object> {{"foo", "baz"}}, Client.Events.RetrieveObjectInfo(evnt.Key, "A-5").ExtraData);
}

[Fact]
public void DoNotTryToPreventOrphanSeats()
{
var chartKey = CreateTestChart();
var evnt = Client.Events.Create(chartKey);
Client.Events.Book(evnt.Key, new[] {"A-4", "A-5"});

var bestAvailableResult = Client.Events.ChangeObjectStatus(evnt.Key, new BestAvailable(2, tryToPreventOrphanSeats: false), "foo");

Assert.Equal(new[] {"A-2", "A-3"}, bestAvailableResult.Objects);
}

[Fact]
Expand All @@ -89,9 +101,9 @@ public void TicketTypes()

var bestAvailableResult = Client.Events.ChangeObjectStatus(evnt.Key, new BestAvailable(2, ticketTypes: new[]{"adult", "child"}), "foo");

Assert.Equal(new[] {"B-4", "B-5"}, bestAvailableResult.Objects);
Assert.Equal("adult", Client.Events.RetrieveObjectInfo(evnt.Key, "B-4").TicketType);
Assert.Equal("child", Client.Events.RetrieveObjectInfo(evnt.Key, "B-5").TicketType);
Assert.Equal(new[] {"A-4", "A-5"}, bestAvailableResult.Objects);
Assert.Equal("adult", Client.Events.RetrieveObjectInfo(evnt.Key, "A-4").TicketType);
Assert.Equal("child", Client.Events.RetrieveObjectInfo(evnt.Key, "A-5").TicketType);
}

[Fact]
Expand All @@ -100,11 +112,11 @@ public void KeepExtraDataTrue()
var chartKey = CreateTestChart();
var evnt = Client.Events.Create(chartKey);
var extraData = new Dictionary<string, object> {{"foo1", "bar1"}};
Client.Events.UpdateExtraData(evnt.Key, "B-5", extraData);
Client.Events.UpdateExtraData(evnt.Key, "A-5", extraData);

Client.Events.ChangeObjectStatus(evnt.Key, new BestAvailable(1), "someStatus", null, null, true);

Assert.Equal(extraData, Client.Events.RetrieveObjectInfo(evnt.Key, "B-5").ExtraData);
Assert.Equal(extraData, Client.Events.RetrieveObjectInfo(evnt.Key, "A-5").ExtraData);
}

[Fact]
Expand All @@ -113,11 +125,11 @@ public void KeepExtraDataFalse()
var chartKey = CreateTestChart();
var evnt = Client.Events.Create(chartKey);
var extraData = new Dictionary<string, object> {{"foo1", "bar1"}};
Client.Events.UpdateExtraData(evnt.Key, "B-5", extraData);
Client.Events.UpdateExtraData(evnt.Key, "A-5", extraData);

Client.Events.ChangeObjectStatus(evnt.Key, new BestAvailable(1), "someStatus", null, null, false);

Assert.Null(Client.Events.RetrieveObjectInfo(evnt.Key, "B-5").ExtraData);
Assert.Null(Client.Events.RetrieveObjectInfo(evnt.Key, "A-5").ExtraData);
}

[Fact]
Expand All @@ -126,11 +138,11 @@ public void NoKeepExtraData()
var chartKey = CreateTestChart();
var evnt = Client.Events.Create(chartKey);
var extraData = new Dictionary<string, object> {{"foo1", "bar1"}};
Client.Events.UpdateExtraData(evnt.Key, "B-5", extraData);
Client.Events.UpdateExtraData(evnt.Key, "A-5", extraData);

Client.Events.ChangeObjectStatus(evnt.Key, new BestAvailable(1), "someStatus");

Assert.Null(Client.Events.RetrieveObjectInfo(evnt.Key, "B-5").ExtraData);
Assert.Null(Client.Events.RetrieveObjectInfo(evnt.Key, "A-5").ExtraData);
}

[Fact]
Expand All @@ -145,12 +157,12 @@ public void ChannelKeys()
Client.Events.Channels.Replace(evnt.Key, channels);
Client.Events.Channels.SetObjects(evnt.Key, new
{
channelKey1 = new[] {"B-6"}
channelKey1 = new[] {"A-6"}
});

var bestAvailableResult = Client.Events.ChangeObjectStatus(evnt.Key, new BestAvailable(1), "someStatus", channelKeys: new[] {"channelKey1"});

Assert.Equal(new[] {"B-6"}, bestAvailableResult.Objects);
Assert.Equal(new[] {"A-6"}, bestAvailableResult.Objects);
}

[Fact]
Expand All @@ -165,12 +177,12 @@ public void IgnoreChannels()
Client.Events.Channels.Replace(evnt.Key, channels);
Client.Events.Channels.SetObjects(evnt.Key, new
{
channelKey1 = new[] {"B-5"}
channelKey1 = new[] {"A-5"}
});

var bestAvailableResult = Client.Events.ChangeObjectStatus(evnt.Key, new BestAvailable(1), "someStatus", ignoreChannels: true);

Assert.Equal(new[] {"B-5"}, bestAvailableResult.Objects);
Assert.Equal(new[] {"A-5"}, bestAvailableResult.Objects);
}
}
}
4 changes: 2 additions & 2 deletions SeatsioDotNet.Test/Events/HoldObjectsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public void BestAvailable()
var bestAvailableResult = Client.Events.Hold(evnt.Key, new BestAvailable(3), holdToken.Token, "order1");

Assert.True(bestAvailableResult.NextToEachOther);
Assert.Equal(new[] {"B-4", "B-5", "B-6"}, bestAvailableResult.Objects);
Assert.Equal("order1", Client.Events.RetrieveObjectInfo(evnt.Key, "B-4").OrderId);
Assert.Equal(new[] {"A-4", "A-5", "A-6"}, bestAvailableResult.Objects);
Assert.Equal("order1", Client.Events.RetrieveObjectInfo(evnt.Key, "A-4").OrderId);
}

[Fact]
Expand Down
Loading

0 comments on commit f2f81bd

Please sign in to comment.