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 AddToStorage counting all builds on the server #322

Merged
merged 1 commit into from
Jul 25, 2023
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
58 changes: 58 additions & 0 deletions DragaliaAPI.Database.Test/Repositories/FortRepositoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,62 @@ public async Task AddDojos_AddsDojos()

this.mockPlayerIdentityService.VerifyAll();
}

[Fact]
public async Task AddToStorage_IsTotalQuantity_AddsBuilds()
{
this.mockPlayerIdentityService.SetupGet(x => x.AccountId).Returns("account id");

this.fixture.ApiContext.PlayerFortBuilds.AddRange(
new List<DbFortBuild>()
{
new() { DeviceAccountId = "some other id", PlantId = FortPlants.FlameDracolith, }
}
);
await this.fixture.ApiContext.SaveChangesAsync();

await this.fortRepository.AddToStorage(
FortPlants.FlameDracolith,
quantity: 1,
isTotalQuantity: true,
level: 4
);
await this.fixture.ApiContext.SaveChangesAsync();

this.fixture.ApiContext.PlayerFortBuilds
.Should()
.Contain(
x =>
x.DeviceAccountId == "account id"
&& x.Level == 4
&& x.PositionX == -1
&& x.PositionZ == -1
);
}

[Fact]
public async Task AddToStorage_IsTotalQuantity_AlreadyOwned_DoesNotAddBuilds()
{
this.mockPlayerIdentityService.SetupGet(x => x.AccountId).Returns("account id");

this.fixture.ApiContext.PlayerFortBuilds.AddRange(
new List<DbFortBuild>()
{
new() { DeviceAccountId = "account id", PlantId = FortPlants.WindDracolith, }
}
);
await this.fixture.ApiContext.SaveChangesAsync();

await this.fortRepository.AddToStorage(
FortPlants.WindDracolith,
quantity: 1,
isTotalQuantity: true,
level: 4
);
await this.fixture.ApiContext.SaveChangesAsync();

this.fixture.ApiContext.PlayerFortBuilds
.Should()
.ContainSingle(x => x.PlantId == FortPlants.WindDracolith);
}
}
11 changes: 10 additions & 1 deletion DragaliaAPI/Features/Fort/FortRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,19 @@ public async Task AddToStorage(
int? level = null
)
{
this.logger.LogDebug(
"Adding {quantity} copies of {plant} to storage (isTotalQuantity: {isTotalQuantity})",
quantity,
plant,
isTotalQuantity
);

int startQuantity = isTotalQuantity
? await apiContext.PlayerFortBuilds.Where(x => x.PlantId == plant).CountAsync()
? await this.Builds.Where(x => x.PlantId == plant).CountAsync()
: 0;

this.logger.LogDebug("User already owns {startQuantity} copies.", startQuantity);

if (startQuantity >= quantity)
return;

Expand Down
Loading