test_that("process_page handles comments with and without replies", {
snippet = list(topLevelComment = list(snippet = list(textDisplay = "t1"))),
list(id = "c1r1", snippet = list(textDisplay = "r1")),
list(id = "c1r2", snippet = list(textDisplay = "r2"))
snippet = list(topLevelComment = list(snippet = list(textDisplay = "t2")))
expect_true(any(is.na(df$parentId)))    # top level comments
expect_true("c2" %in% df$id)            # second comment present
expect_false(any(df$parentId == "c2"))  # no replies for c2
test_that("get_all_comments runs successfully with real API", {
skip("No token file available for API testing")
# Use a well-known video with comments (Rick Astley - Never Gonna Give You Up)
result <- get_all_comments(video_id = "dQw4w9WgXcQ")
expected_cols <- c("authorDisplayName", "textDisplay", "publishedAt", "id")
info = paste("Missing columns:", paste(missing_cols, collapse = ", ")))
test_that("get_all_comments handles pagination correctly", {
# Create a mock that simulates paginated responses
mock_tuber_GET_paginated <- function(endpoint, query, ...) {
current_page <- if (is.null(page_token)) 1 else as.numeric(page_token)
comment_id <- paste0("page", current_page, "_comment", i)
textDisplay = paste("Comment from page", current_page, "item", i),
authorDisplayName = paste("Author", current_page, i),
# Add nextPageToken for first 2 pages only
next_token <- if (current_page < 3) as.character(current_page + 1) else NULL
result <- get_all_comments(video_id = "test123")
expect_equal(nrow(result), 15)  # 3 pages * 5 comments each
# Check that we got comments from all pages
test_that("get_all_comments handles empty responses gracefully", {
mock_empty_response <- function(endpoint, query, ...) {
result <- get_all_comments(video_id = "empty_video")

"process_page handles comments with and without replies"
"get_all_comments runs successfully with real API"
"No token file available for API testing"
"get_all_comments handles empty responses gracefully"

process_page handles comments with and without replies