import Foundation import IndieSync import Testing @testable import Notes struct NoteDocumentTests { private func makeNote() -> Note { var context = CaptureContext.empty context.latitude = 37.8044 context.longitude = -122.2712 context.placeName = "Blue Bottle Coffee" context.locality = "Oakland" context.timeZoneID = "America/Los_Angeles" context.device = "iPhone" return Note.create(text: "Barista's name is Sam\nLikes cortados", tags: ["coffee", "people"], context: context) } @Test func codableRoundTrip() throws { let note = makeNote() let data = try DocumentCoder.encode(note) let decoded = try DocumentCoder.decode(Note.self, from: data) #expect(decoded.payload == note.payload) #expect(decoded.meta.id == note.meta.id) #expect(decoded.meta.schemaVersion == note.meta.schemaVersion) // ISO-8601 encoding truncates sub-second precision. #expect(abs(decoded.meta.createdAt.timeIntervalSince(note.meta.createdAt)) < 1) #expect(abs(decoded.meta.modifiedAt.timeIntervalSince(note.meta.modifiedAt)) < 1) } @Test func forwardGateQuarantinesNewerSchema() { var note = makeNote() note.meta.schemaVersion = Note.currentSchemaVersion + 1 #expect(!note.isReadable) #expect(makeNote().isReadable) } @Test func relativePathIsUTCBucketed() { let note = makeNote() let path = note.relativePath #expect(path.hasSuffix("\(note.meta.id.stringValue).json")) #expect(path == TimeBucketedLayout.relativePath(for: note.meta.id)) } @Test func titleIsFirstLine() { #expect(makeNote().title == "Barista's name is Sam") } }