tests/testthat/test-data-models.R

context("test-data-models")
library(brandseyer2)

test_that("Can read languages", {
  mockr::with_mock(
    read_api = function(endpoint) {
      jsonlite::fromJSON(
        '[{
           "id": "ab",
           "name": "Abkhazian"
         }]', simplifyVector = FALSE
      )
    }, {
      d <- data_model_languages()
      expect_equal(nrow(d), 1)
      expect_equal(d$id, 'ab')
      expect_equal(d$name, 'Abkhazian')
    }
  )
})

test_that("Can read categories", {
  mockr::with_mock(
    read_api = function(endpoint) {
      jsonlite::fromJSON(
        '[{
           "id": "CONSUMER",
           "label": "Consumer"
         }]', simplifyVector = FALSE
      )
    }, {
      d <- data_model_categories()
      expect_equal(nrow(d), 1)
      expect_equal(d$id, 'CONSUMER')
      expect_equal(d$name, 'Consumer')
    }
  )
})

test_that("Can read countries", {
  mockr::with_mock(
    read_api = function(endpoint) {
      jsonlite::fromJSON(
        '[{
           "id": "AF",
           "name": "Afghanistan"
         }]', simplifyVector = FALSE
      )
    }, {
      d <- data_model_countries()
      expect_equal(nrow(d), 1)
      expect_equal(d$id, 'AF')
      expect_equal(d$name, 'Afghanistan')
    }
  )
})
brandseye/brandseyer2 documentation built on Sept. 5, 2021, 2:15 p.m.