Skip to content

Commit

Permalink
Merge branch 'eventual-eventing' into items
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeFZ authored Jul 23, 2023
2 parents b2144f3 + e882aca commit 57182fa
Show file tree
Hide file tree
Showing 9 changed files with 337 additions and 128 deletions.
69 changes: 69 additions & 0 deletions DragaliaAPI.Integration.Test/Features/Event/Clb01EventTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using DragaliaAPI.Database.Entities;
using DragaliaAPI.Models;
using DragaliaAPI.Models.Generated;
using DragaliaAPI.Shared.Definitions.Enums.EventItemTypes;
using Microsoft.EntityFrameworkCore;

namespace DragaliaAPI.Integration.Test.Features.Event;

public class Clb01EventTest : TestFixture
{
public Clb01EventTest(
CustomWebApplicationFactory<Program> factory,
ITestOutputHelper outputHelper
)
: base(factory, outputHelper) { }

private const int EventId = 21401;
private const string Prefix = "clb01_event";

[Fact]
public async Task GetEventData_ReturnsEventData()
{
await Client.PostMsgpack<MemoryEventActivateData>(
"memory_event/activate",
new MemoryEventActivateRequest(EventId)
);

DragaliaResponse<Clb01EventGetEventDataData> evtData =
await Client.PostMsgpack<Clb01EventGetEventDataData>(
$"{Prefix}/get_event_data",
new Clb01EventGetEventDataRequest(EventId)
);

evtData.data.clb_01_event_user_data.Should().NotBeNull();
evtData.data.clb_01_event_reward_list.Should().NotBeNull();
}

[Fact]
public async Task ReceiveEventRewards_ReturnsEventRewards()
{
await Client.PostMsgpack<MemoryEventActivateData>(
"memory_event/activate",
new MemoryEventActivateRequest(EventId)
);

DbPlayerEventItem pointItem = await ApiContext.PlayerEventItems.SingleAsync(
x => x.EventId == EventId && x.Type == (int)Clb01EventItemType.Clb01EventPoint
);

pointItem.Quantity += 500;

ApiContext.PlayerEventRewards.RemoveRange(
ApiContext.PlayerEventRewards.Where(x => x.EventId == EventId)
);

await ApiContext.SaveChangesAsync();

DragaliaResponse<Clb01EventReceiveClb01PointRewardData> evtResp =
await Client.PostMsgpack<Clb01EventReceiveClb01PointRewardData>(
$"{Prefix}/receive_clb01_point_reward",
new Clb01EventReceiveClb01PointRewardRequest(EventId)
);

evtResp.data.clb_01_event_reward_entity_list.Should().NotBeNullOrEmpty();
evtResp.data.clb_01_event_reward_list.Should().NotBeNullOrEmpty();
evtResp.data.entity_result.Should().NotBeNull();
evtResp.data.update_data_list.Should().NotBeNull();
}
}
111 changes: 111 additions & 0 deletions DragaliaAPI.Integration.Test/Features/Event/CombatEventTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using DragaliaAPI.Database.Entities;
using DragaliaAPI.Models;
using DragaliaAPI.Models.Generated;
using DragaliaAPI.Shared.Definitions.Enums.EventItemTypes;
using Microsoft.EntityFrameworkCore;

namespace DragaliaAPI.Integration.Test.Features.Event;

public class CombatEventTest : TestFixture
{
public CombatEventTest(
CustomWebApplicationFactory<Program> factory,
ITestOutputHelper outputHelper
)
: base(factory, outputHelper) { }

private const int EventId = 22213;
private const string Prefix = "combat_event";

[Fact]
public async Task GetEventData_ReturnsEventData()
{
await Client.PostMsgpack<MemoryEventActivateData>(
"memory_event/activate",
new MemoryEventActivateRequest(EventId)
);

DragaliaResponse<CombatEventGetEventDataData> evtData =
await Client.PostMsgpack<CombatEventGetEventDataData>(
$"{Prefix}/get_event_data",
new CombatEventGetEventDataRequest(EventId)
);

evtData.data.combat_event_user_data.Should().NotBeNull();
evtData.data.user_event_location_reward_list.Should().NotBeNull();
evtData.data.event_reward_list.Should().NotBeNull();
evtData.data.event_trade_list.Should().NotBeNull();
}

[Fact]
public async Task ReceiveEventRewards_ReturnsEventRewards()
{
await Client.PostMsgpack<MemoryEventActivateData>(
"memory_event/activate",
new MemoryEventActivateRequest(EventId)
);

DbPlayerEventItem pointItem = await ApiContext.PlayerEventItems.SingleAsync(
x => x.EventId == EventId && x.Type == (int)Clb01EventItemType.Clb01EventPoint
);

pointItem.Quantity += 500;

ApiContext.PlayerEventRewards.RemoveRange(
ApiContext.PlayerEventRewards.Where(x => x.EventId == EventId)
);

await ApiContext.SaveChangesAsync();

DragaliaResponse<CombatEventReceiveEventPointRewardData> evtResp =
await Client.PostMsgpack<CombatEventReceiveEventPointRewardData>(
$"{Prefix}/receive_event_point_reward",
new CombatEventReceiveEventPointRewardRequest(EventId)
);

evtResp.data.event_reward_entity_list.Should().NotBeNullOrEmpty();
evtResp.data.event_reward_list.Should().NotBeNullOrEmpty();
evtResp.data.entity_result.Should().NotBeNull();
evtResp.data.update_data_list.Should().NotBeNull();
}

[Fact]
public async Task ReceiveEventLocationRewards_ReturnsEventLocationRewards()
{
await Client.PostMsgpack<MemoryEventActivateData>(
"memory_event/activate",
new MemoryEventActivateRequest(EventId)
);

DbPlayerEventItem pointItem = await ApiContext.PlayerEventItems.SingleAsync(
x => x.EventId == EventId && x.Type == (int)Clb01EventItemType.Clb01EventPoint
);

pointItem.Quantity += 500;

ApiContext.PlayerQuests.RemoveRange(
ApiContext.PlayerQuests.Where(x => x.DeviceAccountId == DeviceAccountId)
);

ApiContext.PlayerQuests.Add(
new DbQuest
{
DeviceAccountId = DeviceAccountId,
QuestId = 222130103,
State = 3
}
);

await ApiContext.SaveChangesAsync();

DragaliaResponse<CombatEventReceiveEventLocationRewardData> evtResp =
await Client.PostMsgpack<CombatEventReceiveEventLocationRewardData>(
$"{Prefix}/receive_event_location_reward",
new CombatEventReceiveEventLocationRewardRequest(EventId, 2221302)
);

evtResp.data.event_location_reward_entity_list.Should().NotBeNullOrEmpty();
evtResp.data.user_event_location_reward_list.Should().NotBeNullOrEmpty();
evtResp.data.update_data_list.Should().NotBeNull();
}
}
68 changes: 68 additions & 0 deletions DragaliaAPI.Integration.Test/Features/Event/RaidEventTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using DragaliaAPI.Database.Entities;
using DragaliaAPI.Models;
using DragaliaAPI.Models.Generated;
using DragaliaAPI.Shared.Definitions.Enums.EventItemTypes;
using Microsoft.EntityFrameworkCore;

