Skip to content

test(geo): cover countryForLogin and the location parser's refusals#87

Merged
Younesfdj merged 1 commit into
Younesfdj:masterfrom
Amayyas:test/geo-country-for-login
Jul 20, 2026
Merged

test(geo): cover countryForLogin and the location parser's refusals#87
Younesfdj merged 1 commit into
Younesfdj:masterfrom
Amayyas:test/geo-country-for-login

Conversation

@Amayyas

@Amayyas Amayyas commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

What

countryForLogin is the function engine.ts calls to set every card's country, and it had no tests. This adds coverage for it and for the location-parser contracts geo.test.ts didn't yet pin. +11 tests, no source changes.

countryForLogin (was entirely untested)

It layers a pinned-origin override over countryFromLocation. Now pinned:

  • the pinned origin wins and ignores the profile location (torvaldsus even with a French location);
  • the login match is case-insensitive;
  • everyone else falls through to the location parser;
  • a non-pinned account with no resolvable location → null.

countryFromLocation — the deliberate refusals

geo.test.ts already covered the UK home nations and the Georgia country-vs-US-state split. What it didn't cover were the design decisions the module's own header comment calls out — and where "a wrong guess is worse than no flag" is the whole point:

  • ambiguous 2-letter abbreviations are refused (DE = Germany or Delaware, CA = California or Canada → null), while the intentional ukgb alias still stands — so the test documents that "drop 2-letter codes" has a deliberate exception, not a bug;
  • empty / blank / symbol-only input sanitises to null;
  • native-language & colloquial aliases (Deutschland, España, Türkiye, Holland), accented cities (München, Kraków), and multi-word phrases found anywhere in the free text ("based in United Kingdom");
  • first resolving segment wins left-to-right ("California, France"us).

Confidence

Mutation-checked: dropping the pinned override turns the countryForLogin tests red. 276 passed, lint clean, build green.

countryForLogin is what engine.ts calls to set every card's country, and it
had no tests at all — nothing pinned its pinned-origin override (torvalds →
us regardless of location), the case-insensitive login match, or the
fall-through to the location parser.

geo.test.ts already covered the UK home nations and the Georgia country-vs-
US-state split, but not the design decisions the module's own header calls
out — where a wrong guess is worse than no flag:

- ambiguous 2-letter abbreviations are refused ("DE", "CA" → null), while
  the intentional "uk" → gb alias still stands;
- empty / blank / symbol-only input sanitises to null;
- native-language and colloquial aliases (Deutschland, España, Türkiye,
  Holland), accented cities (München, Kraków), and multi-word phrases found
  anywhere in the free text ("based in United Kingdom");
- first resolving segment wins left-to-right ("California, France" → us).

Mutation-checked: dropping the pinned override turns the countryForLogin
tests red.
@Younesfdj

Copy link
Copy Markdown
Owner

great work, thanks @Amayyas

@Younesfdj
Younesfdj merged commit 3f6e12c into Younesfdj:master Jul 20, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants