1
0
mirror of https://github.com/bitwarden/server synced 2026-02-19 02:43:38 +00:00
Files
server/test/Admin.Test/Billing/Models/SubscriptionDiscountViewModelTests.cs
Kyle Denney f0c69cedc2 [PM-30108] import discount from stripe (#6982)
* [PM-30108] import discount from stripe

* fix repo tests

* pr feedback

* wrap discounts in feature flag

* claude pr feedback
2026-02-17 12:57:14 -06:00

169 lines
4.1 KiB
C#

using Bit.Admin.Billing.Models;
using Bit.Core.Billing.Enums;
namespace Admin.Test.Billing.Models;
public class SubscriptionDiscountViewModelTests
{
[Fact]
public void DiscountDisplay_WithPercentOff_ReturnsFormattedPercent()
{
var model = new SubscriptionDiscountViewModel
{
PercentOff = 25m
};
Assert.Equal("25% off", model.DiscountDisplay);
}
[Fact]
public void DiscountDisplay_WithDecimalPercentOff_ReturnsFormattedPercentWithDecimals()
{
var model = new SubscriptionDiscountViewModel
{
PercentOff = 33.5m
};
Assert.Equal("33.5% off", model.DiscountDisplay);
}
[Fact]
public void DiscountDisplay_WithWholeNumberPercentOff_ReturnsFormattedPercentWithoutDecimals()
{
var model = new SubscriptionDiscountViewModel
{
PercentOff = 50.00m
};
Assert.Equal("50% off", model.DiscountDisplay);
}
[Fact]
public void DiscountDisplay_WithAmountOff_ReturnsFormattedDollar()
{
var model = new SubscriptionDiscountViewModel
{
AmountOff = 1000
};
Assert.Equal("$10 off", model.DiscountDisplay);
}
[Fact]
public void DiscountDisplay_WithZeroAmountOff_ReturnsZero()
{
var model = new SubscriptionDiscountViewModel
{
AmountOff = 0
};
Assert.Equal("$0 off", model.DiscountDisplay);
}
[Fact]
public void IsRestrictedToNewUsersOnly_WithMatchingAudienceType_ReturnsTrue()
{
var model = new SubscriptionDiscountViewModel
{
AudienceType = DiscountAudienceType.UserHasNoPreviousSubscriptions
};
Assert.True(model.IsRestrictedToNewUsersOnly);
}
[Fact]
public void IsRestrictedToNewUsersOnly_WithAllUsersAudienceType_ReturnsFalse()
{
var model = new SubscriptionDiscountViewModel
{
AudienceType = DiscountAudienceType.AllUsers
};
Assert.False(model.IsRestrictedToNewUsersOnly);
}
[Fact]
public void IsAvailableToAllUsers_WithAllUsersAudienceType_ReturnsTrue()
{
var model = new SubscriptionDiscountViewModel
{
AudienceType = DiscountAudienceType.AllUsers
};
Assert.True(model.IsAvailableToAllUsers);
}
[Fact]
public void IsAvailableToAllUsers_WithRestrictedAudienceType_ReturnsFalse()
{
var model = new SubscriptionDiscountViewModel
{
AudienceType = DiscountAudienceType.UserHasNoPreviousSubscriptions
};
Assert.False(model.IsAvailableToAllUsers);
}
[Fact]
public void IsActive_WhenWithinDateRange_ReturnsTrue()
{
var model = new SubscriptionDiscountViewModel
{
StartDate = DateTime.UtcNow.AddDays(-1),
EndDate = DateTime.UtcNow.AddDays(1)
};
Assert.True(model.IsActive);
}
[Fact]
public void IsActive_WhenBeforeStartDate_ReturnsFalse()
{
var model = new SubscriptionDiscountViewModel
{
StartDate = DateTime.UtcNow.AddDays(1),
EndDate = DateTime.UtcNow.AddDays(2)
};
Assert.False(model.IsActive);
}
[Fact]
public void IsActive_WhenAfterEndDate_ReturnsFalse()
{
var model = new SubscriptionDiscountViewModel
{
StartDate = DateTime.UtcNow.AddDays(-2),
EndDate = DateTime.UtcNow.AddDays(-1)
};
Assert.False(model.IsActive);
}
[Fact]
public void IsActive_WhenExactlyOnStartDate_ReturnsTrue()
{
var now = DateTime.UtcNow;
var model = new SubscriptionDiscountViewModel
{
StartDate = now,
EndDate = now.AddDays(1)
};
Assert.True(model.IsActive);
}
[Fact]
public void IsActive_WhenCurrentTimeIsOnEndDate_ReturnsTrue()
{
var now = DateTime.UtcNow;
var model = new SubscriptionDiscountViewModel
{
StartDate = now.AddDays(-1),
EndDate = now.AddSeconds(1)
};
Assert.True(model.IsActive);
}
}