@@ -210,8 +210,8 @@ void findNearby_excludesProtectedBirdCollections() throws Exception {
210210 }
211211
212212 @ Test
213- @ DisplayName ("mineOnly 주변 조회도 보호등급 새 컬렉션을 결과에서 제외한다 " )
214- void findNearby_mineOnly_excludesProtectedBirdCollections () throws Exception {
213+ @ DisplayName ("mineOnly 주변 조회는 내 보호등급 새 컬렉션도 결과에 포함한다 " )
214+ void findNearby_mineOnly_includesMyProtectedBirdCollections () throws Exception {
215215 // given
216216 User owner = newUser ();
217217 Point ref = gf .createPoint (new Coordinate (126.9780 , 37.5665 ));
@@ -235,11 +235,46 @@ void findNearby_mineOnly_excludesProtectedBirdCollections() throws Exception {
235235 List <UserBirdCollection > result = collectionRepository .findNearby (ref , 1_000 , owner .getId (), true , null );
236236 long candidateCount = collectionRepository .countNearbyCandidates (ref , 1_000 , owner .getId (), true );
237237
238+ // then
239+ assertEquals (2 , result .size ());
240+ assertEquals (2L , candidateCount );
241+ assertTrue (result .stream ().anyMatch (c -> c .getId ().equals (normalCollection .getId ())));
242+ assertTrue (result .stream ().anyMatch (c -> c .getId ().equals (protectedCollection .getId ())));
243+ }
244+
245+ @ Test
246+ @ DisplayName ("로그인 주변 조회는 내 보호등급 새 컬렉션만 포함하고 타인의 보호등급 새 컬렉션은 제외한다" )
247+ void findNearby_all_includesMyProtectedBirdCollectionsOnly () throws Exception {
248+ // given
249+ User me = newUser ();
250+ User other = newUser ();
251+ Point ref = gf .createPoint (new Coordinate (126.9780 , 37.5665 ));
252+ Point near = gf .createPoint (new Coordinate (126.9781 , 37.5664 ));
253+
254+ Bird myProtectedBird = new BirdBuilder (em )
255+ .korName ("my-protected-nearby-" + System .nanoTime ())
256+ .conservationGrade (ConservationGrade .GRADE_I )
257+ .build ();
258+ Bird otherProtectedBird = new BirdBuilder (em )
259+ .korName ("other-protected-nearby-" + System .nanoTime ())
260+ .conservationGrade (ConservationGrade .GRADE_II )
261+ .build ();
262+
263+ UserBirdCollection myProtectedCollection = newCollection (me , myProtectedBird , near , AccessLevelType .PRIVATE );
264+ UserBirdCollection otherProtectedCollection = newCollection (other , otherProtectedBird , near , AccessLevelType .PUBLIC );
265+
266+ em .flush ();
267+ em .clear ();
268+
269+ // when
270+ List <UserBirdCollection > result = collectionRepository .findNearby (ref , 1_000 , me .getId (), false , null );
271+ long candidateCount = collectionRepository .countNearbyCandidates (ref , 1_000 , me .getId (), false );
272+
238273 // then
239274 assertEquals (1 , result .size ());
240275 assertEquals (1L , candidateCount );
241- assertTrue (result .stream ().anyMatch (c -> c .getId ().equals (normalCollection .getId ())));
242- assertFalse (result .stream ().anyMatch (c -> c .getId ().equals (protectedCollection .getId ())));
276+ assertTrue (result .stream ().anyMatch (c -> c .getId ().equals (myProtectedCollection .getId ())));
277+ assertFalse (result .stream ().anyMatch (c -> c .getId ().equals (otherProtectedCollection .getId ())));
243278 }
244279
245280 @ Test
@@ -317,4 +352,37 @@ void findNearbyEven_excludesProtectedBirdCollections() throws Exception {
317352 assertTrue (result .stream ().anyMatch (c -> c .getId ().equals (normalCollection .getId ())));
318353 assertFalse (result .stream ().anyMatch (c -> c .getId ().equals (protectedCollection .getId ())));
319354 }
355+
356+ @ Test
357+ @ DisplayName ("findNearbyEven mineOnly는 내 보호등급 새 컬렉션도 결과에 포함한다" )
358+ void findNearbyEven_mineOnly_includesMyProtectedBirdCollections () throws Exception {
359+ // given
360+ User owner = newUser ();
361+ Point ref = gf .createPoint (new Coordinate (126.9780 , 37.5665 ));
362+ Point near = gf .createPoint (new Coordinate (126.9781 , 37.5664 ));
363+
364+ Bird protectedBird = new BirdBuilder (em )
365+ .korName ("protected-even-mine-nearby-" + System .nanoTime ())
366+ .conservationGrade (ConservationGrade .GRADE_I )
367+ .build ();
368+
369+ UserBirdCollection protectedCollection = newCollection (owner , protectedBird , near , AccessLevelType .PRIVATE );
370+
371+ em .flush ();
372+ em .clear ();
373+
374+ // when
375+ List <UserBirdCollection > result = collectionRepository .findNearbyEven (
376+ ref ,
377+ 1_000 ,
378+ owner .getId (),
379+ true ,
380+ 10 ,
381+ 80
382+ );
383+
384+ // then
385+ assertEquals (1 , result .size ());
386+ assertTrue (result .stream ().anyMatch (c -> c .getId ().equals (protectedCollection .getId ())));
387+ }
320388}
0 commit comments