xebia-functional / nine-cards-v2

An Open Source Android Launcher built with Scala on Android
http://www.9cards.io/
Other
183 stars 20 forks source link

Rankings - Refresh endpoints #605

Closed diesalbla closed 8 years ago

diesalbla commented 8 years ago

Source Location: the processes and api modules of the Backend API.

Goal: to implement a set of endpoints to update the application rankings.

API: the endpoints to create would be the following:

Processes: to support those endpoints, create a set of processes that combine the services for fetching rankings from google analytics (#603) and writing them to a database (#604).

diesalbla commented 8 years ago

Here is the PR.

diesalbla commented 8 years ago

The instructions for the QA are as follows:

For the setup, you should run sbt in local mode ``sbt -Dconfig.file="modules/api/src/main/resources/localhost.conf". In sbt, run the commands flywayClean and flywayMigrate, to clean the database.

To run the reload endpoint, you will need an access token on the Analytics Reports of NineCards. To get it, you should follow the steps described here. Once you have obtained the token in Postman: open the tab Authorization, select the token from the Existing Tokens panel at the left side, and copy the text that appears in the field access_token on the panel at the right. That is the access token for the endpoints.

With that access token, you can perform the tests. You have to run the application in local mode, with the command ``sbt -Dconfig.file="modules/api/src/main/resources/localhost.conf" api/run.

1) Get empty rankings. After migrating the DB, the rankings are empty. To see the contents of each ranking, you have to run requests of the form curl "http://localhost:8080/rankings/SCOPE", where SCOPE indicates if it is the world's, a continent's, o a country ranking. This request does not take any header or body parameters This SCOPE can be one of the following:

The endpoint should return 200 OK if the Country or continent is correct, and 400 BadRequest in other case. The response body should be a Json object with a categories field, whose value is an empty list.

2) Reload. To reload each ranking, you have to use a request to the same path as the ranking you want to reload, with the POST method. This request would be as follows:

curl -X POST \
  -H "Content-Type: application/json"  \
  -H "X-Google-Analytics-Token: <OAUTH_TOKEN_ANALYTICS>" \
 -d '{ "rankingLength" : 5, "startDate" : "2016-07-01", "endDate" : "2016-08-01"}'  \
  "http://localhost:8080/rankings/countries/Spain"

The response should be 200 OK, and the body should be an empty json object (a pair f braces {}).

_3) Read again _ the ranking that you refreshed using the get endpoint again. You should see the ranking object, such as the following one:

{
  "categories": [
    {
      "category": "EDUCATION",
      "apps": [
        "org.coursera.android"
      ]
    },
    {
      "category": "MEDIA_AND_VIDEO",
      "apps": [
        "com.google.android.youtube",
        "com.netflix.mediaclient",
        "com.neuralprisma",
        "dp.ws.popcorntime",
        "com.imdb.mobile"
      ]
    },
    [...]

Note that in each category there are at most as many items as the value in the rankingLength parameter in the request.

javipacheco commented 8 years ago

Steps work as expected. LGTM!