tests/testthat/test-get_sources.R

context("Validate functionality given multiple or single sources")

# Test data
ld <- get_sources(language = "de")
cle <- get_sources(country = "us", language = "en")
cld <- get_sources(category = "general", language = "de")
clc <- get_sources(category = "politics")


test_that("Validate formal structure as data.frame", {

  for (each in list(ld, cle, cld, clc)) {
    expect_equal(class(each), "data.frame")
  }
})

testthat::test_that("Validate empty list of parameters as warnings", {

  testthat::expect_warning(get_sources(), "Please pass one of the following sources: category, language, country. Otherwise all sources are displayed.")
})

testthat::test_that("Validate wrong language as error", {

  testthat::expect_error(get_sources(language = "badisch"), "language must be one of these: ar, en, cn, de, es, fr, he, it, nl, no, pt, ru, sv, ud")
})

testthat::test_that("Validate wrong country as error", {

  testthat::expect_error(get_sources(country = "North-Germany"), "country must be one of these:, ar, au, br, ca, cn, de, es, fr, gb, hk, ie, in, is, it, nl, no, pk, ru, sa, sv, us, za")
})

testthat::test_that("Validate wrong category as error", {

  testthat::expect_error(get_sources(category = ""), "category must be one of these: business, entertainment, gaming, general, health-and-medical, music, politics, science-and-nature, sport, technology")
})
data-atelier/newsExploreR documentation built on May 22, 2019, 11:51 p.m.