diff --git a/Tests/ConfidenceTests/EventStorageTests.swift b/Tests/ConfidenceTests/EventStorageTests.swift index d9e6b034..dd0f3a5e 100644 --- a/Tests/ConfidenceTests/EventStorageTests.swift +++ b/Tests/ConfidenceTests/EventStorageTests.swift @@ -5,6 +5,13 @@ import XCTest class EventStorageTest: XCTestCase { + override func setUp() async throws { + let folderURL = try! EventStorageImpl.getFolderURL() + if FileManager.default.fileExists(atPath: folderURL.path) { + try! FileManager.default.removeItem(at: folderURL) + } + } + func testCreateNewBatch() throws { let eventStorage = try EventStorageImpl() try eventStorage.writeEvent(event: Event(eventDefinition: "some event", eventTime: Date().self, payload: ["pants"], context: ["pants context"])) @@ -16,39 +23,25 @@ class EventStorageTest: XCTestCase { XCTAssertEqual(events[1].eventDefinition, "some event 2") } - func testContinueWritingToOldBatch() { - - } - - func testRolloverToNewBatchWhenBatchIsFull() { - - } - - func testGetReadyFilesToSend() { - - } - - func testGetEventsFromFile() { - - } - - func testRemoveFile() { - + func testContinueWritingToOldBatch() throws { + let eventStorage = try EventStorageImpl() + try eventStorage.writeEvent(event: Event(eventDefinition: "some event", eventTime: Date().self, payload: ["pants"], context: ["pants context"])) + // user stops using app, new session after this + let eventStorageNew = try EventStorageImpl() + try eventStorageNew.writeEvent(event: Event(eventDefinition: "some event 2", eventTime: Date().self, payload: ["pants"], context: ["pants context"])) + try eventStorageNew.startNewBatch() + try XCTAssertEqual(eventStorageNew.batchReadyIds().count, 1) + let events = try eventStorageNew.eventsFrom(id: try eventStorageNew.batchReadyIds()[0]) + XCTAssertEqual(events[0].eventDefinition, "some event") + XCTAssertEqual(events[1].eventDefinition, "some event 2") } - override func setUp() { - let folderURL = try! EventStorageImpl.getFolderURL() - if FileManager.default.fileExists(atPath: folderURL.path) { - try! FileManager.default.removeItem(at: folderURL) - } + func testRemoveFile() throws { + let eventStorage = try EventStorageImpl() + try eventStorage.writeEvent(event: Event(eventDefinition: "some event", eventTime: Date().self, payload: ["pants"], context: ["pants context"])) + try eventStorage.writeEvent(event: Event(eventDefinition: "some event 2", eventTime: Date().self, payload: ["pants"], context: ["pants context"])) + try eventStorage.startNewBatch() + try eventStorage.remove(id: eventStorage.batchReadyIds()[0]) + try XCTAssertEqual(eventStorage.batchReadyIds().count, 0) } } - - -//struct Event: Codable { -// let eventDefinition: String -// let eventTime: Date -// // TODO: fix this to be ConfidenceValue -// let payload: [String] -// let context: [String] -//}