refactor(campaign): delegate gift-reward-type check to GiftRewardTypes
Delete local IsSupportedGiftRewardType and replace its single call site with GiftRewardTypes.IsSupported — Card (5) and Sleeve (6) are now accepted. Update unsupported-type test sentinel from 5 (Card) to 11 (SpotCard). Add Card and Sleeve success-path tests; full suite 1152/1152.
This commit is contained in:
@@ -4,6 +4,7 @@ using SVSim.Database;
|
|||||||
using SVSim.Database.Enums;
|
using SVSim.Database.Enums;
|
||||||
using SVSim.Database.Models;
|
using SVSim.Database.Models;
|
||||||
using SVSim.EmulatedEntrypoint.Models.Dtos.Campaign;
|
using SVSim.EmulatedEntrypoint.Models.Dtos.Campaign;
|
||||||
|
using SVSim.EmulatedEntrypoint.Services;
|
||||||
|
|
||||||
namespace SVSim.EmulatedEntrypoint.Controllers;
|
namespace SVSim.EmulatedEntrypoint.Controllers;
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@ public sealed class CampaignController : SVSimController
|
|||||||
.AnyAsync(r => r.ViewerId == viewerId && r.SerialCodeId == code.Id, ct);
|
.AnyAsync(r => r.ViewerId == viewerId && r.SerialCodeId == code.Id, ct);
|
||||||
if (alreadyRedeemed) return Fail();
|
if (alreadyRedeemed) return Fail();
|
||||||
|
|
||||||
if (code.Rewards.Any(r => !IsSupportedGiftRewardType(r.RewardType))) return Fail();
|
if (code.Rewards.Any(r => !GiftRewardTypes.IsSupported(r.RewardType))) return Fail();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -82,12 +83,4 @@ public sealed class CampaignController : SVSimController
|
|||||||
|
|
||||||
private IActionResult Fail() => Ok(new { result_code = FailureResultCode });
|
private IActionResult Fail() => Ok(new { result_code = FailureResultCode });
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gift wire types per <c>GiftController.WireRewardTypeToUserGoodsType</c>:
|
|
||||||
/// 1=Crystal, 4=Item, 9=Rupy. Codes with unsupported types fail-fast at redemption.
|
|
||||||
/// Note: wire "1" means Crystal (not RedEther), following the gift wire convention
|
|
||||||
/// rather than the <see cref="UserGoodsType"/> enum order.
|
|
||||||
/// </summary>
|
|
||||||
private static bool IsSupportedGiftRewardType(int rewardType) =>
|
|
||||||
rewardType is 1 or 4 or 9;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,9 +182,10 @@ public class CampaignControllerTests
|
|||||||
{
|
{
|
||||||
using var factory = new SVSimTestFactory();
|
using var factory = new SVSimTestFactory();
|
||||||
long viewerId = await factory.SeedViewerAsync();
|
long viewerId = await factory.SeedViewerAsync();
|
||||||
// RewardType 5 = Card; gift mapper supports only 1=Crystal, 4=Item, 9=Rupy.
|
// RewardType 11 = SpotCard; InventoryTransaction throws NotSupportedException, so the
|
||||||
|
// gift mapper rejects it.
|
||||||
var code = await SeedCodeAsync(factory, "BADTYPE",
|
var code = await SeedCodeAsync(factory, "BADTYPE",
|
||||||
rewards: new[] { (5, 100L, 1) });
|
rewards: new[] { (11, 100L, 1) });
|
||||||
|
|
||||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||||
var response = await client.PostAsync("/campaign/regist_serial_code",
|
var response = await client.PostAsync("/campaign/regist_serial_code",
|
||||||
@@ -227,4 +228,57 @@ public class CampaignControllerTests
|
|||||||
using var doc = JsonDocument.Parse(raw);
|
using var doc = JsonDocument.Parse(raw);
|
||||||
Assert.That(doc.RootElement.GetProperty("result_code").GetInt32(), Is.EqualTo(4202));
|
Assert.That(doc.RootElement.GetProperty("result_code").GetInt32(), Is.EqualTo(4202));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task Register_with_card_reward_succeeds_and_creates_present()
|
||||||
|
{
|
||||||
|
using var factory = new SVSimTestFactory();
|
||||||
|
long viewerId = await factory.SeedViewerAsync();
|
||||||
|
var code = await SeedCodeAsync(factory, "CARDCODE", "Free card",
|
||||||
|
rewards: new[] { (5, 12345L, 1) });
|
||||||
|
|
||||||
|
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||||
|
var response = await client.PostAsync("/campaign/regist_serial_code",
|
||||||
|
JsonBody("""{"serial_code":"CARDCODE"}"""));
|
||||||
|
var raw = await response.Content.ReadAsStringAsync();
|
||||||
|
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK), raw);
|
||||||
|
|
||||||
|
using var doc = JsonDocument.Parse(raw);
|
||||||
|
Assert.That(doc.RootElement.GetProperty("is_complete").GetBoolean(), Is.True);
|
||||||
|
|
||||||
|
using var verifyScope = factory.Services.CreateScope();
|
||||||
|
var ctx = verifyScope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||||
|
var presents = await ctx.ViewerPresents.AsNoTracking()
|
||||||
|
.Where(p => p.ViewerId == viewerId).ToListAsync();
|
||||||
|
Assert.That(presents, Has.Count.EqualTo(1));
|
||||||
|
Assert.That(presents[0].RewardType, Is.EqualTo(5));
|
||||||
|
Assert.That(presents[0].RewardDetailId, Is.EqualTo(12345L));
|
||||||
|
Assert.That(presents[0].Source, Is.EqualTo($"serial_code:{code.Id}"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task Register_with_sleeve_reward_succeeds_and_creates_present()
|
||||||
|
{
|
||||||
|
using var factory = new SVSimTestFactory();
|
||||||
|
long viewerId = await factory.SeedViewerAsync();
|
||||||
|
var code = await SeedCodeAsync(factory, "SLEEVECODE", "Free sleeve",
|
||||||
|
rewards: new[] { (6, 700100L, 1) });
|
||||||
|
|
||||||
|
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||||
|
var response = await client.PostAsync("/campaign/regist_serial_code",
|
||||||
|
JsonBody("""{"serial_code":"SLEEVECODE"}"""));
|
||||||
|
var raw = await response.Content.ReadAsStringAsync();
|
||||||
|
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK), raw);
|
||||||
|
|
||||||
|
using var doc = JsonDocument.Parse(raw);
|
||||||
|
Assert.That(doc.RootElement.GetProperty("is_complete").GetBoolean(), Is.True);
|
||||||
|
|
||||||
|
using var verifyScope = factory.Services.CreateScope();
|
||||||
|
var ctx = verifyScope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||||
|
var presents = await ctx.ViewerPresents.AsNoTracking()
|
||||||
|
.Where(p => p.ViewerId == viewerId).ToListAsync();
|
||||||
|
Assert.That(presents, Has.Count.EqualTo(1));
|
||||||
|
Assert.That(presents[0].RewardType, Is.EqualTo(6));
|
||||||
|
Assert.That(presents[0].RewardDetailId, Is.EqualTo(700100L));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user