Skip to content

Commit

Permalink
Refactoring Register Call
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosdel committed Jan 4, 2018
1 parent 0b5e720 commit 5d33dd7
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 90 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import eu.jnksoftware.discountfinderandroid.models.discounts.DiscountPost;
import eu.jnksoftware.discountfinderandroid.models.discounts.TopDiscount;
import eu.jnksoftware.discountfinderandroid.models.token.FcmToken;
import eu.jnksoftware.discountfinderandroid.models.token.RegisterTokenRequest;
import eu.jnksoftware.discountfinderandroid.models.token.User;
import retrofit2.Call;
import retrofit2.http.Body;
Expand All @@ -37,8 +36,9 @@ public interface IuserService {
@POST("login")
Call<User> login(@Field("username")String username,@Field("password")String password);

@FormUrlEncoded
@POST("register")
Call<User> register(@Body RegisterTokenRequest registerTokenRequest);
Call<User> register(@Field("firstName")String firstName,@Field("lastName")String lastName,@Field("eMail")String eMail,@Field("password")String password);

@PUT("requestedDiscount/{id}")
Call<DiscountPreferencesResponse> putDiscountPreferences(@Path("id")int id,@Body DiscountPreferencesRequest discountPreferencesRequest,@Header("Authorization") String auth);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import eu.jnksoftware.discountfinderandroid.models.discounts.DiscountPost;
import eu.jnksoftware.discountfinderandroid.models.discounts.TopDiscount;
import eu.jnksoftware.discountfinderandroid.models.token.FcmToken;
import eu.jnksoftware.discountfinderandroid.models.token.RegisterTokenRequest;
import eu.jnksoftware.discountfinderandroid.models.token.User;
import retrofit2.Call;
import retrofit2.mock.BehaviorDelegate;
Expand All @@ -43,10 +42,12 @@ public Call<User> login(String username, String password) {
}

@Override
public Call<User> register(RegisterTokenRequest registerTokenRequest) {
public Call<User> register(String firstName, String lastName, String eMail, String password) {
return null;
}



@Override
public Call<DiscountPreferencesResponse> putDiscountPreferences(int id, DiscountPreferencesRequest discountPreferencesRequest, String auth) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import eu.jnksoftware.discountfinderandroid.Apis.ApiUtils;
import eu.jnksoftware.discountfinderandroid.R;
import eu.jnksoftware.discountfinderandroid.models.token.RegisterTokenRequest;
import eu.jnksoftware.discountfinderandroid.models.token.User;
import eu.jnksoftware.discountfinderandroid.services.IuserService;
import retrofit2.Call;
Expand All @@ -24,6 +23,10 @@ public class Register extends Activity {
private EditText password;
private EditText firstName;
private EditText lastName;
private String mail;
private String fName;
private String lName;
private String pass;
IuserService iuserService;
@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -44,21 +47,21 @@ protected void onCreate(Bundle savedInstanceState) {
public void onClick(final View reg) {


RegisterTokenRequest registerTokenRequest=new RegisterTokenRequest();
registerTokenRequest.setEMail(eMail.getText().toString().trim());
registerTokenRequest.setFirstName(firstName.getText().toString().trim());
registerTokenRequest.setLastName(lastName.getText().toString().trim());
registerTokenRequest.setPassword(password.getText().toString().trim());
doRegister(registerTokenRequest);

fName=firstName.getText().toString().trim();
lName=lastName.getText().toString().trim();
mail=eMail.getText().toString().trim();
pass=password.getText().toString().trim();
doRegister(fName,lName,mail,pass);





}
};
public void doRegister(final RegisterTokenRequest registerTokenRequest){
Call<User> call=iuserService.register(registerTokenRequest);
public void doRegister(String fName,String lName,String mail,String pass){
Call<User> call=iuserService.register(fName,lName,mail,pass);
call.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.io.IOException;


import eu.jnksoftware.discountfinderandroid.models.token.RegisterTokenRequest;
import eu.jnksoftware.discountfinderandroid.models.token.User;
import eu.jnksoftware.discountfinderandroid.services.IuserService;

Expand All @@ -21,13 +20,13 @@ public void testTokenType() throws IOException

{
IuserService s = ApiUtils.getMockUserService();
RegisterTokenRequest registerTokenRequest=new RegisterTokenRequest();
registerTokenRequest.setLastName("Delis");
registerTokenRequest.setFirstName("Nikos");
registerTokenRequest.setEMail("[email protected]");
registerTokenRequest.setPassword("123455");
String email="[email protected]";
String fname="nikos";
String lname="delis";
String pass="123456";

User user = s.register(registerTokenRequest).execute().body();

User user = s.register(fname,lname,email,pass).execute().body();
assertEquals("Bearer", user.getTokenType());

}
Expand All @@ -36,13 +35,13 @@ public void testTokenAccess() throws IOException

{
IuserService s = ApiUtils.getMockUserService();
RegisterTokenRequest registerTokenRequest=new RegisterTokenRequest();
registerTokenRequest.setLastName("Delis");
registerTokenRequest.setFirstName("Nikos");
registerTokenRequest.setEMail("[email protected]");
registerTokenRequest.setPassword("123455");
String email="[email protected]";
String fname="nikos";
String lname="delis";
String pass="123456";


User user = s.register(registerTokenRequest).execute().body();
User user = s.register(fname,lname,email,pass).execute().body();
assertEquals("mock_access", user.getAccessToken().toString());

}
Expand All @@ -51,13 +50,13 @@ public void testTokenRefresh() throws IOException

{
IuserService s = ApiUtils.getMockUserService();
RegisterTokenRequest registerTokenRequest=new RegisterTokenRequest();
registerTokenRequest.setLastName("Delis");
registerTokenRequest.setFirstName("Nikos");
registerTokenRequest.setEMail("[email protected]");
registerTokenRequest.setPassword("123455");
String email="[email protected]";
String fname="nikos";
String lname="delis";
String pass="123456";

User user = s.register(registerTokenRequest).execute().body();

User user = s.register(fname,lname,email,pass).execute().body();
assertEquals("mock_refresh", user.getRefreshToken().toString());

}
Expand All @@ -66,13 +65,13 @@ public void testExpiresIn() throws IOException

{
IuserService s = ApiUtils.getMockUserService();
RegisterTokenRequest registerTokenRequest=new RegisterTokenRequest();
registerTokenRequest.setLastName("Delis");
registerTokenRequest.setFirstName("Nikos");
registerTokenRequest.setEMail("[email protected]");
registerTokenRequest.setPassword("123455");
String email="[email protected]";
String fname="nikos";
String lname="delis";
String pass="123456";


User user = s.register(registerTokenRequest).execute().body();
User user = s.register(fname,lname,email,pass).execute().body();
assertEquals("7199", user.getExpiresIn().toString());

}
Expand Down

0 comments on commit 5d33dd7

Please sign in to comment.