textMetadata: concatenate list values metadata fields (tab separated)

Change-Id: Icd1e39b71d0ab013989a0baad75ab94a608ed32b
diff --git a/R/textMetadata.R b/R/textMetadata.R
index 32d8d12..b23bc49 100644
--- a/R/textMetadata.R
+++ b/R/textMetadata.R
@@ -45,13 +45,15 @@
     } else {
       if ("document" %in% names(res) & "fields" %in% names(res$document) && length(res$document$fields) > 0) {
         res <- as_tibble(res$document$fields) %>%
+          dplyr::mutate(across(where(is.list), ~ purrr::map(.x, ~ if (length(.x) < 2) unlist(.x) else paste(.x, collapse = "\\t")))) %>%
           select(key, value) %>%
           tidyr::pivot_wider(names_from = key, values_from = value, names_repair = "unique") %>%
           mutate(
             textSigle = as.character(textSigle),
             requestUrl = url,
             webUIRequestUrl = paste0(kco@KorAPUrl, sprintf('?q=<base/s=t>&cq=textSigle+%%3D+"%s"', url_encode(enc2utf8(textSigle))))) %>%
-        relocate(textSigle)
+          mutate(across(everything(), as.character)) %>%
+          relocate(textSigle)
       } else {
         res <- lapply(res, function(x) paste0(x, collapse = "\\t")) # flatten list
         res <- as_tibble(res) %>%
diff --git a/tests/testthat/test-textMetadata.R b/tests/testthat/test-textMetadata.R
index b81ec00..9a8610b 100644
--- a/tests/testthat/test-textMetadata.R
+++ b/tests/testthat/test-textMetadata.R
@@ -10,3 +10,9 @@
   m <- new("KorAPConnection") %>% textMetadata(c("WUD17/B96/57558", "unknownsigle"))
   expect("errors" %in% names(m), "textMetadata should return an errors column if a text does not exist")
 })
+
+test_that("textMetadata works with list valued fields", {
+  skip_if_offline()
+  m <- new("KorAPConnection") %>% textMetadata("WUD17/B96/57558")
+  expect("staat-gesellschaft\\tbiographien-interviews" == m$textClass[1], "multiple text classes / domnains should be tab separated")
+})