tests/testthat/test-token-url.R

# This code tests the magmaRset function
# library(magmaR); library(testthat); source("tests/testthat/setup.R"); source("tests/testthat/test-token-url.R")

test_that("token, url, and opts get stored in expected spots, & 'followlocation' added when left out by user", {
    
    expect_message(
        targ <- magmaRset(
            token = TOKEN,
            url = URL,
            opts = list(option1 = FALSE)),
        "'followlocation = FALSE' added",
        fixed = TRUE)
    
    expect_identical(
        targ$token,
        TOKEN)
    expect_identical(
        targ$url,
        URL)
    expect_identical(
        targ$opts,
        list(option1 = FALSE, followlocation = FALSE))
})

test_that("default, production, magma link is filled in when not gven", {
    
    expect_identical(
        magmaRset("")$url,
        "https://magma.ucsf.edu")
})

vcr::use_cassette("bad_token", {
    test_that("Proper error given when a token is improper", {
        
        bad_targ <- magmaRset(token = "BAD_TOKEN")
        
        expect_error(
            retrieveProjects(bad_targ),
            "unauthorized. Update your 'token'",
            fixed = TRUE
        )
    })
})

Try the magmaR package in your browser

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

magmaR documentation built on Oct. 2, 2021, 5:08 p.m.