Skip to content

Commit

Permalink
Adding test
Browse files Browse the repository at this point in the history
  • Loading branch information
apgupta3303 committed Mar 13, 2024
1 parent 068fba5 commit ebfdd72
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Tests/SpeziMedicationTests/SpeziMedicationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,51 @@ import XCTest

final class SpeziMedicationTests: XCTestCase {
// swiftlint:disable:next function_body_length

Check failure on line 15 in Tests/SpeziMedicationTests/SpeziMedicationTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint

Superfluous Disable Command Violation: SwiftLint rule 'function_body_length' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
func testScheduleDecodingWithAndWithoutTimes() throws {
let jsonDecoder = JSONDecoder()
jsonDecoder.dateDecodingStrategy = .iso8601

// Test decoding without times
let noTimesJSON = """
{
"frequency": {
"asNeeded": true
},
"startDate": "2023-12-07T08:00:00Z"
}
""".data(using: .utf8)!

Check failure on line 28 in Tests/SpeziMedicationTests/SpeziMedicationTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint

Force Unwrapping Violation: Force unwrapping should be avoided (force_unwrapping)
let noTimesSchedule = try jsonDecoder.decode(Schedule.self, from: noTimesJSON)
XCTAssertEqual(noTimesSchedule.times, nil)

Check failure on line 30 in Tests/SpeziMedicationTests/SpeziMedicationTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint

XCTest Specific Matcher Violation: Prefer the specific matcher 'XCTAssertNil' instead (xct_specific_matcher)

// Test decoding with times
let withTimesJSON = """
{
"frequency": {
"regularDayIntervals": 2
},
"startDate": "2023-12-07T08:00:00Z",
"times": [
{
"time": {
"hour": 8,
"minute": 0
}
},
{
"time": {
"hour": 15,
"minute": 0
}
}
]
}
""".data(using: .utf8)!

Check failure on line 54 in Tests/SpeziMedicationTests/SpeziMedicationTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint

Force Unwrapping Violation: Force unwrapping should be avoided (force_unwrapping)
let withTimesSchedule = try jsonDecoder.decode(Schedule.self, from: withTimesJSON)
XCTAssertNotNil(withTimesSchedule.times)
}


func testScheduleEncoding() throws {

Check failure on line 60 in Tests/SpeziMedicationTests/SpeziMedicationTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint

Function Body Length Violation: Function body should span 50 lines or less excluding comments and whitespace: currently spans 91 lines (function_body_length)
let jsonEncoder = JSONEncoder()
jsonEncoder.outputFormatting = [.prettyPrinted, .sortedKeys, .withoutEscapingSlashes]
Expand Down

0 comments on commit ebfdd72

Please sign in to comment.