tests/testthat/test-getCompensation.R

context("getCompensation")

test_that("Correct HTTP request is made", {
  with_mock(
    `httr::request_perform` = function(req, handle, refresh) {
      expect_equal(req$method, "GET")
      expect_equal(req$url, "https://my.server.com/api/v1/experiments/591a3b441d725115208a6fda/compensations/62a41fb7b72926ab549680db")
      response <- httptest::fake_response(
        req$url,
        req$method,
        content = '{"_id": "62a41fb7b72926ab549680db", "channels": ["Ax488-A","PE-A","PE-TR-A"],"spillMatrix": [1,0.2,0, 0,1,0, 0,0,1], "experimentId": "62a41fb7b72926ab5496809a", "name": "Comp 1"}', # nolint
        status_code = 200,
        headers = list(`Content-Type` = "application/json")
      )
      return(response)
    },
    {
      setServer("https://my.server.com")
      resp <- getCompensation("591a3b441d725115208a6fda", "62a41fb7b72926ab549680db")
      expect_equal(resp$name, "Comp 1")
      expect_true(is.matrix(resp$spillMatrix))
      expect_equal(resp$spillMatrix, matrix(
        c(1,0.2,0, 0,1,0, 0,0,1),
        nrow=3,
        ncol=3,
        byrow=TRUE,
        dimnames=list(
          c("Ax488-A","PE-A","PE-TR-A"),
          c("Ax488-A","PE-A","PE-TR-A")
        )
      ))
    }
  )
})
primitybio/cellengine-r-toolkit documentation built on Oct. 19, 2024, 1:17 a.m.