tests/testthat/test-tg_api_usage.R

test_that("tg_api_usage parses response and structure correctly", {
  
  with_mock_dir("tg_api_usage", {
    
    # Запрашиваем квоты
    res <- tg_api_usage()
    
    # Проверяем, что вернулся кастомный класс
    expect_s3_class(res, "tg_api_quote")
    expect_s3_class(res, "tbl_df")
    
    # Проверяем, что колонки были правильно конвертированы из snake_case
    expect_true("service_key" %in% names(res))
    
    # Проверяем работу логики сплющивания (flatting) и расчета rate
    expect_true("spent_channels_rate" %in% names(res))
    expect_true("spent_requests_rate" %in% names(res))
    expect_true("spent_words_rate" %in% names(res))
    
    # Убеждаемся, что даты переведены в формат POSIXct
    expect_s3_class(res$expired_at, "POSIXct")
  })
})

Try the rtgstat package in your browser

Any scripts or data that you put into this service are public.

rtgstat documentation built on April 17, 2026, 5:07 p.m.