-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e6a8ea0
commit 8e8fc4f
Showing
5 changed files
with
36 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,74 +89,5 @@ class DataUtilsTesting { | |
let result = try! DataUtils.userLogin(for: notLoggedUser, context: modelContext) | ||
#expect(result == true) | ||
} | ||
|
||
@Test("delete a comment") func deleteComment() { | ||
let context = self.modelContext | ||
var commentsInContext: [miniProject_seniorDesign.Comment] = [] | ||
|
||
let user = User(name: "Test User", email: "[email protected]", admin: true) | ||
context.insert(user) | ||
|
||
let post = Post(user: user, contents: "Test post content") | ||
context.insert(post) | ||
|
||
|
||
let comment = Comment(user: user, post: post, contents: "Test comment", createdAt: Date()) | ||
context.insert(comment) | ||
commentsInContext.append(comment) | ||
|
||
#expect(commentsInContext.contains { $0 === comment } == true) | ||
|
||
do { | ||
try DataUtils.deleteComment(for: context, comment: comment) | ||
commentsInContext.removeAll { $0 === comment } | ||
let isCommentDeleted = !commentsInContext.contains { $0 === comment } | ||
#expect(isCommentDeleted == true) | ||
} catch { | ||
#expect(Bool(false), "Error deleting comment: \(error)") | ||
} | ||
} | ||
@Test("add a empty comment")func addEmptyComment(){ | ||
let context = self.modelContext | ||
var commentsInContext: [miniProject_seniorDesign.Comment] = [] | ||
|
||
let user = User(name: "Test User", email: "[email protected]", admin: true) | ||
context.insert(user) | ||
|
||
let post = Post(user: user, contents: "Test post content") | ||
context.insert(post) | ||
|
||
let contents = "" | ||
|
||
do{ | ||
let comment = try DataUtils.addComment(for: context, post: post, user: user, contents: contents) | ||
commentsInContext.append(comment) | ||
#expect(Bool(false), "Expected an error when adding an empty comment, but it succeeded.") | ||
|
||
}catch{ | ||
#expect(commentsInContext.isEmpty == true, "No comment should be added for empty content") | ||
} | ||
} | ||
@Test("add a comment")func addComment(){ | ||
let context = self.modelContext | ||
var commentsInContext: [miniProject_seniorDesign.Comment] = [] | ||
|
||
let user = User(name: "Test User", email: "[email protected]", admin: true) | ||
context.insert(user) | ||
|
||
let post = Post(user: user, contents: "Test post content") | ||
context.insert(post) | ||
|
||
let contents = "This is a test comment" | ||
do{ | ||
let comment = try DataUtils.addComment(for: context, post: post, user: user, contents: contents) | ||
commentsInContext.append(comment) | ||
#expect(!commentsInContext.isEmpty == true) | ||
|
||
}catch{ | ||
#expect(Bool(false), "Error adding a valid comment: \(error)") | ||
} | ||
} | ||
|
||
} | ||
|