Skip to content
Snippets Groups Projects
Commit 3376d7ff authored by Jim Wallace's avatar Jim Wallace
Browse files

Fixed comment endpoint

parent a716d0dd
No related branches found
No related tags found
No related merge requests found
Pipeline #108250 passed
...@@ -26,17 +26,13 @@ import Foundation ...@@ -26,17 +26,13 @@ import Foundation
struct RedditListing: Decodable { struct RedditListing: Decodable {
let kind: String let kind: String
let data: RedditListingData let data: RedditListingData
var after: String? { data.after }
var before: String? { data.before }
var children: [RedditListingDataItem] { data.children }
} }
struct RedditListingData: Decodable { struct RedditListingData: Decodable {
let after: String?
let dist: Int?
let modhash: String? let modhash: String?
let dist: Int
let before: String? let before: String?
let after: String?
let geo_filter: String? let geo_filter: String?
let children: [RedditListingDataItem] let children: [RedditListingDataItem]
} }
......
...@@ -159,7 +159,7 @@ extension RedditClient { ...@@ -159,7 +159,7 @@ extension RedditClient {
let (data, response) = try await session.data(for: request) let (data, response) = try await session.data(for: request)
//print(String(data: data, encoding: .utf8)!) print(String(data: data, encoding: .utf8)!)
guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 else { guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 else {
throw RedditClientError(message: "Bad server response" + response.description) throw RedditClientError(message: "Bad server response" + response.description)
......
...@@ -114,6 +114,7 @@ final class RedditClientTest: XCTestCase { ...@@ -114,6 +114,7 @@ final class RedditClientTest: XCTestCase {
// https://www.reddit.com/r/uwaterloo/comments/18lbokl/conestoga_college_finally_being_called_out_by_the/ // https://www.reddit.com/r/uwaterloo/comments/18lbokl/conestoga_college_finally_being_called_out_by_the/
let submission = RedditSubmission(id: "18lbokl", subreddit: "uwaterloo") let submission = RedditSubmission(id: "18lbokl", subreddit: "uwaterloo")
// This should return an array of listings, one with original submisison and one with responses.
let result = try await client.searchComment(submission: submission) let result = try await client.searchComment(submission: submission)
...@@ -136,13 +137,13 @@ final class RedditClientTest: XCTestCase { ...@@ -136,13 +137,13 @@ final class RedditClientTest: XCTestCase {
} }
let overviewResult = try await client.searchUserOverview(userName: "jimntonik") let overviewResult = try await client.searchUserOverview(userName: "jimntonik")
XCTAssert(overviewResult.children.count > 0) XCTAssert(overviewResult.data.children.count > 0)
let submittedResult = try await client.searchUserSubmitted(userName: "jimntonik") let submittedResult = try await client.searchUserSubmitted(userName: "jimntonik")
XCTAssert(submittedResult.children.count > 0) XCTAssert(submittedResult.data.children.count > 0)
let commentResult = try await client.searchUserComments(userName: "jimntonik") let commentResult = try await client.searchUserComments(userName: "jimntonik")
XCTAssert(commentResult.children.count > 0) XCTAssert(commentResult.data.children.count > 0)
//let upvotedResult = try await client.searchUserUpvoted(userName: "jimntonik") // TODO: 403 - Forbidden - requires login? //let upvotedResult = try await client.searchUserUpvoted(userName: "jimntonik") // TODO: 403 - Forbidden - requires login?
//XCTAssert(upvotedResult.children.count > 0) //XCTAssert(upvotedResult.children.count > 0)
...@@ -159,5 +160,4 @@ final class RedditClientTest: XCTestCase { ...@@ -159,5 +160,4 @@ final class RedditClientTest: XCTestCase {
//let gildedResult = try await client.searchUserGilded(userName: "jimntonik") // TODO: 403 - Forbidden //let gildedResult = try await client.searchUserGilded(userName: "jimntonik") // TODO: 403 - Forbidden
//XCTAssert(gildedResult.children.count > 0) //XCTAssert(gildedResult.children.count > 0)
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment