Skip to content

Commit

Permalink
fix(DataStore): Fixing a crash when attempting to create a model with…
Browse files Browse the repository at this point in the history
… a predicate. (#3600)
  • Loading branch information
ruisebas authored Apr 8, 2024
1 parent b955a71 commit 235b49f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ final class StorageEngine: StorageEngineBehavior {
"Cannot apply a condition on model which does not exist.",
"Save the model instance without a condition first.")
completion(.failure(causedBy: dataStoreError))
return
}

do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,28 @@ class StorageEngineTestsHasOne: StorageEngineTestsBase {
}
}

/// Given: A model that does not exist
/// When: save is called with a predicate
/// Then: A DataStoreError.invalidCondition error is returned
func testSaveModelWithPredicate_shouldFail() {
let team = Team(name: "Team")
let saveFinished = expectation(description: "Save finished")
storageEngine.save(team, condition: Team.keys.name.beginsWith("T")) { result in
defer {
saveFinished.fulfill()
}
guard case .failure(let error) = result,
case . invalidCondition(let errorDescription, let recoverySuggestion, _) = error else {
XCTFail("Expected failure with .invalidCondition, got \(result)")
return
}

XCTAssertEqual(errorDescription, "Cannot apply a condition on model which does not exist.")
XCTAssertEqual(recoverySuggestion, "Save the model instance without a condition first.")
}
wait(for: [saveFinished], timeout: defaultTimeout)
}

func testBelongsToRelationshipWithoutOwner() {
let teamA = Team(name: "A-Team")
let projectA = Project(name: "ProjectA", team: teamA)
Expand Down

0 comments on commit 235b49f

Please sign in to comment.