namespace DragaliaAPI.Integration.Test.Features.Event;

public class RaidEventTest : TestFixture
{
public RaidEventTest(
CustomWebApplicationFactory<Program> factory,
ITestOutputHelper outputHelper
)
: base(factory, outputHelper) { }

private const int EventId = 20455;
private const string Prefix = "raid_event";

[Fact]
public async Task GetEventData_ReturnsEventData()
{
await Client.PostMsgpack<MemoryEventActivateData>(
"memory_event/activate",
new MemoryEventActivateRequest(EventId)
);

DragaliaResponse<RaidEventGetEventDataData> evtData =
await Client.PostMsgpack<RaidEventGetEventDataData>(
$"{Prefix}/get_event_data",
new RaidEventGetEventDataRequest(EventId)
);

evtData.data.raid_event_user_data.Should().NotBeNull();
evtData.data.raid_event_reward_list.Should().NotBeNull();
}

[Fact]
public async Task ReceiveEventRewards_ReturnsEventRewards()
{
await Client.PostMsgpack<MemoryEventActivateData>(
"memory_event/activate",
new MemoryEventActivateRequest(EventId)
);

DbPlayerEventItem pointItem = await ApiContext.PlayerEventItems.SingleAsync(
x => x.EventId == EventId && x.Type == (int)RaidEventItemType.RaidPoint1
);

pointItem.Quantity += 500;

ApiContext.PlayerEventRewards.RemoveRange(
ApiContext.PlayerEventRewards.Where(x => x.EventId == EventId)
);

await ApiContext.SaveChangesAsync();

DragaliaResponse<RaidEventReceiveRaidPointRewardData> evtResp =
await Client.PostMsgpack<RaidEventReceiveRaidPointRewardData>(
$"{Prefix}/receive_raid_point_reward",
new RaidEventReceiveRaidPointRewardRequest(EventId, new[] { 1001 })
);

evtResp.data.raid_event_reward_list.Should().NotBeNullOrEmpty();
evtResp.data.entity_result.Should().NotBeNull();
evtResp.data.update_data_list.Should().NotBeNull();
}
}
2 changes: 2 additions & 0 deletions DragaliaAPI.Shared.Test/Unit/MasterAssetTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public void CharaData_Get_ReturnsExpectedProperties()
AwakeNeedEntityType5: EntityTypes.Dew,
AwakeNeedEntityId5: 0,
AwakeNeedEntityQuantity5: 25000,
GrowMaterialOnlyStartDate: DateTimeOffset.UnixEpoch,
GrowMaterialOnlyEndDate: DateTimeOffset.UnixEpoch,
UniqueGrowMaterialId1: Materials.GalaLaxisConviction,
UniqueGrowMaterialId2: Materials.GalaLaxisDevotion,
GrowMaterialId: Materials.Empty,
Expand Down
4 changes: 4 additions & 0 deletions DragaliaAPI.Shared/MasterAsset/Models/CharaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public record CharaData(
Materials UniqueGrowMaterialId1,
Materials UniqueGrowMaterialId2,
Materials GrowMaterialId,
[property: JsonConverter(typeof(MasterAssetDateTimeOffsetConverter))]
DateTimeOffset GrowMaterialOnlyStartDate,
[property: JsonConverter(typeof(MasterAssetDateTimeOffsetConverter))]
DateTimeOffset GrowMaterialOnlyEndDate,
int DefaultAbility1Level,
int DefaultAbility2Level,
int DefaultAbility3Level,
Expand Down
Loading

0 comments on commit 57182fa

Please sign in to comment.