Skip to content

Commit

Permalink
test: test EventStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
nickybondarenko committed Apr 11, 2024
1 parent 9450360 commit 8ea8cb4
Showing 1 changed file with 25 additions and 32 deletions.
57 changes: 25 additions & 32 deletions Tests/ConfidenceTests/EventStorageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"]))
Expand All @@ -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]
//}

0 comments on commit 8ea8cb4

Please sign in to comment.