test_that("search_tweets validates product before requiring configuration", {
  search_tweets_fn <- twscrapeR_test_fn("search_tweets")

  expect_error(
    search_tweets_fn("rstats", product = "Popular", progress = FALSE),
    "'arg' should be one of"
  )
})

test_that("search_tweets passes Latest product to twscrape by default", {
  python_code <- twscrapeR_test_fn(".search_tweets_python_code")

  code <- python_code("rstats", 10)

  expect_match(code, "api\\.search\\('rstats', limit=10, kv=\\{'product': 'Latest'\\}\\)")
})

test_that("search_tweets passes selected Top product to twscrape", {
  python_code <- twscrapeR_test_fn(".search_tweets_python_code")

  code <- python_code("rstats", 10, "Top")

  expect_match(code, "api\\.search\\('rstats', limit=10, kv=\\{'product': 'Top'\\}\\)")
})

test_that("search_tweets escapes query string literals", {
  python_code <- twscrapeR_test_fn(".search_tweets_python_code")

  code <- python_code("it's rstats", 10)

  expect_match(code, "api\\.search\\('it\\\\'s rstats', limit=10, kv=\\{'product': 'Latest'\\}\\)")
})
