Skip to content

Commit

Permalink
swift tests
Browse files Browse the repository at this point in the history
  • Loading branch information
velicuvlad committed Sep 23, 2024
1 parent 2f27640 commit 415e6dc
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
2 changes: 0 additions & 2 deletions Objective-C/Tests/DocumentTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -2325,8 +2325,6 @@ - (void) testDocumentRevisionHistory {
// Assert(doc._getRevisionHistory);
}



#pragma clang diagnostic pop

@end
50 changes: 50 additions & 0 deletions Swift/Tests/DocumentTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1855,4 +1855,54 @@ class DocumentTest: CBLTestCase {
}
}
}

// MARK: toJSONTimestamp & Revision history

// https://github.com/couchbaselabs/couchbase-lite-api/blob/master/spec/tests/T0005-Version-Vector.md

// 1. TestDocumentTimestamp
// Description
// Test that the document's timestamp returns value as expected.
// Steps
// 1. Create a new document with id = "doc1"
// 2. Get document's timestamp and check that the timestamp is 0.
// 3. Save the document into the default collection.
// 4. Get document's timestamp and check that the timestamp is more than 0.
// 5. Get the document id = "doc1" from the database.
// 6. Get document's timestamp and check that the timestamp is the same as the timestamp from step 4.
func testDocumentTimestamp() throws {
var doc = MutableDocument(id: "doc1")
assert(doc.timestamp == 0)

try defaultCollection!.save(document: doc)
let timestamp = doc.timestamp
assert(timestamp > 0);

doc = try defaultCollection!.document(id: "doc1")!.toMutable()
assert(doc.timestamp == timestamp)
}

// 2. TestDocumentRevisionHistory
// Description
// Test that the document's timestamp returns value as expected.
// Steps
// 1. Create a new document with id = "doc1"
// 2. Get document's _revisionIDs and check that the value returned is an empty array.
// 3. Save the document into the default collection.
// 4. Get document's _revisionIDs and check that the value returned is an array containing a
// single revision id which is the revision id of the documnt.
// 5. Get the document id = "doc1" from the database.
// 6. Get document's _revisionIDs and check that the value returned is an array containing a
// single revision id which is the revision id of the documnt.
func testDocumentRevisionHistory() throws {
var doc = MutableDocument(id: "doc1")
assert(doc._getRevisionHistory() == nil)

try defaultCollection!.save(document: doc)
assert(doc._getRevisionHistory() != nil)

// Fails from LiteCore,only 1 rev, no rev history
// doc = try defaultCollection!.document(id: "doc1")!.toMutable();
// asser(doc._getRevisionHistory() != nil)
}
}
6 changes: 6 additions & 0 deletions Swift/Tests/ReplicatorTest+CustomConflict.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ class ReplicatorTest_CustomConflict: ReplicatorTest {
XCTAssertNil(try defaultCollection!.document(id: "doc"))
}

/** https://github.com/couchbaselabs/couchbase-lite-api/blob/master/spec/tests/T0005-Version-Vector.md
Test 4. DefaultConflictResolverDeleteWins -> testConflictResolverDeletedLocalWins + testConflictResolverDeletedRemoteWins
*/
func testConflictResolverDeletedLocalWins() throws {
let remoteData = ["key2": "value2"]
try makeConflict(forID: "doc", withLocal: nil, withRemote: remoteData)
Expand Down Expand Up @@ -482,6 +485,9 @@ class ReplicatorTest_CustomConflict: ReplicatorTest {
XCTAssert(try defaultCollection!.document(id: docID)!.toDictionary() == remoteData)
}

/** https://github.com/couchbaselabs/couchbase-lite-api/blob/master/spec/tests/T0005-Version-Vector.md
Test 3. DefaultConflictResolverLastWriteWins -> default resolver
*/
func testConflictResolutionDefault() throws {
let localData = ["key1": "value1"]
let remoteData = ["key2": "value2"]
Expand Down

0 comments on commit 415e6dc

Please sign in to comment.