mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
[GSoC] Merge Leaderboard branch with master (#3905)
* [GSoC] Fixes #3789 Updated UI of achievements activity to display level in first tab & Leaderboard in the second tab (#3794)
* Updated UI of achievements activity to display level in first tab and Leaderboard in the second tab
* Removed hardcoded string
* Fixes #3861 Use the APIs to fetch leaderboard’s based on uploads via mobile app (all time) and display it in the Leaderboard screen. (#3865)
* [GSoC] Added Unit Tests and Fixed Landscape Mode Bug (#3872)
* Fixes #3861 Use the APIs to fetch leaderboard’s based on uploads via mobile app (all time) and display it in the Leaderboard screen.
* Fixed Bug - missing data in landscape mode
* Added Unit Tests for Leaderboard
* Added JavaDocs
* Updated JavaDocs
* [GSoC] Added Pagination to Leaderboard (#3881)
* Fixes #3861 Use the APIs to fetch leaderboard’s based on uploads via mobile app (all time) and display it in the Leaderboard screen.
* Fixed Bug - missing data in landscape mode
* Added Unit Tests for Leaderboard
* Added JavaDocs
* Updated JavaDocs
* Added Pagination
* Added Merge Adapter
* Fixed Test Case
* Added Smooth Scroll
* Added Progress Bar for Paging
* Fixed Gradle
* [GSoC] Added option to set a new avatar (#3892)
* Fixes #3861 Use the APIs to fetch leaderboard’s based on uploads via mobile app (all time) and display it in the Leaderboard screen.
* Added option to set a new avatar
* [GSoC] Added Click to open user profile for leaderboard (#3887)
* Localisation updates from https://translatewiki.net.
* Localisation updates from https://translatewiki.net.
* #3749 Improve MediaClient UnitTests (#3846)
* #3468 Switch from RvRenderer to AdapterDelegates - replace SearchDepictionsRenderer
* #3468 Switch from RvRenderer to AdapterDelegates - replace UploadCategoryDepictionsRenderer
* #3468 Switch from RvRenderer to AdapterDelegates - update BaseAdapter to be easier to use
* #3468 Switch from RvRenderer to AdapterDelegates - replace SearchImagesRenderer
* #3468 Switch from RvRenderer to AdapterDelegates - replace SearchCategoriesRenderer
* #3468 Switch from RvRenderer to AdapterDelegates - replace NotificationRenderer
* #3468 Switch from RvRenderer to AdapterDelegates - replace UploadDepictsRenderer
* #3468 Switch from RvRenderer to AdapterDelegates - replace PlaceRenderer
* #3756 Convert SearchDepictionsFragment to use Pagination - convert SearchDepictionsFragment
* #3756 Convert SearchDepictionsFragment to use Pagination - fix presenter unit tests now that view is not nullable - fix Category prefix imports
* #3756 Convert SearchDepictionsFragment to use Pagination - test DataSource related classes
* #3756 Convert SearchDepictionsFragment to use Pagination - reset rx scheduler - ignore failing test
* #3760 Convert SearchCategoriesFragment to use Pagination - extract functionality of pagination to base classes - add category pagination
* #3772 Convert SearchImagesFragment to use Pagination - convert SearchImagesFragment - tidy up showing the empty view - make search fragments show snackbar with appropriate text
* #3772 Convert SearchImagesFragment to use Pagination - allow viewpager to load more data
* #3760 remove test that got re-added by merge
* #3760 remove duplicate dependency
* #3772 fix compilation
* #3780 Create media using a combination of Entities & MwQueryResult - construct media with an entity - move fields from media down to contribution - move dynamic fields outside of media - remove unused constructors - remove all unnecessary fetching of captions/descriptions - bump database version
* #3808 Construct media objects that depict an item id correctly - use generator to construct media for DepictedImages
* #3810 Convert DepictedImagesFragment to use Pagination - extract common media paging methods - convert to DepictedImages to use pagination
* #3810 Convert DepictedImagesFragment to use Pagination - rename base classes to better reflect usage
* #3810 Convert DepictedImagesFragment to use Pagination - map to empty result with no pages
* #3810 Convert DepictedImagesFragment to use Pagination - align test with returned values
* #3780 Create media using a combination of Entities & MwQueryResult - update wikicode to align with expected behaviour
* #3780 Create media using a combination of Entities & MwQueryResult - replace old site of thumbnail title with most relevant caption
* #3818 Convert SubDepictionListFragment to use Pagination - replace SubDepictionList with Child and Parent Fragments - replace contracts with simple presenter declarations - move classes to appropriate packages - delete unused network models - delete duplicated paging classes
* #3820 Convert CategoryImagesListFragment to use Pagination - replace CategoryImagesListFragment with CategoriesMediaFragment - disallow the construction of media objects without imageinfo
* #3822 Convert SubCategoryImagesListFragment to use Pagination - convert subcategories - add continuation support in category client - rely on interfaces for callbacks of PageableMediaFragments
* #3822 Convert SubCategoryImagesListFragment to use Pagination - convert parent categories - delete list fragment - creat base class to support continuation requests in clients
* #3822 Convert SubCategoryImagesListFragment to use Pagination - add tests for ParentCategoriesDataSource
* #3822 Convert SubCategoryImagesListFragment to use Pagination - remove no longer applicable test
* #3749 Improve MediaClient UnitTests - test rewrite
* #3749 Improve MediaClient UnitTests - align with buildConfig property
* With pause and resume for uploads (#3858)
* With pause and resume for uploads
* Dispose current upload
* Make pause and resume work
* Check stash validity
* With java docs
* minor
* Localisation updates from https://translatewiki.net.
* Localisation updates from https://translatewiki.net.
* Add nearby presenter unit tests (#3615)
* init the test file
* Add tests to check if searchthisarea button action and checkbox actions are added after initialize test
* Add tests to locked unlocked nearby cases
* Add tests for null cases in updateMapAndList method
* Add test to check which locations are used to populate places, depending to LocationChangeType
* Add tests to test users position is not followed if blue dot (current location marker) is not visible
* Add tests to decide search this area method visibility on camera move
* Add tests for multi filteirng of placetypes
* add tests for single place type selection too
* Add tests to tests search view focus gain and bottom sheet visibilities
* Add tests for SearchCloseToCurrentLocation
* Remove two unneeded getter and setter for isNearbyLocked, use @VisibleForTesting annotation instead
* Add VisibleForTesting annotation to initializeNearbyOperations method so that it will be private by default
* Add missing tests
* Add tests for map updated case and add missing lines those are being tested
* Add some missind method verifications
* Create real latlang objects isntead of spying them
* Use a real presenter object instead of a spy
* Revert nonneeded @VisibleForTest annotations, instead reach via lockUnlock method
* Reduce code repetitions
* Do not call a test from another test method
* Add some more tests
* Fix minor issues
* Hidden categories are not showed in suggested categories (#3853)
* Localisation updates from https://translatewiki.net.
* Clarify that the caption would also be used as the image title (#3876)
The app uses the fist caption as the file title. This should also
be communicated to the user via the info box as they would not be
aware of it otherwise.
* Localisation updates from https://translatewiki.net.
* Added Click event for leaderboard, Fixed #3886
* Fixed Travis
Co-authored-by: translatewiki.net <l10n-bot@translatewiki.net>
Co-authored-by: Seán Mac Gillicuddy <seantheappdev@gmail.com>
Co-authored-by: Vivek Maskara <maskaravivek@gmail.com>
Co-authored-by: neslihanturan <tur.neslihan@gmail.com>
Co-authored-by: Paulina <63326136+PaulinaQuintero@users.noreply.github.com>
Co-authored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
* [GSoC] Added Leaderboard Filters (#3902)
* Attempt to add filters
* Basic Filter Working
* Filter Improved
* Filter Completed
* Add JavaDocs
* Added Test for Update Avatar
* Decreased Margin of Filter
* [GSoC] Updated leaderboard string (#3897)
* Localisation updates from https://translatewiki.net.
* Localisation updates from https://translatewiki.net.
* #3749 Improve MediaClient UnitTests (#3846)
* #3468 Switch from RvRenderer to AdapterDelegates - replace SearchDepictionsRenderer
* #3468 Switch from RvRenderer to AdapterDelegates - replace UploadCategoryDepictionsRenderer
* #3468 Switch from RvRenderer to AdapterDelegates - update BaseAdapter to be easier to use
* #3468 Switch from RvRenderer to AdapterDelegates - replace SearchImagesRenderer
* #3468 Switch from RvRenderer to AdapterDelegates - replace SearchCategoriesRenderer
* #3468 Switch from RvRenderer to AdapterDelegates - replace NotificationRenderer
* #3468 Switch from RvRenderer to AdapterDelegates - replace UploadDepictsRenderer
* #3468 Switch from RvRenderer to AdapterDelegates - replace PlaceRenderer
* #3756 Convert SearchDepictionsFragment to use Pagination - convert SearchDepictionsFragment
* #3756 Convert SearchDepictionsFragment to use Pagination - fix presenter unit tests now that view is not nullable - fix Category prefix imports
* #3756 Convert SearchDepictionsFragment to use Pagination - test DataSource related classes
* #3756 Convert SearchDepictionsFragment to use Pagination - reset rx scheduler - ignore failing test
* #3760 Convert SearchCategoriesFragment to use Pagination - extract functionality of pagination to base classes - add category pagination
* #3772 Convert SearchImagesFragment to use Pagination - convert SearchImagesFragment - tidy up showing the empty view - make search fragments show snackbar with appropriate text
* #3772 Convert SearchImagesFragment to use Pagination - allow viewpager to load more data
* #3760 remove test that got re-added by merge
* #3760 remove duplicate dependency
* #3772 fix compilation
* #3780 Create media using a combination of Entities & MwQueryResult - construct media with an entity - move fields from media down to contribution - move dynamic fields outside of media - remove unused constructors - remove all unnecessary fetching of captions/descriptions - bump database version
* #3808 Construct media objects that depict an item id correctly - use generator to construct media for DepictedImages
* #3810 Convert DepictedImagesFragment to use Pagination - extract common media paging methods - convert to DepictedImages to use pagination
* #3810 Convert DepictedImagesFragment to use Pagination - rename base classes to better reflect usage
* #3810 Convert DepictedImagesFragment to use Pagination - map to empty result with no pages
* #3810 Convert DepictedImagesFragment to use Pagination - align test with returned values
* #3780 Create media using a combination of Entities & MwQueryResult - update wikicode to align with expected behaviour
* #3780 Create media using a combination of Entities & MwQueryResult - replace old site of thumbnail title with most relevant caption
* #3818 Convert SubDepictionListFragment to use Pagination - replace SubDepictionList with Child and Parent Fragments - replace contracts with simple presenter declarations - move classes to appropriate packages - delete unused network models - delete duplicated paging classes
* #3820 Convert CategoryImagesListFragment to use Pagination - replace CategoryImagesListFragment with CategoriesMediaFragment - disallow the construction of media objects without imageinfo
* #3822 Convert SubCategoryImagesListFragment to use Pagination - convert subcategories - add continuation support in category client - rely on interfaces for callbacks of PageableMediaFragments
* #3822 Convert SubCategoryImagesListFragment to use Pagination - convert parent categories - delete list fragment - creat base class to support continuation requests in clients
* #3822 Convert SubCategoryImagesListFragment to use Pagination - add tests for ParentCategoriesDataSource
* #3822 Convert SubCategoryImagesListFragment to use Pagination - remove no longer applicable test
* #3749 Improve MediaClient UnitTests - test rewrite
* #3749 Improve MediaClient UnitTests - align with buildConfig property
* With pause and resume for uploads (#3858)
* With pause and resume for uploads
* Dispose current upload
* Make pause and resume work
* Check stash validity
* With java docs
* minor
* Localisation updates from https://translatewiki.net.
* Localisation updates from https://translatewiki.net.
* Add nearby presenter unit tests (#3615)
* init the test file
* Add tests to check if searchthisarea button action and checkbox actions are added after initialize test
* Add tests to locked unlocked nearby cases
* Add tests for null cases in updateMapAndList method
* Add test to check which locations are used to populate places, depending to LocationChangeType
* Add tests to test users position is not followed if blue dot (current location marker) is not visible
* Add tests to decide search this area method visibility on camera move
* Add tests for multi filteirng of placetypes
* add tests for single place type selection too
* Add tests to tests search view focus gain and bottom sheet visibilities
* Add tests for SearchCloseToCurrentLocation
* Remove two unneeded getter and setter for isNearbyLocked, use @VisibleForTesting annotation instead
* Add VisibleForTesting annotation to initializeNearbyOperations method so that it will be private by default
* Add missing tests
* Add tests for map updated case and add missing lines those are being tested
* Add some missind method verifications
* Create real latlang objects isntead of spying them
* Use a real presenter object instead of a spy
* Revert nonneeded @VisibleForTest annotations, instead reach via lockUnlock method
* Reduce code repetitions
* Do not call a test from another test method
* Add some more tests
* Fix minor issues
* Hidden categories are not showed in suggested categories (#3853)
* Localisation updates from https://translatewiki.net.
* Clarify that the caption would also be used as the image title (#3876)
The app uses the fist caption as the file title. This should also
be communicated to the user via the info box as they would not be
aware of it otherwise.
* Localisation updates from https://translatewiki.net.
* Delete NearbyMapFragment & NearbyListFragment (#3885)
* Fixes #3884
* Delete NearbyMapFragment & NearbyListFragment
* Fixed NearbyParentFragmentPresenterTest
* Localisation updates from https://translatewiki.net.
* Localisation updates from https://translatewiki.net.
* Add more nearby tests (#3877)
* more nearby tests added
* Add tests for Label class
* Add checkbox test javadocs
* Add javadocs for label
* Localisation updates from https://translatewiki.net.
* Updated strings.xml
Co-authored-by: translatewiki.net <l10n-bot@translatewiki.net>
Co-authored-by: Seán Mac Gillicuddy <seantheappdev@gmail.com>
Co-authored-by: Vivek Maskara <maskaravivek@gmail.com>
Co-authored-by: neslihanturan <tur.neslihan@gmail.com>
Co-authored-by: Paulina <63326136+PaulinaQuintero@users.noreply.github.com>
Co-authored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Co-authored-by: Ashish Kumar <ashishkumar468@gmail.com>
* Updated Strings
* Added JavaDocs for all methods and classes
* Added JavaDocs for all methods and classes
* Added More JavaDocs
* Revert string.xml
* Revert "Revert string.xml"
This reverts commit 00019b598a.
* Added protected
* Fixed strings.xml extra changes
* Revert codeStyle change
* Fixed extra string change
Co-authored-by: Vivek Maskara <maskaravivek@gmail.com>
Co-authored-by: translatewiki.net <l10n-bot@translatewiki.net>
Co-authored-by: Seán Mac Gillicuddy <seantheappdev@gmail.com>
Co-authored-by: neslihanturan <tur.neslihan@gmail.com>
Co-authored-by: Paulina <63326136+PaulinaQuintero@users.noreply.github.com>
Co-authored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Co-authored-by: Ashish Kumar <ashishkumar468@gmail.com>
This commit is contained in:
parent
50bcaab15d
commit
eb816b4536
44 changed files with 2839 additions and 641 deletions
|
|
@ -3,10 +3,13 @@ package fr.free.nrw.commons.delete
|
|||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import fr.free.nrw.commons.Media
|
||||
import fr.free.nrw.commons.achievements.FeedbackResponse
|
||||
import fr.free.nrw.commons.auth.SessionManager
|
||||
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient
|
||||
import fr.free.nrw.commons.profile.achievements.FeedbackResponse
|
||||
import fr.free.nrw.commons.profile.leaderboard.LeaderboardResponse
|
||||
import fr.free.nrw.commons.profile.leaderboard.UpdateAvatarResponse
|
||||
import fr.free.nrw.commons.utils.ViewUtilWrapper
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.Single
|
||||
import media
|
||||
import org.junit.Before
|
||||
|
|
@ -54,6 +57,10 @@ class ReasonBuilderTest {
|
|||
`when`(sessionManager?.doesAccountExist()).thenReturn(true)
|
||||
`when`(okHttpJsonApiClient!!.getAchievements(anyString()))
|
||||
.thenReturn(Single.just(mock(FeedbackResponse::class.java)))
|
||||
`when`(okHttpJsonApiClient!!.getLeaderboard(anyString(), anyString(), anyString(), anyString(), anyString()))
|
||||
.thenReturn(Observable.just(mock(LeaderboardResponse::class.java)))
|
||||
`when`(okHttpJsonApiClient!!.setAvatar(anyString(), anyString()))
|
||||
.thenReturn(Single.just(mock(UpdateAvatarResponse::class.java)))
|
||||
|
||||
val media = media(filename="test_file", dateUploaded = Date())
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,116 @@
|
|||
package fr.free.nrw.commons.leaderboard;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import fr.free.nrw.commons.profile.leaderboard.LeaderboardResponse;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Request.Builder;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* This class tests the Leaderboard API calls
|
||||
*/
|
||||
public class LeaderboardApiTest {
|
||||
|
||||
MockWebServer server;
|
||||
private static final String TEST_USERNAME = "user";
|
||||
private static final String TEST_AVATAR = "avatar";
|
||||
private static final int TEST_USER_RANK = 1;
|
||||
private static final int TEST_USER_COUNT = 0;
|
||||
|
||||
private static final String FILE_NAME = "leaderboard_sample_response.json";
|
||||
private static final String ENDPOINT = "/leaderboard.py";
|
||||
|
||||
/**
|
||||
* This method initialises a Mock Server
|
||||
*/
|
||||
@Before
|
||||
public void initTest() {
|
||||
server = new MockWebServer();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will setup a Mock Server and load Test JSON Response File
|
||||
* @throws Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
String testResponseBody = convertStreamToString(getClass().getClassLoader().getResourceAsStream(FILE_NAME));
|
||||
|
||||
server.enqueue(new MockResponse().setBody(testResponseBody));
|
||||
server.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method converts a Input Stream to String
|
||||
* @param is takes Input Stream of JSON File as Parameter
|
||||
* @return a String with JSON data
|
||||
* @throws Exception
|
||||
*/
|
||||
private static String convertStreamToString(InputStream is) throws Exception {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line).append("\n");
|
||||
}
|
||||
reader.close();
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will call the Mock Server and Test it with sample values.
|
||||
* It will test the Leaderboard API call functionality and check if the object is
|
||||
* being created with the correct values
|
||||
* @throws IOException
|
||||
*/
|
||||
@Test
|
||||
public void apiTest() throws IOException {
|
||||
HttpUrl httpUrl = server.url(ENDPOINT);
|
||||
LeaderboardResponse response = sendRequest(new OkHttpClient(), httpUrl);
|
||||
|
||||
Assert.assertEquals(TEST_AVATAR, response.getAvatar());
|
||||
Assert.assertEquals(TEST_USERNAME, response.getUsername());
|
||||
Assert.assertEquals(Integer.valueOf(TEST_USER_RANK), response.getRank());
|
||||
Assert.assertEquals(Integer.valueOf(TEST_USER_COUNT), response.getCategoryCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will call the Mock API and returns the Leaderboard Response Object
|
||||
* @param okHttpClient
|
||||
* @param httpUrl
|
||||
* @return Leaderboard Response Object
|
||||
* @throws IOException
|
||||
*/
|
||||
private LeaderboardResponse sendRequest(OkHttpClient okHttpClient, HttpUrl httpUrl)
|
||||
throws IOException {
|
||||
Request request = new Builder().url(httpUrl).build();
|
||||
Response response = okHttpClient.newCall(request).execute();
|
||||
if (response.isSuccessful()) {
|
||||
Gson gson = new Gson();
|
||||
return gson.fromJson(response.body().string(), LeaderboardResponse.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method shuts down the Mock Server
|
||||
* @throws IOException
|
||||
*/
|
||||
@After
|
||||
public void shutdown() throws IOException {
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
package fr.free.nrw.commons.leaderboard;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import fr.free.nrw.commons.profile.leaderboard.UpdateAvatarResponse;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Request.Builder;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class UpdateAvatarApiTest {
|
||||
|
||||
private static final String TEST_USERNAME = "user";
|
||||
private static final String TEST_STATUS = "200";
|
||||
private static final String TEST_MESSAGE = "Avatar Updated";
|
||||
private static final String FILE_NAME = "update_leaderboard_avatar_sample_response.json";
|
||||
private static final String ENDPOINT = "/update_avatar.py";
|
||||
MockWebServer server;
|
||||
|
||||
/**
|
||||
* This method converts a Input Stream to String
|
||||
*
|
||||
* @param is takes Input Stream of JSON File as Parameter
|
||||
* @return a String with JSON data
|
||||
* @throws Exception
|
||||
*/
|
||||
private static String convertStreamToString(final InputStream is) throws Exception {
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line).append("\n");
|
||||
}
|
||||
reader.close();
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initialises a Mock Server
|
||||
*/
|
||||
@Before
|
||||
public void initTest() {
|
||||
server = new MockWebServer();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will setup a Mock Server and load Test JSON Response File
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
final String testResponseBody = convertStreamToString(
|
||||
getClass().getClassLoader().getResourceAsStream(FILE_NAME));
|
||||
|
||||
server.enqueue(new MockResponse().setBody(testResponseBody));
|
||||
server.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will call the Mock Server and Test it with sample values. It will test the Update
|
||||
* Avatar API call functionality and check if the object is being created with the correct
|
||||
* values
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Test
|
||||
public void apiTest() throws IOException {
|
||||
final HttpUrl httpUrl = server.url(ENDPOINT);
|
||||
final UpdateAvatarResponse response = sendRequest(new OkHttpClient(), httpUrl);
|
||||
|
||||
Assert.assertEquals(TEST_USERNAME, response.getUser());
|
||||
Assert.assertEquals(TEST_STATUS, response.getStatus());
|
||||
Assert.assertEquals(TEST_MESSAGE, response.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will call the Mock API and returns the Update Avatar Response Object
|
||||
*
|
||||
* @param okHttpClient
|
||||
* @param httpUrl
|
||||
* @return Update Avatar Response Object
|
||||
* @throws IOException
|
||||
*/
|
||||
private UpdateAvatarResponse sendRequest(final OkHttpClient okHttpClient, final HttpUrl httpUrl)
|
||||
throws IOException {
|
||||
final Request request = new Builder().url(httpUrl).build();
|
||||
final Response response = okHttpClient.newCall(request).execute();
|
||||
if (response.isSuccessful()) {
|
||||
final Gson gson = new Gson();
|
||||
return gson.fromJson(response.body().string(), UpdateAvatarResponse.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method shuts down the Mock Server
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@After
|
||||
public void shutdown() throws IOException {
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -442,4 +442,4 @@ class NearbyParentFragmentPresenterTest {
|
|||
verify(nearbyParentFragmentView).isNetworkConnectionEstablished()
|
||||
verifyZeroInteractions(nearbyParentFragmentView)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
19
app/src/test/resources/leaderboard_sample_response.json
Normal file
19
app/src/test/resources/leaderboard_sample_response.json
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"status": 200,
|
||||
"username": "user",
|
||||
"category_count": 0,
|
||||
"limit": null,
|
||||
"avatar": "avatar",
|
||||
"offset": null,
|
||||
"duration": "all_time",
|
||||
"leaderboard_list": [
|
||||
{
|
||||
"username": "user",
|
||||
"category_count": 0,
|
||||
"avatar": "avatar",
|
||||
"rank": 1
|
||||
}
|
||||
],
|
||||
"category": "used",
|
||||
"rank": 1
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"status": "200",
|
||||
"message": "Avatar Updated",
|
||||
"user": "user"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue