From 71d06a96df256a61d6acb12b32bb6fb4737acad2 Mon Sep 17 00:00:00 2001 From: Vincent Guyader Date: Fri, 24 Apr 2026 23:15:16 +0200 Subject: [PATCH 1/3] fix(sample_source_call): respect local argument (#9) sample_source_call() was always returning the French-locale list ('Local','France','Europe','International'), leaking 'France' as a source when users passed local='en_US'. Switch the list on the locale the same way the other sample_* helpers do, so en_US now yields 'Local','US','Europe','International'. --- R/utils.R | 11 +++++------ tests/testthat/test-locale.R | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 tests/testthat/test-locale.R diff --git a/R/utils.R b/R/utils.R index 9ebf2d0..ee9f425 100644 --- a/R/utils.R +++ b/R/utils.R @@ -80,12 +80,11 @@ sample_state_level <- function(vol, local = "en_US") { } sample_source_call <- function(vol, local = "en_US") { - source_level <- c( - "Local", - "France", - "Europe", - "International" - ) + source_level <- if (local == "fr_FR") { + c("Local", "France", "Europe", "International") + } else { + c("Local", "US", "Europe", "International") + } factor( sample(source_level, vol, replace = TRUE), source_level diff --git a/tests/testthat/test-locale.R b/tests/testthat/test-locale.R new file mode 100644 index 0000000..3ce9209 --- /dev/null +++ b/tests/testthat/test-locale.R @@ -0,0 +1,26 @@ +test_that("fake_ticket_client(local = 'en_US') has no French tokens in source_call (#9)", { + df <- fakir::fake_ticket_client(vol = 200, local = "en_US", seed = 42) + # The source_call column in en_US mode should not include "France" + # (that is the French-locale label). + expect_false("France" %in% levels(df$source_call)) + expect_false("France" %in% as.character(df$source_call)) +}) + +test_that("fake_ticket_client(local = 'fr_FR') keeps French tokens", { + df <- fakir::fake_ticket_client(vol = 200, local = "fr_FR", seed = 42) + expect_true("France" %in% as.character(df$source_appel) || + "Europe" %in% as.character(df$source_appel)) +}) + +test_that("sample_source_call is locale-aware", { + skip_if_not(exists("sample_source_call", envir = asNamespace("fakir"))) + withr::with_seed( + seed = 1, + { + en <- fakir:::sample_source_call(200, local = "en_US") + fr <- fakir:::sample_source_call(200, local = "fr_FR") + } + ) + expect_false("France" %in% levels(en)) + expect_true("France" %in% levels(fr) || "France" %in% as.character(fr)) +}) From 00fb307bc3ad861a95d75a2874748a694e8b4369 Mon Sep 17 00:00:00 2001 From: Vincent Guyader Date: Sat, 25 Apr 2026 09:13:48 +0200 Subject: [PATCH 2/3] fix(sample_source_call): use match.arg() to reject unknown locales Aligns sample_source_call() with the rest of the file's locale handling and turns silent fallthrough on unknown locales (e.g. local = 'de_DE') into an explicit error instead of yielding the en_US list. --- R/utils.R | 3 ++- tests/testthat/test-locale.R | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/R/utils.R b/R/utils.R index ee9f425..1cc0fbf 100644 --- a/R/utils.R +++ b/R/utils.R @@ -79,7 +79,8 @@ sample_state_level <- function(vol, local = "en_US") { ) } -sample_source_call <- function(vol, local = "en_US") { +sample_source_call <- function(vol, local = c("en_US", "fr_FR")) { + local <- match.arg(local) source_level <- if (local == "fr_FR") { c("Local", "France", "Europe", "International") } else { diff --git a/tests/testthat/test-locale.R b/tests/testthat/test-locale.R index 3ce9209..c87ead9 100644 --- a/tests/testthat/test-locale.R +++ b/tests/testthat/test-locale.R @@ -12,6 +12,13 @@ test_that("fake_ticket_client(local = 'fr_FR') keeps French tokens", { "Europe" %in% as.character(df$source_appel)) }) +test_that("sample_source_call rejects unknown locales (#9)", { + expect_error( + fakir:::sample_source_call(10, local = "de_DE"), + regexp = "should be one of" + ) +}) + test_that("sample_source_call is locale-aware", { skip_if_not(exists("sample_source_call", envir = asNamespace("fakir"))) withr::with_seed( From 0c11133fc74cd52acd14bf923ad5728fe2f76639 Mon Sep 17 00:00:00 2001 From: Vincent Guyader Date: Sat, 25 Apr 2026 19:20:48 +0200 Subject: [PATCH 3/3] ci(pkgdown): bump deprecated r-lib/actions v1 -> v2 and checkout v2 -> v4 --- .github/workflows/pkgdown.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index 45fc691..5da0f11 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -15,15 +15,15 @@ jobs: env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: r-lib/actions/setup-pandoc@v1 + - uses: r-lib/actions/setup-pandoc@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 with: use-public-rspm: true - - uses: r-lib/actions/setup-r-dependencies@v1 + - uses: r-lib/actions/setup-r-dependencies@v2 with: extra-packages: pkgdown needs: website