package ca.corefacility.bioinformatics.irida.web.controller.test.integration.user;

import java.util.HashMap;
import java.util.Map;

import org.apache.http.HttpStatus;
import org.junit.Test;

import static com.jayway.restassured.RestAssured.expect;
import static com.jayway.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.is;

/**
 * Integration tests for users.
 * 
 * @author Franklin Bristow <franklin.bristow@phac-aspc.gc.ca>
 */
public class UsersIntegrationTest {

	@Test
	public void testGetAllUsers() {
		expect().body("resource.links.rel", hasItems("self", "collection/pages/first")).and()
				.body("resource.resources.username", hasItem("fbristow")).when().get("/users/all");
	}

	@Test
	public void testGetCurrentUser() {
		expect().body("resource.links.rel", hasItems("self", "user/projects")).and()
				.body("resource.username", is("fbristow")).when().get("/users/current");
	}

	@Test
	public void testCreateUserFail() {
		Map<String, String> user = new HashMap<>();
		user.put("username", "franklin");
		user.put("password", "Password1");
		user.put("email", "fbristow@phac-aspc.gc.ca");
		user.put("firstName", "Franklin");
		user.put("lastName", "Bristow");
		user.put("phoneNumber", "7029");
		// doesn't matter what the user is, we should fail here when trying to
		// create a user because the current user doesn't have permission to
		// create users.
		given().body(user).expect().response().statusCode(HttpStatus.SC_FORBIDDEN).when().post("/users");
	}
}

@@ -1052,16 +1052,537 @@
 ail() %7B%0A
+%09%09// doesn't matter what the user is, we should fail here when trying to%0A%09%09// create a user because the current user doesn't have permission to%0A%09%09// create users.%0A%09%09given().body(createUser()).expect().response().statusCode(HttpStatus.SC_FORBIDDEN).when().post(%22/users%22);%0A%09%7D%0A%0A%09@Test%0A%09public void testCreateUserSucceed() %7B%0A%09%09given().body(createUser()).and().auth().basic(%22admin%22, %22password1%22).expect().response()%0A%09%09%09%09.statusCode(HttpStatus.SC_CREATED).when().post(%22/users%22);%0A%09%7D%0A%0A%09private Map%3CString, String%3E createUser() %7B%0A
 %09%09Map%3CSt
@@ -1854,267 +1854,19 @@
 ;%0A%09%09
-// doesn't matter what the user is, we should fail here when trying to%0A%09%09// create a user because the current user doesn't have permission to%0A%09%09// create users.%0A%09%09given().body(user).expect().response().statusCode(HttpStatus.SC_FORBIDDEN).when().post(%22/users%22)
+return user
 ;%0A%09%7D

Test that administrative users can create users.