Skip to content

Commit

Permalink
Disabling place parsing from locale (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
kueda committed Dec 7, 2020
1 parent 27118b1 commit 17bbe1f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 30 deletions.
22 changes: 14 additions & 8 deletions lib/inaturalist_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,14 +677,20 @@ InaturalistAPI.lookupPreferredPlaceMiddleware = ( req, res, next ) => {
"preferred_place_id", Place.findByID, "preferredPlace" );
return;
}
const { locale } = req.query;
Place.findByLocaleString( locale ).then( localePlace => {
if ( localePlace ) {
req.inat = req.inat || { };
req.inat.preferredPlace = localePlace;
}
next( );
} ).catch( err => util.renderError( err, res ) );
// Disabling lookupPreferredPlaceMiddleware because it's causing some people
// to see names in the wrong language, e.g. zh-HK names when requesting en-HK.
// Some more context at
// https://github.com/inaturalist/iNaturalistAPI/issues/89#issuecomment-740142965.
// ~~kueda 20201207
// const { locale } = req.query;
// Place.findByLocaleString( locale ).then( localePlace => {
// if ( localePlace ) {
// req.inat = req.inat || { };
// req.inat.preferredPlace = localePlace;
// }
// next( );
// } ).catch( err => util.renderError( err, res ) );
next( );
};

InaturalistAPI.lookupUnobservedByUserMiddleware = ( req, res, next ) => {
Expand Down
49 changes: 27 additions & 22 deletions test/inaturalist_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,40 @@ describe( "InaturalistAPI", ( ) => {

describe( "lookupPreferredPlaceMiddleware", ( ) => {
it( "looks up preferred_place by preferred_place_id", done => {
const req = { query: { preferred_place_id: 1, locale: "zh-LP"}, inat: {} };
const req = { query: { preferred_place_id: 1, locale: "zh-LP" }, inat: {} };
InaturalistAPI.lookupPreferredPlaceMiddleware( req, null, () => {
expect( req.inat.preferredPlace.id ).to.eq( 1 );
done( );
} );
} );

it( "looks up preferred_place by locale", done => {
const req = { query: { locale: "zh-LP" }, inat: {} };
InaturalistAPI.lookupPreferredPlaceMiddleware( req, null, () => {
expect( req.inat.preferredPlace.id ).to.eq( 511 );
done( );
} );
} );
// Disabling lookupPreferredPlaceMiddleware because it's causing some people
// to see names in the wrong language, e.g. zh-HK names when requesting
// en-HK. Some more context at
// https://github.com/inaturalist/iNaturalistAPI/issues/89#issuecomment-740142965.
// ~~kueda 20201207
// it( "looks up preferred_place by locale", done => {
// const req = { query: { locale: "zh-LP" }, inat: {} };
// InaturalistAPI.lookupPreferredPlaceMiddleware( req, null, () => {
// expect( req.inat.preferredPlace.id ).to.eq( 511 );
// done( );
// } );
// } );

it( "does not set preferred_place if locale is malformed", done => {
const req = { query: { locale: "zh-LP-LP" }, inat: {} };
InaturalistAPI.lookupPreferredPlaceMiddleware( req, null, () => {
expect( req.inat.preferredPlace ).to.be.undefined;
done( );
} );
} );
// it( "does not set preferred_place if locale is malformed", done => {
// const req = { query: { locale: "zh-LP-LP" }, inat: {} };
// InaturalistAPI.lookupPreferredPlaceMiddleware( req, null, () => {
// expect( req.inat.preferredPlace ).to.be.undefined;
// done( );
// } );
// } );

it( "does not set preferred_place if country is not found", done => {
const req = { query: { locale: "zh-LPB" } };
InaturalistAPI.lookupPreferredPlaceMiddleware( req, null, () => {
expect( req.inat ).to.be.undefined;
done( );
} );
} );
// it( "does not set preferred_place if country is not found", done => {
// const req = { query: { locale: "zh-LPB" } };
// InaturalistAPI.lookupPreferredPlaceMiddleware( req, null, () => {
// expect( req.inat ).to.be.undefined;
// done( );
// } );
// } );
} );
} );

0 comments on commit 17bbe1f

Please sign in to comment.