require "./spec_helper" describe JosieHealth::Utils::TimezoneCity do describe ".data" do it "loads timezone data" do data = JosieHealth::Utils::TimezoneCity.data data.should_not be_empty end end describe ".lookup" do it "finds cities by exact name" do matches = JosieHealth::Utils::TimezoneCity.lookup("Tokyo") matches.should_not be_empty matches.first.city.downcase.should eq("tokyo") matches.first.timezone.should eq("Asia/Tokyo") end it "finds cities by prefix" do matches = JosieHealth::Utils::TimezoneCity.lookup("Tok") matches.should_not be_empty matches.any? { |m| m.city.downcase.starts_with?("tok") }.should be_true end it "finds cities by partial match" do matches = JosieHealth::Utils::TimezoneCity.lookup("york") matches.should_not be_empty matches.any? { |m| m.city.downcase.includes?("york") }.should be_true end it "finds by country name" do matches = JosieHealth::Utils::TimezoneCity.lookup("Germany") matches.should_not be_empty matches.first.country.should eq("Germany") end it "returns empty for short queries" do matches = JosieHealth::Utils::TimezoneCity.lookup("a") matches.should be_empty end it "returns empty for no matches" do matches = JosieHealth::Utils::TimezoneCity.lookup("xyznonexistent") matches.should be_empty end it "limits results to specified count" do matches = JosieHealth::Utils::TimezoneCity.lookup("New", limit: 3) matches.size.should be <= 3 end it "returns results with score" do matches = JosieHealth::Utils::TimezoneCity.lookup("London") matches.should_not be_empty matches.first.score.should be > 0 end it "prioritizes exact matches over partial" do matches = JosieHealth::Utils::TimezoneCity.lookup("Berlin") matches.should_not be_empty # Exact match "Berlin" should be first matches.first.city.downcase.should eq("berlin") end end describe ".find" do it "returns timezone for city" do tz = JosieHealth::Utils::TimezoneCity.find("London") tz.should eq("Europe/London") end it "returns nil for unknown city" do tz = JosieHealth::Utils::TimezoneCity.find("xyznonexistent") tz.should be_nil end end describe "Match#to_h" do it "converts match to hash" do matches = JosieHealth::Utils::TimezoneCity.lookup("Paris") matches.should_not be_empty h = matches.first.to_h h["city"].should_not be_empty h["country"].should_not be_empty h["timezone"].should_not be_empty end end end