89 lines
2.3 KiB
Swift
89 lines
2.3 KiB
Swift
import Testing
|
|
@testable import BulkHealth
|
|
|
|
struct BulkHealthTests {
|
|
@Test
|
|
func moodwellToStateOfMindTransform() throws {
|
|
let entry = MoodwellEntry(
|
|
arrayOfPhotos: [],
|
|
moodType: 4,
|
|
moodUniqueIdentifier: "abc-123",
|
|
arrayOfBadEmotions: ["Frustrated"],
|
|
notesString: "stressful but okay",
|
|
arrayOfWeathers: ["Sunny"],
|
|
createdAt: "2023-01-01T10:00:00.000Z",
|
|
arrayOfActivities: ["Work", "Sports"],
|
|
arrayOfGoodEmotions: ["Happy", "Optimistic"]
|
|
)
|
|
let result = MoodwellStateOfMindTemplate.makeDrafts(
|
|
entries: [entry],
|
|
mapping: MoodwellStateOfMindTemplate.defaultMapping,
|
|
moodValenceScale: [1: -0.8, 2: -0.25, 3: 0.3, 4: 0.8]
|
|
)
|
|
|
|
#expect(result.errors.isEmpty)
|
|
#expect(result.drafts.count == 1)
|
|
let draft = try #require(result.drafts.first)
|
|
#expect(draft.valence == 0.8)
|
|
#expect(draft.labels.contains(.happy))
|
|
#expect(draft.labels.contains(.hopeful))
|
|
#expect(draft.labels.contains(.frustrated))
|
|
#expect(draft.associations.contains(.work))
|
|
#expect(draft.associations.contains(.fitness))
|
|
#expect(draft.associations.contains(.weather))
|
|
}
|
|
|
|
@Test
|
|
func invalidDateCreatesError() {
|
|
let entry = MoodwellEntry(
|
|
arrayOfPhotos: [],
|
|
moodType: 2,
|
|
moodUniqueIdentifier: "broken-date",
|
|
arrayOfBadEmotions: [],
|
|
notesString: nil,
|
|
arrayOfWeathers: [],
|
|
createdAt: "not-a-date",
|
|
arrayOfActivities: [],
|
|
arrayOfGoodEmotions: []
|
|
)
|
|
let result = MoodwellStateOfMindTemplate.makeDrafts(
|
|
entries: [entry],
|
|
mapping: MoodwellStateOfMindTemplate.defaultMapping,
|
|
moodValenceScale: [1: -0.8, 2: -0.25, 3: 0.3, 4: 0.8]
|
|
)
|
|
|
|
#expect(result.drafts.isEmpty)
|
|
#expect(!result.errors.isEmpty)
|
|
}
|
|
|
|
@Test
|
|
func iso8601FormatterSupportsFractionalSeconds() {
|
|
let output = ImportFieldFormatterEngine.apply(
|
|
sourceText: "2020-06-03T19:52:27.336Z",
|
|
config: FieldFormatterConfig(formatterType: .dateISO8601ToISO8601)
|
|
)
|
|
|
|
#expect(output != nil)
|
|
#expect(output == "2020-06-03T19:52:27Z")
|
|
}
|
|
|
|
@Test
|
|
func integerLookupFormatterMapsDiscreteValues() {
|
|
let output = ImportFieldFormatterEngine.apply(
|
|
sourceText: "3",
|
|
config: FieldFormatterConfig(
|
|
formatterType: .integerLookupToNumber,
|
|
integerLookup: [
|
|
"0": "-1.0",
|
|
"1": "-0.5",
|
|
"2": "0.0",
|
|
"3": "0.5",
|
|
"4": "1.0"
|
|
]
|
|
)
|
|
)
|
|
|
|
#expect(output == "0.5")
|
|
}
|
|
}
|