test_that("country links persist, update only their key, and retain history", { path <- tempfile(); on.exit(unlink(c(path,paste0(path,".bak")),recursive=TRUE)) initial <- country_links(path) update_country_link("Italy","https://example.org/first","2026-09-21",path=path) update_country_link("italy","https://example.org/second","2026-09-22",path=path) x <- country_links(path) hit <- x$country_code==380 & x$source_id=="country_portal" expect_equal(sum(hit),1L) expect_equal(x$url[hit],"https://example.org/second") expect_equal(nrow(x),nrow(initial)+1L) expect_equal(country_links(path,TRUE)$url,"https://example.org/first") expect_true(file.exists(paste0(path,".bak"))) old <- options(ALSdownloadeR.country_links=path); on.exit(options(old),add=TRUE) catalog <- provider_catalog() expect_true(any(catalog$country_code==380 & catalog$info_url=="https://example.org/second" & !catalog$implemented)) update_country_link("Brazil","https://example.org/brazil","2026-09-22",path=path) catalog <- provider_catalog() expect_true(any(catalog$country_code==76 & catalog$implemented)) expect_true(any(catalog$country_code==76 & !catalog$implemented & catalog$info_url=="https://example.org/brazil")) expect_error(update_country_link("Italy","javascript:alert(1)","2026-09-22",path=path),"HTTPS") expect_error(update_country_link("Italy","https://example.org","2026-02-30",path=path),"valid") expect_error(update_country_link("Atlantis","https://example.org","2026-09-22",path=path),"Country") })