From 2b83939fda48c8f906bf1a8fd379d4bc799a88d3 Mon Sep 17 00:00:00 2001 From: Yuuki Toriyama Date: Fri, 12 Jan 2024 18:56:27 +0900 Subject: [PATCH 1/3] =?UTF-8?q?update:=20API=E5=A4=B1=E6=95=97=E6=99=82?= =?UTF-8?q?=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=82=B3=E3=83=BC=E3=83=89?= =?UTF-8?q?:=20`prefecture=5Fmaster=5Fapi`,=20`city=5Fmaster=5Fapi`?= =?UTF-8?q?=E3=82=92public=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/api.rs b/src/api.rs index 50587a30..71e7df51 100644 --- a/src/api.rs +++ b/src/api.rs @@ -21,8 +21,8 @@ pub trait Api { } pub struct ApiImpl { - prefecture_master_api: PrefectureMasterApi, - city_master_api: CityMasterApi, + pub prefecture_master_api: PrefectureMasterApi, + pub city_master_api: CityMasterApi, } impl Api for ApiImpl { @@ -72,7 +72,8 @@ impl BlockingApi for BlockingApiImpl { fn new() -> Self { BlockingApiImpl { prefecture_master_api: PrefectureMasterApi { - server_url: "https://yuukitoriyama.github.io/geolonia-japanese-addresses-accompanist", + server_url: + "https://yuukitoriyama.github.io/geolonia-japanese-addresses-accompanist", }, city_master_api: CityMasterApi { server_url: "https://geolonia.github.io/japanese-addresses/api/ja", @@ -85,6 +86,7 @@ impl BlockingApi for BlockingApiImpl { } fn get_city_master(&self, prefecture_name: &str, city_name: &str) -> Result { - self.city_master_api.get_blocking(prefecture_name, city_name) + self.city_master_api + .get_blocking(prefecture_name, city_name) } } From b7b936a3daeb0a179fa512270ceae4cd50a23494 Mon Sep 17 00:00:00 2001 From: Yuuki Toriyama Date: Fri, 12 Jan 2024 18:56:53 +0900 Subject: [PATCH 2/3] =?UTF-8?q?update:=20API=E5=A4=B1=E6=95=97=E6=99=82?= =?UTF-8?q?=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=82=B3=E3=83=BC=E3=83=89?= =?UTF-8?q?:=20=E9=83=BD=E9=81=93=E5=BA=9C=E7=9C=8C=E3=83=9E=E3=82=B9?= =?UTF-8?q?=E3=82=BF=E3=81=8C=E5=8F=96=E5=BE=97=E3=81=A7=E3=81=8D=E3=81=AA?= =?UTF-8?q?=E3=81=84=E5=A0=B4=E5=90=88=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=82=B3=E3=83=BC=E3=83=89=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parser.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/parser.rs b/src/parser.rs index 0d52cdc9..fd583134 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -71,6 +71,7 @@ pub async fn parse(api: T, input: &str) -> ParseResult { #[cfg(test)] mod non_blocking_tests { + use crate::api::prefecture_master_api::PrefectureMasterApi; use crate::api::{Api, ApiImpl}; use crate::err::ParseErrorKind; use crate::parser::parse; @@ -91,6 +92,21 @@ mod non_blocking_tests { ); } + #[tokio::test] + async fn 都道府県マスタが取得できない場合() { + let mut api = ApiImpl::new(); + api.prefecture_master_api = PrefectureMasterApi { + server_url: "https://example.com/invalid_url/api/", + }; + + let result = parse(api, "青森県青森市長島1丁目1−1").await; + assert_eq!(result.error.is_some(), true); + assert_eq!(result.address.prefecture, "青森県"); + assert_eq!(result.address.city, ""); + assert_eq!(result.address.town, ""); + assert_eq!(result.address.rest, "青森市長島1丁目1−1"); + } + #[tokio::test] async fn 市区町村名が誤っている場合() { let api = ApiImpl::new(); From a780a12fb2ac66fb4d370dbc83010d33abab4056 Mon Sep 17 00:00:00 2001 From: Yuuki Toriyama Date: Fri, 12 Jan 2024 18:59:53 +0900 Subject: [PATCH 3/3] =?UTF-8?q?update:=20API=E5=A4=B1=E6=95=97=E6=99=82?= =?UTF-8?q?=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=82=B3=E3=83=BC=E3=83=89?= =?UTF-8?q?:=20=E5=B8=82=E5=8C=BA=E7=94=BA=E6=9D=91=E3=83=9E=E3=82=B9?= =?UTF-8?q?=E3=82=BF=E3=81=8C=E5=8F=96=E5=BE=97=E3=81=A7=E3=81=8D=E3=81=AA?= =?UTF-8?q?=E3=81=84=E5=A0=B4=E5=90=88=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=82=B3=E3=83=BC=E3=83=89=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parser.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/parser.rs b/src/parser.rs index fd583134..fade4809 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -71,6 +71,7 @@ pub async fn parse(api: T, input: &str) -> ParseResult { #[cfg(test)] mod non_blocking_tests { + use crate::api::city_master_api::CityMasterApi; use crate::api::prefecture_master_api::PrefectureMasterApi; use crate::api::{Api, ApiImpl}; use crate::err::ParseErrorKind; @@ -122,6 +123,21 @@ mod non_blocking_tests { ); } + #[tokio::test] + async fn 市区町村マスタが取得できない場合() { + let mut api = ApiImpl::new(); + api.city_master_api = CityMasterApi { + server_url: "https://example.com/invalid_url/api/", + }; + + let result = parse(api, "青森県青森市長島1丁目1−1").await; + assert_eq!(result.error.is_some(), true); + assert_eq!(result.address.prefecture, "青森県"); + assert_eq!(result.address.city, "青森市"); + assert_eq!(result.address.town, ""); + assert_eq!(result.address.rest, "長島1丁目1−1"); + } + #[tokio::test] async fn 町名が誤っている場合() { let api = ApiImpl::new();