Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions BeeKitTests/BeeKitTests.swift

This file was deleted.

131 changes: 67 additions & 64 deletions BeeKitTests/DaystampTests.swift
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,125 +1,128 @@
import XCTest
import Testing
@testable import BeeKit

final class DaystampTests: XCTestCase {
final class DaystampTests {
var previousTimezone: TimeZone!

let OneHourInSeconds = 60 * 60

func testFormatsAsString() throws {

@Test func testFormatsAsString() async throws {
let daystamp = Daystamp(year: 2023, month: 7, day: 11)
XCTAssertEqual(daystamp.description, "20230711")
#expect(daystamp.description == "20230711")
}

func testParsesFromString() throws {
@Test func testParsesFromString() async throws {
let daystamp = try Daystamp(fromString: "20230711")
XCTAssertEqual(daystamp.year, 2023)
XCTAssertEqual(daystamp.month, 7)
XCTAssertEqual(daystamp.day, 11)
#expect(daystamp.year == 2023)
#expect(daystamp.month == 7)
#expect(daystamp.day == 11)
}

func testConvertsFromDate() throws {
@Test func testConvertsFromDate() async throws {
let date = date(year: 1970, month: 1, day: 1, hour: 0, minute: 0)
let daystamp = Daystamp(fromDate: date, deadline: 0)
XCTAssertEqual(daystamp.year, 1970)
XCTAssertEqual(daystamp.month, 1)
XCTAssertEqual(daystamp.day, 1)
#expect(daystamp.year == 1970)
#expect(daystamp.month == 1)
#expect(daystamp.day == 1)
}

func testConvertsFromDateWithPositiveDeadlineLaterInDay() throws {
@Test func testConvertsFromDateWithPositiveDeadlineLaterInDay() async throws {
let date = date(year: 1970, month: 1, day: 1, hour: 0, minute: 0)
let daystamp = Daystamp(fromDate: date, deadline: OneHourInSeconds)
XCTAssertEqual(daystamp.year, 1969)
XCTAssertEqual(daystamp.month, 12)
XCTAssertEqual(daystamp.day, 31)
#expect(daystamp.year == 1969)
#expect(daystamp.month == 12)
#expect(daystamp.day == 31)
}

func testConvertsFromDateWithPositiveDeadlineEarlierInDay() throws {
@Test func testConvertsFromDateWithPositiveDeadlineEarlierInDay() async throws {
let date = date(year: 1970, month: 1, day: 1, hour: 2, minute: 0)
let daystamp = Daystamp(fromDate: date, deadline: OneHourInSeconds)
XCTAssertEqual(daystamp.year, 1970)
XCTAssertEqual(daystamp.month, 1)
XCTAssertEqual(daystamp.day, 1)
#expect(daystamp.year == 1970)
#expect(daystamp.month == 1)
#expect(daystamp.day == 1)
}

func testConvertsFromDateWithNegativeDeadlineLaterInDay() throws {
@Test func testConvertsFromDateWithNegativeDeadlineLaterInDay() async throws {
let date = date(year: 1970, month: 1, day: 1, hour: 0, minute: 0)
let daystamp = Daystamp(fromDate: date, deadline: -OneHourInSeconds)
XCTAssertEqual(daystamp.year, 1970)
XCTAssertEqual(daystamp.month, 1)
XCTAssertEqual(daystamp.day, 1)
#expect(daystamp.year == 1970)
#expect(daystamp.month == 1)
#expect(daystamp.day == 1)
}

func testConvertsFromDateWithNegativeDeadlineEarlierInDay() throws {
@Test func testConvertsFromDateWithNegativeDeadlineEarlierInDay() async throws {
let date = date(year: 1970, month: 1, day: 1, hour: 23, minute: 0)
let daystamp = Daystamp(fromDate: date, deadline: -2 * OneHourInSeconds)
XCTAssertEqual(daystamp.year, 1970)
XCTAssertEqual(daystamp.month, 1)
XCTAssertEqual(daystamp.day, 2)
#expect(daystamp.year == 1970)
#expect(daystamp.month == 1)
#expect(daystamp.day == 2)
}

func testConvertsFromDateAtStartOfNegativeDaystamp() throws {
@Test func testConvertsFromDateAtStartOfNegativeDaystamp() async throws {
// Ensure there is not an off-by one error when importing values right on the datestamp boundary
let date = date(year: 1970, month: 1, day: 1, hour: 23, minute: 0)
let daystamp = Daystamp(fromDate: date, deadline: -OneHourInSeconds)
XCTAssertEqual(daystamp, Daystamp(year: 1970, month: 1, day: 2))
#expect(daystamp == Daystamp(year: 1970, month: 1, day: 2))
}

func testConvertsFromDateAtStartOfPositiveDaystamp() throws {
@Test func testConvertsFromDateAtStartOfPositiveDaystamp() async throws {
// Ensure there is not an off-by one error when importing values right on the datestamp boundary
let date = date(year: 1970, month: 1, day: 1, hour: 1, minute: 0)
let daystamp = Daystamp(fromDate: date, deadline: OneHourInSeconds)
XCTAssertEqual(daystamp, Daystamp(year: 1970, month: 1, day: 1))
#expect(daystamp == Daystamp(year: 1970, month: 1, day: 1))
}

@Test func testComparesCorrectly() async throws {
#expect(Daystamp(year: 2023, month: 7, day: 11) < Daystamp(year: 2023, month: 7, day: 12))
#expect(Daystamp(year: 2023, month: 7, day: 11) < Daystamp(year: 2023, month: 8, day: 10))
#expect(Daystamp(year: 2023, month: 7, day: 11) < Daystamp(year: 2024, month: 6, day: 10))
#expect(Daystamp(year: 2023, month: 7, day: 11) == Daystamp(year: 2023, month: 7, day: 11))
}

func testComparesCorrectly() throws {
XCTAssertLessThan(Daystamp(year: 2023, month: 7, day: 11), Daystamp(year: 2023, month: 7, day: 12))
XCTAssertLessThan(Daystamp(year: 2023, month: 7, day: 11), Daystamp(year: 2023, month: 8, day: 10))
XCTAssertLessThan(Daystamp(year: 2023, month: 7, day: 11), Daystamp(year: 2024, month: 6, day: 10))
XCTAssertEqual(Daystamp(year: 2023, month: 7, day: 11), Daystamp(year: 2023, month: 7, day: 11))
@Test func testCanAddToDaystamp() async throws {
#expect(Daystamp(year: 2023, month: 7, day: 11) + 1 == Daystamp(year: 2023, month: 7, day: 12))
#expect(Daystamp(year: 2023, month: 7, day: 11) + 30 == Daystamp(year: 2023, month: 8, day: 10))
#expect(Daystamp(year: 2023, month: 7, day: 11) + 365 == Daystamp(year: 2024, month: 7, day: 10)) // Leap year!
}

func testCanAddToDaystamp() throws {
XCTAssertEqual(Daystamp(year: 2023, month: 7, day: 11) + 1, Daystamp(year: 2023, month: 7, day: 12))
XCTAssertEqual(Daystamp(year: 2023, month: 7, day: 11) + 30, Daystamp(year: 2023, month: 8, day: 10))
XCTAssertEqual(Daystamp(year: 2023, month: 7, day: 11) + 365, Daystamp(year: 2024, month: 7, day: 10)) // Leap year!
@Test func testCanSubtractFromDaystamp() async throws {
#expect(Daystamp(year: 2023, month: 7, day: 11) - 1 == Daystamp(year: 2023, month: 7, day: 10))
#expect(Daystamp(year: 2023, month: 7, day: 11) - 30 == Daystamp(year: 2023, month: 6, day: 11))
#expect(Daystamp(year: 2023, month: 7, day: 11) - 365 == Daystamp(year: 2022, month: 7, day: 11))
}

func testCanSubtractFromDaystamp() throws {
XCTAssertEqual(Daystamp(year: 2023, month: 7, day: 11) - 1, Daystamp(year: 2023, month: 7, day: 10))
XCTAssertEqual(Daystamp(year: 2023, month: 7, day: 11) - 30, Daystamp(year: 2023, month: 6, day: 11))
XCTAssertEqual(Daystamp(year: 2023, month: 7, day: 11) - 365, Daystamp(year: 2022, month: 7, day: 11))
@Test func testCanCountDaysBetweenDaystamps() async throws {
#expect(Daystamp(year: 2023, month: 7, day: 12) - Daystamp(year: 2023, month: 7, day: 11) == 1)
#expect(Daystamp(year: 2023, month: 8, day: 10) - Daystamp(year: 2023, month: 7, day: 11) == 30)
#expect(Daystamp(year: 2024, month: 6, day: 11) - Daystamp(year: 2023, month: 6, day: 11) == 366) // Leap year!
}

func testCanCountDaysBetweenDaystamps() throws {
XCTAssertEqual(Daystamp(year: 2023, month: 7, day: 12) - Daystamp(year: 2023, month: 7, day: 11), 1)
XCTAssertEqual(Daystamp(year: 2023, month: 8, day: 10) - Daystamp(year: 2023, month: 7, day: 11), 30)
XCTAssertEqual(Daystamp(year: 2024, month: 6, day: 11) - Daystamp(year: 2023, month: 6, day: 11), 366) // Leap year!
@Test func testCanCalculateBoundsForZeroDeadline() async throws {
#expect(Daystamp(year: 1970, month: 1, day: 1).start(deadline: 0) == date(year: 1970, month: 1, day: 1, hour: 0, minute: 0))
#expect(Daystamp(year: 1970, month: 1, day: 1).end(deadline: 0) == date(year: 1970, month: 1, day: 2, hour: 0, minute: 0))
}

func testCanCalculateBoundsForZeroDeadline() throws {
XCTAssertEqual(Daystamp(year: 1970, month: 1, day: 1).start(deadline: 0), date(year: 1970, month: 1, day: 1, hour: 0, minute: 0))
XCTAssertEqual(Daystamp(year: 1970, month: 1, day: 1).end(deadline: 0), date(year: 1970, month: 1, day: 2, hour: 0, minute: 0))
@Test func testCanCalculateBoundsForNegativeDeadline() async throws {
#expect(Daystamp(year: 1970, month: 1, day: 1).start(deadline: -OneHourInSeconds) == date(year: 1969, month: 12, day: 31, hour: 23, minute: 0))
#expect(Daystamp(year: 1970, month: 1, day: 1).end(deadline: -OneHourInSeconds) == date(year: 1970, month: 1, day: 1, hour: 23, minute: 0))
}

func testCanCalculateBoundsForNegativeDeadline() throws {
XCTAssertEqual(Daystamp(year: 1970, month: 1, day: 1).start(deadline: -OneHourInSeconds), date(year: 1969, month: 12, day: 31, hour: 23, minute: 0))
XCTAssertEqual(Daystamp(year: 1970, month: 1, day: 1).end(deadline: -OneHourInSeconds), date(year: 1970, month: 1, day: 1, hour: 23, minute: 0))
@Test func testCanCalculateBoundsForPositiveDeadline() async throws {
#expect(Daystamp(year: 1970, month: 1, day: 1).start(deadline: OneHourInSeconds) == date(year: 1970, month: 1, day: 1, hour: 1, minute: 0))
#expect(Daystamp(year: 1970, month: 1, day: 1).end(deadline: OneHourInSeconds) == date(year: 1970, month: 1, day: 2, hour: 1, minute: 0))
}

func testCanCalculateBoundsForPositiveDeadline() throws {
XCTAssertEqual(Daystamp(year: 1970, month: 1, day: 1).start(deadline: OneHourInSeconds), date(year: 1970, month: 1, day: 1, hour: 1, minute: 0))
XCTAssertEqual(Daystamp(year: 1970, month: 1, day: 1).end(deadline: OneHourInSeconds), date(year: 1970, month: 1, day: 2, hour: 1, minute: 0))
@Test func testCanIterateOverRange() async throws {
let daystamp = Daystamp(year: 1970, month: 1, day: 1)
let range = daystamp...(daystamp + 3)
#expect(Array(range) == [daystamp, daystamp + 1, daystamp + 2, daystamp + 3])
}
}

private extension DaystampTests {
func date(year: Int, month: Int, day: Int, hour: Int, minute: Int) -> Date {
let components = DateComponents(year: year, month: month, day: day, hour: hour, minute: minute)
return Calendar.current.date(from: components)!
}

func testCanIterateOverRange() throws {
let daystamp = Daystamp(year: 1970, month: 1, day: 1)
let range = daystamp...(daystamp + 3)
XCTAssertEqual(Array(range), [daystamp, daystamp + 1, daystamp + 2, daystamp + 3])
}
}
8 changes: 0 additions & 8 deletions BeeSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
A196CB1F1AE4142F00B90A3E /* GalleryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A196CB1E1AE4142F00B90A3E /* GalleryViewController.swift */; };
A196CB221AE4142F00B90A3E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A196CB201AE4142F00B90A3E /* Main.storyboard */; };
A196CB241AE4142F00B90A3E /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A196CB231AE4142F00B90A3E /* Images.xcassets */; };
A196CB331AE4142F00B90A3E /* BeeSwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A196CB321AE4142F00B90A3E /* BeeSwiftTests.swift */; };
A1A8BDE61FEAE8DD007D61D6 /* ConfigureNotificationsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1A8BDE51FEAE8DD007D61D6 /* ConfigureNotificationsViewController.swift */; };
A1B6723E1B0989DF00584782 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A1B6723D1B0989DF00584782 /* Foundation.framework */; };
A1B672401B0989E800584782 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A1B6723F1B0989E800584782 /* UIKit.framework */; };
Expand Down Expand Up @@ -121,7 +120,6 @@
E55760F526549D310076B95A /* AddDataIntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = E55760F426549D310076B95A /* AddDataIntentHandler.swift */; };
E557610026549DD10076B95A /* AddDataIntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = E55760F426549D310076B95A /* AddDataIntentHandler.swift */; };
E57BE6E92655EBE000BA540B /* BeeKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E57BE6E02655EBD900BA540B /* BeeKit.framework */; };
E57BE6F02655EBE000BA540B /* BeeKitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E57BE6EF2655EBE000BA540B /* BeeKitTests.swift */; };
E57BE6F22655EBE000BA540B /* BeeKit.h in Headers */ = {isa = PBXBuildFile; fileRef = E57BE6E22655EBDA00BA540B /* BeeKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
E57BE6F52655EBE000BA540B /* BeeKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E57BE6E02655EBD900BA540B /* BeeKit.framework */; };
E57BE7042655EE1F00BA540B /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = E55FEE6A23FF7552007C20B2 /* Config.swift */; };
Expand Down Expand Up @@ -257,7 +255,6 @@
A196CB231AE4142F00B90A3E /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
A196CB2C1AE4142F00B90A3E /* BeeSwiftTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = BeeSwiftTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
A196CB311AE4142F00B90A3E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
A196CB321AE4142F00B90A3E /* BeeSwiftTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BeeSwiftTests.swift; sourceTree = "<group>"; };
A1A8BDE51FEAE8DD007D61D6 /* ConfigureNotificationsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigureNotificationsViewController.swift; sourceTree = "<group>"; };
A1B53C301B2D04EA00AF266F /* NotificationCenter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = NotificationCenter.framework; path = System/Library/Frameworks/NotificationCenter.framework; sourceTree = SDKROOT; };
A1B6723D1B0989DF00584782 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -324,7 +321,6 @@
E57BE6E22655EBDA00BA540B /* BeeKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BeeKit.h; sourceTree = "<group>"; };
E57BE6E32655EBDA00BA540B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
E57BE6E82655EBDF00BA540B /* BeeKitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = BeeKitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
E57BE6EF2655EBE000BA540B /* BeeKitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BeeKitTests.swift; sourceTree = "<group>"; };
E57BE6F12655EBE000BA540B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
E5C161932423CE9F0045C90D /* VersionManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VersionManager.swift; sourceTree = "<group>"; };
E5DF493624DC69A200260560 /* Config.swift.sample */ = {isa = PBXFileReference; lastKnownFileType = text; path = Config.swift.sample; sourceTree = "<group>"; };
Expand Down Expand Up @@ -516,7 +512,6 @@
isa = PBXGroup;
children = (
A196CB301AE4142F00B90A3E /* Supporting Files */,
A196CB321AE4142F00B90A3E /* BeeSwiftTests.swift */,
E48E2713296B75E4008013C0 /* TotalSleepMinutesTests.swift */,
E43BEA852A036D4300FC3A38 /* LogReaderTests.swift */,
E417572C2A6446FE0029CDDA /* CurrentUserManagerTests.swift */,
Expand Down Expand Up @@ -669,7 +664,6 @@
E57BE6EE2655EBE000BA540B /* BeeKitTests */ = {
isa = PBXGroup;
children = (
E57BE6EF2655EBE000BA540B /* BeeKitTests.swift */,
E45470292B60E25C00EE648B /* DaystampTests.swift */,
E57BE6F12655EBE000BA540B /* Info.plist */,
);
Expand Down Expand Up @@ -1061,7 +1055,6 @@
E417572D2A6446FE0029CDDA /* CurrentUserManagerTests.swift in Sources */,
E4B0A32E28C194C800055EA7 /* AddDataIntents.intentdefinition in Sources */,
E48E2714296B75E4008013C0 /* TotalSleepMinutesTests.swift in Sources */,
A196CB331AE4142F00B90A3E /* BeeSwiftTests.swift in Sources */,
E4B6FEC62A776A2900690376 /* GoalTests.swift in Sources */,
E43BEA862A036D4300FC3A38 /* LogReaderTests.swift in Sources */,
);
Expand Down Expand Up @@ -1121,7 +1114,6 @@
files = (
E454702A2B60E25C00EE648B /* DaystampTests.swift in Sources */,
E4B0A33228C194CA00055EA7 /* AddDataIntents.intentdefinition in Sources */,
E57BE6F02655EBE000BA540B /* BeeKitTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
36 changes: 0 additions & 36 deletions BeeSwiftTests/BeeSwiftTests.swift

This file was deleted.

10 changes: 5 additions & 5 deletions BeeSwiftTests/CurrentUserManagerTests.swift
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import XCTest
import Testing
import KeychainSwift
@testable import BeeKit

final class CurrentUserManagerTests: XCTestCase {
final class CurrentUserManagerTests {

override func setUpWithError() throws {
init() throws {
let keychain = KeychainSwift(keyPrefix: CurrentUserManager.keychainPrefix)
keychain.delete(CurrentUserManager.accessTokenKey)
}

func testCanSetAndRetrieveAccessToken() throws {
@Test func testCanSetAndRetrieveAccessToken() async throws {
let currentUserManager = CurrentUserManager(requestManager: ServiceLocator.requestManager, container: ServiceLocator.persistentContainer)
currentUserManager.setAccessToken("test_access_token")
XCTAssertEqual(currentUserManager.accessToken, "test_access_token")
#expect(currentUserManager.accessToken == "test_access_token")
}
}
Loading
Loading