Move module funcs to properties

This commit is contained in:
2025-01-30 20:36:00 -05:00
parent facc294d66
commit 42e3a58131
12 changed files with 384 additions and 410 deletions

View File

@@ -15,7 +15,7 @@ let countAll _ = true
module ReferenceListTests =
[<Tests>]
let asOfDateListTests =
testList "ReferenceList.asOfDateList" [
@@ -43,7 +43,7 @@ module ReferenceListTests =
Expect.equal (fst lst) (string PlainTextFormat) "The 3rd option should have been plain text"
}
]
[<Tests>]
let expirationListTests =
testList "ReferenceList.expirationList" [
@@ -66,7 +66,7 @@ module ReferenceListTests =
"The option for immediate expiration was not found"
}
]
[<Tests>]
let requestTypeListTests =
testList "ReferenceList.requestTypeList" [
@@ -129,7 +129,7 @@ let appViewInfoTests =
let assignGroupsTests =
testList "AssignGroups" [
test "fromUser populates correctly" {
let usr = { User.empty with Id = (Guid.NewGuid >> UserId) (); FirstName = "Alice"; LastName = "Bob" }
let usr = { User.Empty with Id = (Guid.NewGuid >> UserId) (); FirstName = "Alice"; LastName = "Bob" }
let asg = AssignGroups.fromUser usr
Expect.equal asg.UserId (shortGuid usr.Id.Value) "The user ID was not filled correctly"
Expect.equal asg.UserName usr.Name "The user's name was not filled correctly"
@@ -142,7 +142,7 @@ let editChurchTests =
testList "EditChurch" [
test "fromChurch populates correctly when interface exists" {
let church =
{ Church.empty with
{ Church.Empty with
Id = (Guid.NewGuid >> ChurchId) ()
Name = "Unit Test"
City = "Testlandia"
@@ -163,7 +163,7 @@ let editChurchTests =
test "fromChurch populates correctly when interface does not exist" {
let edit =
EditChurch.fromChurch
{ Church.empty with
{ Church.Empty with
Id = (Guid.NewGuid >> ChurchId) ()
Name = "Unit Test"
City = "Testlandia"
@@ -198,7 +198,7 @@ let editChurchTests =
HasInterface = Some true
InterfaceAddress = Some "https://test.units"
}
let church = edit.PopulateChurch Church.empty
let church = edit.PopulateChurch Church.Empty
Expect.notEqual (shortGuid church.Id.Value) edit.ChurchId "The church ID should not have been modified"
Expect.equal church.Name edit.Name "The church name was not updated correctly"
Expect.equal church.City edit.City "The church's city was not updated correctly"
@@ -213,7 +213,7 @@ let editChurchTests =
Name = "Test Baptist Church"
City = "Testerville"
State = "TE"
}.PopulateChurch Church.empty
}.PopulateChurch Church.Empty
Expect.isFalse church.HasVpsInterface "The church should show that it has an interface"
Expect.isNone church.InterfaceAddress "The interface address should exist"
}
@@ -224,7 +224,7 @@ let editMemberTests =
testList "EditMember" [
test "fromMember populates with group default format" {
let mbr =
{ Member.empty with
{ Member.Empty with
Id = (Guid.NewGuid >> MemberId) ()
Name = "Test Name"
Email = "test_units@example.com"
@@ -236,7 +236,7 @@ let editMemberTests =
Expect.equal edit.Format "" "The e-mail format should have been blank for group default"
}
test "fromMember populates with specific format" {
let edit = EditMember.fromMember { Member.empty with Format = Some HtmlFormat }
let edit = EditMember.fromMember { Member.Empty with Format = Some HtmlFormat }
Expect.equal edit.Format (string HtmlFormat) "The e-mail format was not filled correctly"
}
test "empty is as expected" {
@@ -259,7 +259,7 @@ let editMemberTests =
let editPreferencesTests =
testList "EditPreferences" [
test "fromPreferences succeeds for native fonts, named colors, and private list" {
let prefs = ListPreferences.empty
let prefs = ListPreferences.Empty
let edit = EditPreferences.fromPreferences prefs
Expect.equal edit.ExpireDays prefs.DaysToExpire "The expiration days were not filled correctly"
Expect.equal edit.DaysToKeepNew prefs.DaysToKeepNew "The days to keep new were not filled correctly"
@@ -278,7 +278,7 @@ let editPreferencesTests =
Expect.isNone edit.Fonts "The list fonts should not exist for native font stack"
Expect.equal edit.HeadingFontSize prefs.HeadingFontSize "The heading font size was not filled correctly"
Expect.equal edit.ListFontSize prefs.TextFontSize "The list text font size was not filled correctly"
Expect.equal edit.TimeZone (TimeZoneId.toString prefs.TimeZoneId) "The time zone was not filled correctly"
Expect.equal edit.TimeZone (string prefs.TimeZoneId) "The time zone was not filled correctly"
Expect.isSome edit.GroupPassword "The group password should have been set"
Expect.equal edit.GroupPassword (Some prefs.GroupPassword) "The group password was not filled correctly"
Expect.equal edit.Visibility GroupVisibility.PrivateList
@@ -287,7 +287,7 @@ let editPreferencesTests =
Expect.equal edit.AsOfDate (string prefs.AsOfDateDisplay) "The as-of date display was not filled correctly"
}
test "fromPreferences succeeds for RGB line color and password-protected list" {
let prefs = { ListPreferences.empty with LineColor = "#ff0000"; GroupPassword = "pw" }
let prefs = { ListPreferences.Empty with LineColor = "#ff0000"; GroupPassword = "pw" }
let edit = EditPreferences.fromPreferences prefs
Expect.equal edit.LineColorType "RGB" "The heading line color type was not derived correctly"
Expect.equal edit.LineColor prefs.LineColor "The heading line color was not filled correctly"
@@ -297,7 +297,7 @@ let editPreferencesTests =
"The list visibility was not derived correctly"
}
test "fromPreferences succeeds for RGB text color and public list" {
let prefs = { ListPreferences.empty with HeadingColor = "#0000ff"; IsPublic = true }
let prefs = { ListPreferences.Empty with HeadingColor = "#0000ff"; IsPublic = true }
let edit = EditPreferences.fromPreferences prefs
Expect.equal edit.HeadingColorType "RGB" "The heading text color type was not derived correctly"
Expect.equal edit.HeadingColor prefs.HeadingColor "The heading text color was not filled correctly"
@@ -307,7 +307,7 @@ let editPreferencesTests =
"The list visibility was not derived correctly"
}
test "fromPreferences succeeds for non-native fonts" {
let prefs = { ListPreferences.empty with Fonts = "Arial,sans-serif" }
let prefs = { ListPreferences.Empty with Fonts = "Arial,sans-serif" }
let edit = EditPreferences.fromPreferences prefs
Expect.isFalse edit.IsNative "The IsNative flag should have been false"
Expect.isSome edit.Fonts "The fonts should have been filled for non-native fonts"
@@ -330,7 +330,7 @@ let editRequestTests =
}
test "fromRequest succeeds" {
let req =
{ PrayerRequest.empty with
{ PrayerRequest.Empty with
Id = (Guid.NewGuid >> PrayerRequestId) ()
RequestType = CurrentRequest
Requestor = Some "Me"
@@ -358,7 +358,7 @@ let editSmallGroupTests =
testList "EditSmallGroup" [
test "fromGroup succeeds" {
let grp =
{ SmallGroup.empty with
{ SmallGroup.Empty with
Id = (Guid.NewGuid >> SmallGroupId) ()
Name = "test group"
ChurchId = (Guid.NewGuid >> ChurchId) ()
@@ -387,7 +387,7 @@ let editSmallGroupTests =
Name = "test name"
ChurchId = (Guid.NewGuid >> shortGuid) ()
}
let grp = edit.populateGroup SmallGroup.empty
let grp = edit.populateGroup SmallGroup.Empty
Expect.equal grp.Name edit.Name "The name was not populated correctly"
Expect.equal grp.ChurchId (idFromShort ChurchId edit.ChurchId) "The church ID was not populated correctly"
}
@@ -408,7 +408,7 @@ let editUserTests =
}
test "fromUser succeeds" {
let usr =
{ User.empty with
{ User.Empty with
Id = (Guid.NewGuid >> UserId) ()
FirstName = "user"
LastName = "test"
@@ -438,7 +438,7 @@ let editUserTests =
Password = "testpw"
}
let hasher = fun x -> x + "+"
let usr = edit.PopulateUser User.empty hasher
let usr = edit.PopulateUser User.Empty hasher
Expect.equal usr.FirstName edit.FirstName "The first name was not populated correctly"
Expect.equal usr.LastName edit.LastName "The last name was not populated correctly"
Expect.equal usr.Email edit.Email "The e-mail address was not populated correctly"
@@ -500,26 +500,26 @@ let requestListTests =
let withRequestList f () =
let today = SystemClock.Instance.GetCurrentInstant ()
{ Requests = [
{ PrayerRequest.empty with
{ PrayerRequest.Empty with
RequestType = CurrentRequest
Requestor = Some "Zeb"
Text = "zyx"
UpdatedDate = today
}
{ PrayerRequest.empty with
{ PrayerRequest.Empty with
RequestType = CurrentRequest
Requestor = Some "Aaron"
Text = "abc"
UpdatedDate = today - Duration.FromDays 9
}
{ PrayerRequest.empty with
{ PrayerRequest.Empty with
RequestType = PraiseReport
Text = "nmo"
UpdatedDate = today
}
]
Date = today.InUtc().Date
SmallGroup = SmallGroup.empty
SmallGroup = SmallGroup.Empty
ShowHeader = false
Recipients = []
CanEmail = false
@@ -596,10 +596,10 @@ let requestListTests =
}
let html = htmlList.AsHtml _s
let expected =
htmlList.Requests[0].UpdatedDate.InZone(SmallGroup.timeZone reqList.SmallGroup).Date.ToString ("d", null)
htmlList.Requests[0].UpdatedDate.InZone(reqList.SmallGroup.TimeZone).Date.ToString ("d", null)
|> sprintf """<strong>Zeb</strong> &ndash; zyx<i style="font-size:9.60pt">&nbsp; (as of %s)</i>"""
// spot check; if one request has it, they all should
Expect.stringContains html expected "Expected short as-of date not found"
Expect.stringContains html expected "Expected short as-of date not found"
"AsHtml succeeds with long as-of date",
fun reqList ->
let htmlList =
@@ -611,10 +611,10 @@ let requestListTests =
}
let html = htmlList.AsHtml _s
let expected =
htmlList.Requests[0].UpdatedDate.InZone(SmallGroup.timeZone reqList.SmallGroup).Date.ToString ("D", null)
htmlList.Requests[0].UpdatedDate.InZone(reqList.SmallGroup.TimeZone).Date.ToString ("D", null)
|> sprintf """<strong>Zeb</strong> &ndash; zyx<i style="font-size:9.60pt">&nbsp; (as of %s)</i>"""
// spot check; if one request has it, they all should
Expect.stringContains html expected "Expected long as-of date not found"
Expect.stringContains html expected "Expected long as-of date not found"
"AsText succeeds with no as-of date",
fun reqList ->
let textList = { reqList with SmallGroup = { reqList.SmallGroup with Name = "Test Group" } }
@@ -642,10 +642,10 @@ let requestListTests =
}
let text = textList.AsText _s
let expected =
textList.Requests[0].UpdatedDate.InZone(SmallGroup.timeZone reqList.SmallGroup).Date.ToString ("d", null)
textList.Requests[0].UpdatedDate.InZone(reqList.SmallGroup.TimeZone).Date.ToString ("d", null)
|> sprintf " + Zeb - zyx (as of %s)"
// spot check; if one request has it, they all should
Expect.stringContains text expected "Expected short as-of date not found"
Expect.stringContains text expected "Expected short as-of date not found"
"AsText succeeds with long as-of date",
fun reqList ->
let textList =
@@ -657,10 +657,10 @@ let requestListTests =
}
let text = textList.AsText _s
let expected =
textList.Requests[0].UpdatedDate.InZone(SmallGroup.timeZone reqList.SmallGroup).Date.ToString ("D", null)
textList.Requests[0].UpdatedDate.InZone(reqList.SmallGroup.TimeZone).Date.ToString ("D", null)
|> sprintf " + Zeb - zyx (as of %s)"
// spot check; if one request has it, they all should
Expect.stringContains text expected "Expected long as-of date not found"
Expect.stringContains text expected "Expected long as-of date not found"
"IsNew succeeds for both old and new requests",
fun reqList ->
let allReqs = reqList.RequestsByType _s