feature_user #15
118
wrapper/src/test/java/wekan/wrapper/api/UserServiceTest.java
Normal file
118
wrapper/src/test/java/wekan/wrapper/api/UserServiceTest.java
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
package wekan.wrapper.api;
|
||||||
|
|
||||||
|
import okhttp3.mockwebserver.MockResponse;
|
||||||
|
import okhttp3.mockwebserver.MockWebServer;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import retrofit2.Retrofit;
|
||||||
|
import retrofit2.converter.gson.GsonConverterFactory;
|
||||||
|
import wekan.wrapper.entity.User;
|
||||||
|
import wekan.wrapper.entity.UserEmail;
|
||||||
|
import wekan.wrapper.entity.UserProfile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class UserServiceTest {
|
||||||
|
private MockWebServer mockWebServer = new MockWebServer();
|
||||||
|
private UserService service = null;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
try {
|
||||||
|
mockWebServer.start();
|
||||||
|
service = new Retrofit.Builder()
|
||||||
|
.baseUrl(mockWebServer.url("/"))
|
||||||
|
.addConverterFactory(GsonConverterFactory.create())
|
||||||
|
.build()
|
||||||
|
.create(UserService.class);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void teardown() {
|
||||||
|
try {
|
||||||
|
mockWebServer.shutdown();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAllUsersTest(){
|
||||||
|
MockResponse response = new MockResponse()
|
||||||
|
.setResponseCode(HttpURLConnection.HTTP_OK)
|
||||||
|
.setBody(
|
||||||
|
"[{\"_id\":\"Si69gNgkJfQuk6uiJ\",\"username\":\"norangebit\"}," +
|
||||||
|
"{\"_id\":\"8rsnfEPkfMS49Pv6q\",\"username\":\"noemi\"}," +
|
||||||
|
"{\"_id\":\"jPdkf3a9bmfZWx3GR\",\"username\":\"umberto\"}]"
|
||||||
|
);
|
||||||
|
mockWebServer.enqueue(response);
|
||||||
|
|
||||||
|
try{
|
||||||
|
List<User> users = service.getAllUser().execute().body();
|
||||||
|
assertNotNull(users);
|
||||||
|
assertEquals("Si69gNgkJfQuk6uiJ", users.get(0).getId());
|
||||||
|
assertEquals("norangebit", users.get(0).getUsername());
|
||||||
|
assertEquals("8rsnfEPkfMS49Pv6q", users.get(1).getId());
|
||||||
|
assertEquals("noemi", users.get(1).getUsername());
|
||||||
|
assertEquals("jPdkf3a9bmfZWx3GR", users.get(2).getId());
|
||||||
|
assertEquals("umberto", users.get(2).getUsername());
|
||||||
|
}
|
||||||
|
catch (IOException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getUser(){
|
||||||
|
MockResponse response = new MockResponse()
|
||||||
|
.setResponseCode(HttpURLConnection.HTTP_OK)
|
||||||
|
.setBody(user1);
|
||||||
|
mockWebServer.enqueue(response);
|
||||||
|
|
||||||
|
try {
|
||||||
|
User user = service.getUser("jPdkf3a9bmfZWx3GR").execute().body();
|
||||||
|
assert user != null;
|
||||||
|
List<UserEmail> userEmail = user.getEmails();
|
||||||
|
UserProfile userProfile = user.getProfile();
|
||||||
|
assertEquals("jPdkf3a9bmfZWx3GR", user.getId());
|
||||||
|
assertEquals("umberto", user.getUsername());
|
||||||
|
assertEquals("password", user.getAuthenticationMethod());
|
||||||
|
assertTrue(user.isAdmin());
|
||||||
|
assertEquals("2019-10-14T18:14:38.249Z", user.getCreatedAt());
|
||||||
|
assertFalse(userEmail.isEmpty());
|
||||||
|
assertEquals("umbertof993@gmail.com", userEmail.get(0).getEmail());
|
||||||
|
assertFalse(userEmail.get(0).isVerified());
|
||||||
|
assertEquals("board-view-swimlanes", userProfile.getBoardView());
|
||||||
|
assertEquals("zo82BZYxFTNBpb7jX", userProfile.getCardTemplatesSwimlaneId());
|
||||||
|
assertEquals("-modifiedAt", userProfile.getListSortBy());
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static final String user1 = "{" +
|
||||||
|
"\"_id\":\"jPdkf3a9bmfZWx3GR\"," +
|
||||||
|
"\"username\":\"umberto\"," +
|
||||||
|
"\"emails\":[{\"address\":\"umbertof993@gmail.com\",\"verified\":false}]," +
|
||||||
|
"\"authenticationMethod\":\"password\"," +
|
||||||
|
"\"isAdmin\":\"true\"," +
|
||||||
|
"\"loginDisabled\":\"true\"," +
|
||||||
|
"\"profile\":{\"boardView\":\"board-view-swimlanes\",\"templatesBoardId\":\"eLvE8FnqvACfC9Rtb\"," +
|
||||||
|
"\"cardTemplatesSwimlaneId\":\"zo82BZYxFTNBpb7jX\",\"listTemplatesSwimlaneId\":\"Kja32A85P2HADWKFA\"," +
|
||||||
|
"\"boardTemplatesSwimlaneId\":\"j6ZuPbwaN9nsCDxyS\",\"listSortBy\":\"-modifiedAt\"}," +
|
||||||
|
"\"createdAt\":\"2019-10-14T18:14:38.249Z\","+
|
||||||
|
"\"modifiedAt\":\"2019-11-09T17:55:36.976Z\"," +
|
||||||
|
"}";
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user