mirror of
https://github.com/bitwarden/server.git
synced 2026-02-08 18:03:11 +08:00
* Implement the detail Subscription Discount Database Infrastructure * Change string to string list * fix lint error * Create all missing database object definition files * Regenerate EF migrations with Designer files The previous migrations were missing .Designer.cs files. This commit: - Removes the incomplete migration files - Regenerates all three provider migrations (MySQL, Postgres, SQLite) with proper Designer files - Updates DatabaseContextModelSnapshot.cs for each provider 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix failing database * Resolve the lint warnings * Resolve the database failure * Fix the build Lint * resolve the dbops reviews * Add the default value --------- Co-authored-by: Claude <noreply@anthropic.com>
110 lines
3.1 KiB
C#
110 lines
3.1 KiB
C#
using System.Text.Json;
|
|
using Bit.Core.Billing.Enums;
|
|
using Bit.Core.Billing.Subscriptions.Entities;
|
|
using Xunit;
|
|
|
|
namespace Bit.Core.Test.Billing.Subscriptions.Entities;
|
|
|
|
public class SubscriptionDiscountTests
|
|
{
|
|
[Fact]
|
|
public void StripeProductIds_CanSerializeToJson()
|
|
{
|
|
// Arrange
|
|
var discount = new SubscriptionDiscount
|
|
{
|
|
StripeCouponId = "test-coupon",
|
|
StripeProductIds = new List<string> { "prod_123", "prod_456" },
|
|
Duration = "once",
|
|
StartDate = DateTime.UtcNow,
|
|
EndDate = DateTime.UtcNow.AddDays(30),
|
|
AudienceType = DiscountAudienceType.UserHasNoPreviousSubscriptions
|
|
};
|
|
|
|
// Act
|
|
var json = JsonSerializer.Serialize(discount.StripeProductIds);
|
|
|
|
// Assert
|
|
Assert.Equal("[\"prod_123\",\"prod_456\"]", json);
|
|
}
|
|
|
|
[Fact]
|
|
public void StripeProductIds_CanDeserializeFromJson()
|
|
{
|
|
// Arrange
|
|
var json = "[\"prod_123\",\"prod_456\"]";
|
|
|
|
// Act
|
|
var result = JsonSerializer.Deserialize<List<string>>(json);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal(2, result.Count);
|
|
Assert.Contains("prod_123", result);
|
|
Assert.Contains("prod_456", result);
|
|
}
|
|
|
|
[Fact]
|
|
public void StripeProductIds_HandlesNull()
|
|
{
|
|
// Arrange
|
|
var discount = new SubscriptionDiscount
|
|
{
|
|
StripeCouponId = "test-coupon",
|
|
StripeProductIds = null,
|
|
Duration = "once",
|
|
StartDate = DateTime.UtcNow,
|
|
EndDate = DateTime.UtcNow.AddDays(30),
|
|
AudienceType = DiscountAudienceType.UserHasNoPreviousSubscriptions
|
|
};
|
|
|
|
// Act
|
|
var json = JsonSerializer.Serialize(discount.StripeProductIds);
|
|
|
|
// Assert
|
|
Assert.Equal("null", json);
|
|
}
|
|
|
|
[Fact]
|
|
public void StripeProductIds_HandlesEmptyCollection()
|
|
{
|
|
// Arrange
|
|
var discount = new SubscriptionDiscount
|
|
{
|
|
StripeCouponId = "test-coupon",
|
|
StripeProductIds = new List<string>(),
|
|
Duration = "once",
|
|
StartDate = DateTime.UtcNow,
|
|
EndDate = DateTime.UtcNow.AddDays(30),
|
|
AudienceType = DiscountAudienceType.UserHasNoPreviousSubscriptions
|
|
};
|
|
|
|
// Act
|
|
var json = JsonSerializer.Serialize(discount.StripeProductIds);
|
|
|
|
// Assert
|
|
Assert.Equal("[]", json);
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_RejectsEndDateBeforeStartDate()
|
|
{
|
|
// Arrange
|
|
var discount = new SubscriptionDiscount
|
|
{
|
|
StripeCouponId = "test-coupon",
|
|
Duration = "once",
|
|
StartDate = DateTime.UtcNow.AddDays(30),
|
|
EndDate = DateTime.UtcNow, // EndDate before StartDate
|
|
AudienceType = DiscountAudienceType.UserHasNoPreviousSubscriptions
|
|
};
|
|
|
|
// Act
|
|
var validationResults = discount.Validate(new System.ComponentModel.DataAnnotations.ValidationContext(discount)).ToList();
|
|
|
|
// Assert
|
|
Assert.Single(validationResults);
|
|
Assert.Contains("EndDate", validationResults[0].MemberNames);
|
|
}
|
|
}
|