33import com .ligg .common .response .Result ;
44import com .ligg .common .statuenum .ResponseCode ;
55import com .ligg .common .vo .bangumi .UserCollectionsVo ;
6+ import com .ligg .common .entity .UserOauthEntity ;
67import com .ligg .flowclient .service .BangumiOAuthTokenService ;
78import com .ligg .flowclient .service .JwtTokenService ;
89import com .ligg .flowclient .service .UserBgmCollectionService ;
910import com .ligg .flowclient .service .UserBgmCollectionSyncService ;
10- import com .ligg .flowclient .service .UserEpisodeWatchService ;
11- import com .ligg .flowclient .service .UserService ;
1211import org .junit .jupiter .api .Test ;
1312import org .junit .jupiter .api .extension .ExtendWith ;
1413import org .mockito .junit .jupiter .MockitoExtension ;
2120import static org .mockito .Mockito .when ;
2221
2322@ ExtendWith (MockitoExtension .class )
24- class FlowUserControllerTest {
25-
26- @ org .mockito .Mock
27- private UserService userService ;
23+ class CollectionControllerTest {
2824
2925 @ org .mockito .Mock
3026 private UserBgmCollectionService userBgmCollectionService ;
@@ -38,27 +34,45 @@ class FlowUserControllerTest {
3834 @ org .mockito .Mock
3935 private JwtTokenService jwtTokenService ;
4036
41- @ org .mockito .Mock
42- private UserEpisodeWatchService userEpisodeWatchService ;
43-
4437 @ Test
4538 void getMeCollections_allowsMissingBangumiOauth () {
46- FlowUserController controller = new FlowUserController (
47- userService ,
48- userBgmCollectionService ,
49- bangumiOAuthTokenService ,
50- userBgmCollectionSyncService ,
39+ CollectionController controller = new CollectionController (
5140 jwtTokenService ,
52- userEpisodeWatchService );
41+ bangumiOAuthTokenService ,
42+ userBgmCollectionService ,
43+ userBgmCollectionSyncService );
5344 UserCollectionsVo collections = new UserCollectionsVo ();
5445 when (jwtTokenService .validateAccessToken ("flow-token" )).thenReturn (10L );
5546 when (bangumiOAuthTokenService .findBangumiOauth (10L )).thenReturn (null );
56- when (userBgmCollectionService .listMyCollections (null , 10L , 2 , 2 , 20 , 0 )).thenReturn (collections );
47+ when (userBgmCollectionService .listMyCollections (null , 10L , 2 , 2 , null , 20 , 0 )).thenReturn (collections );
48+
49+ Result <UserCollectionsVo > result = controller .getMeCollections ("flow-token" , 2 , 2 , null , 20 , 0 );
50+
51+ assertEquals (ResponseCode .SUCCESS .getCode (), result .getCode ());
52+ assertSame (collections , result .getData ());
53+ verify (userBgmCollectionService ).listMyCollections (isNull (), eq (10L ), eq (2 ), eq (2 ), isNull (), eq (20 ), eq (0 ));
54+ }
55+
56+ @ Test
57+ void getMeCollections_passesKeyword () {
58+ CollectionController controller = new CollectionController (
59+ jwtTokenService ,
60+ bangumiOAuthTokenService ,
61+ userBgmCollectionService ,
62+ userBgmCollectionSyncService );
63+ UserOauthEntity oauth = new UserOauthEntity ();
64+ oauth .setAccessToken ("bangumi-token" );
65+ UserCollectionsVo collections = new UserCollectionsVo ();
66+ when (jwtTokenService .validateAccessToken ("flow-token" )).thenReturn (10L );
67+ when (bangumiOAuthTokenService .findBangumiOauth (10L )).thenReturn (oauth );
68+ when (userBgmCollectionService .listMyCollections (
69+ "bangumi-token" , 10L , 2 , 2 , "葬送" , 20 , 0 )).thenReturn (collections );
5770
58- Result <UserCollectionsVo > result = controller .getMeCollections ("flow-token" , 2 , 2 , 20 , 0 );
71+ Result <UserCollectionsVo > result = controller .getMeCollections ("flow-token" , 2 , 2 , "葬送" , 20 , 0 );
5972
6073 assertEquals (ResponseCode .SUCCESS .getCode (), result .getCode ());
6174 assertSame (collections , result .getData ());
62- verify (userBgmCollectionService ).listMyCollections (isNull (), eq (10L ), eq (2 ), eq (2 ), eq (20 ), eq (0 ));
75+ verify (userBgmCollectionService ).listMyCollections (
76+ eq ("bangumi-token" ), eq (10L ), eq (2 ), eq (2 ), eq ("葬送" ), eq (20 ), eq (0 ));
6377 }
6478}
0 commit comments