Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SapiensAnatis committed Aug 7, 2023
1 parent 5bc70ab commit bf24898
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 915 deletions.
203 changes: 194 additions & 9 deletions DragaliaAPI.Integration.Test/Dragalia/DungeonRecordTest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using DragaliaAPI.Features.Dungeon;
using DragaliaAPI.Database.Entities;
using DragaliaAPI.Features.Dungeon;
using DragaliaAPI.Models;
using DragaliaAPI.Models.Generated;
using DragaliaAPI.Shared.Definitions.Enums;
using DragaliaAPI.Shared.MasterAsset;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Xunit.Abstractions;

Expand All @@ -19,16 +21,81 @@ ITestOutputHelper outputHelper
[Fact]
public async Task Record_ReturnsExpectedResponse()
{
int questId = 227100106;
await this.AddToDatabase(
new DbQuest()
{
QuestId = questId,
State = 0,
DeviceAccountId = DeviceAccountId
}
);

DbPlayerUserData oldUserData = await this.ApiContext.PlayerUserData
.AsNoTracking()
.SingleAsync(x => x.DeviceAccountId == DeviceAccountId);

DungeonSession mockSession =
new()
{
Party = new List<PartySettingList>() { new() { chara_id = Charas.ThePrince } },
QuestData = MasterAsset.QuestData.Get(227100106)
QuestData = MasterAsset.QuestData.Get(questId),
EnemyList = new Dictionary<int, IEnumerable<AtgenEnemy>>()
{
{
1,
new List<AtgenEnemy>()
{
new()
{
enemy_idx = 0,
enemy_drop_list = new List<EnemyDropList>()
{
new()
{
coin = 10,
mana = 10,
drop_list = new List<AtgenDropList>()
{
new()
{
type = EntityTypes.Material,
id = (int)Materials.Squishums,
quantity = 1
}
}
}
}
},
new()
{
enemy_idx = 0,
enemy_drop_list = new List<EnemyDropList>()
{
new()
{
coin = 10,
mana = 10,
drop_list = new List<AtgenDropList>()
{
new()
{
type = EntityTypes.Material,
id = (int)Materials.ImitationSquish,
quantity = 1
}
}
}
}
}
}
}
}
};

string key;

key = await this.Services.GetRequiredService<IDungeonService>().StartDungeon(mockSession);
string key = await this.Services
.GetRequiredService<IDungeonService>()
.StartDungeon(mockSession);

DungeonRecordRecordData response = (
await this.Client.PostMsgpack<DungeonRecordRecordData>(
Expand All @@ -38,7 +105,15 @@ await this.Client.PostMsgpack<DungeonRecordRecordData>(
dungeon_key = key,
play_record = new PlayRecord
{
treasure_record = new List<AtgenTreasureRecord>(),
time = 10,
treasure_record = new List<AtgenTreasureRecord>()
{
new()
{
area_idx = 1,
enemy = new List<int>() { 1, 0 }
}
},
live_unit_no_list = new List<int>(),
damage_record = new List<AtgenDamageRecord>(),
dragon_damage_record = new List<AtgenDamageRecord>(),
Expand All @@ -48,11 +123,121 @@ await this.Client.PostMsgpack<DungeonRecordRecordData>(
)
).data;

// TODO: Add more asserts as we add logic into this endpoint
response.ingame_result_data.dungeon_key.Should().Be(key);
response.ingame_result_data.quest_id.Should().Be(227100106);

response.update_data_list.user_data.Should().NotBeNull();
response.update_data_list.quest_list.Should().NotBeNull();
response.ingame_result_data.reward_record.drop_all
.Should()
.BeEquivalentTo(
new List<AtgenDropAll>()
{
new()
{
type = EntityTypes.Material,
id = (int)Materials.Squishums,
quantity = 1
}
}
);
response.ingame_result_data.reward_record.take_coin.Should().Be(10);
response.ingame_result_data.grow_record.take_mana.Should().Be(10);

response.ingame_result_data.grow_record.take_player_exp.Should().NotBe(0);

response.update_data_list.user_data.coin.Should().Be(oldUserData.Coin + 10);
response.update_data_list.user_data.mana_point.Should().Be(oldUserData.ManaPoint + 10);

response.update_data_list.material_list
.Should()
.Contain(x => x.material_id == Materials.Squishums);
response.update_data_list.quest_list
.Should()
.ContainEquivalentOf(
new QuestList()
{
quest_id = questId,
state = 3,
is_appear = 1,
is_mission_clear_1 = 1,
is_mission_clear_2 = 1,
is_mission_clear_3 = 1,
best_clear_time = 10
}
);
}

[Fact]
public async Task Record_Event_UsesMultiplierAndCompletesMissions()
{
int eventId = 20816;
int questId = 208160502; // Flames of Reflection -- The Path To Mastery: Master

await this.AddToDatabase(
new DbQuest()
{
QuestId = questId,
State = 0,
DeviceAccountId = DeviceAccountId
}
);

await this.AddToDatabase(
new DbAbilityCrest()
{
DeviceAccountId = DeviceAccountId,
AbilityCrestId = AbilityCrests.SistersDayOut,
}
);

await this.Client.PostMsgpack<MemoryEventActivateData>(
"/memory_event/activate",
new MemoryEventActivateRequest() { event_id = eventId }
);

DungeonSession mockSession =
new()
{
Party = new List<PartySettingList>()
{
new()
{
chara_id = Charas.ThePrince,
equip_crest_slot_type_1_crest_id_1 = AbilityCrests.SistersDayOut
}
},
QuestData = MasterAsset.QuestData.Get(questId),
EnemyList = new Dictionary<int, IEnumerable<AtgenEnemy>>()
{
{ 1, Enumerable.Empty<AtgenEnemy>() }
}
};

string key = await this.Services
.GetRequiredService<IDungeonService>()
.StartDungeon(mockSession);

DungeonRecordRecordData response = (
await this.Client.PostMsgpack<DungeonRecordRecordData>(
"/dungeon_record/record",
new DungeonRecordRecordRequest()
{
dungeon_key = key,
play_record = new PlayRecord
{
time = 10,
treasure_record = new List<AtgenTreasureRecord>(),
live_unit_no_list = new List<int>(),
damage_record = new List<AtgenDamageRecord>(),
dragon_damage_record = new List<AtgenDamageRecord>(),
battle_royal_record = new AtgenBattleRoyalRecord(),
wave = 3
}
}
)
).data;

response.ingame_result_data.score_mission_success_list.Should().NotBeEmpty();
response.ingame_result_data.reward_record.take_accumulate_point.Should().NotBe(0);
response.ingame_result_data.reward_record.take_boost_accumulate_point.Should().NotBe(0);
}
}
Loading

0 comments on commit bf24898

Please sign in to comment.