Commit 061ec833 authored by Anesa Fazlagić's avatar Anesa Fazlagić
Browse files

added missing test in statistics for create method

parent c1c368b6
Loading
Loading
Loading
Loading
Loading
+13 −11
Original line number Diff line number Diff line
package cz.muni.fi.pa165.statistics.statistics;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -14,7 +13,7 @@ import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;

@SpringBootTest
@AutoConfigureMockMvc
@@ -42,14 +41,9 @@ public class UserStatisticsControllerTest {
		String response = mockMvc.perform(get(URL + "/all?userId=" + statisticCreateDto.getUserId())
						.contentType(CONTENT_TYPE)
						.content(objectMapper.writeValueAsString(statisticCreateDto)))
				//.andExpect(status().is4xxClientError())
				.andReturn()
				.getResponse()
				.getContentAsString();
		/*List<UserStatisticsDto> userStatisticsDto = objectMapper.readValue(response, new TypeReference<List<UserStatisticsDto>>() {
		});

		assertEquals(userStatisticsDto, l);*/
	}

	@Test
@@ -63,13 +57,21 @@ public class UserStatisticsControllerTest {
						+ "&houseId=" + statisticCreateDto.getHouseId())
						.contentType(CONTENT_TYPE)
						.content(objectMapper.writeValueAsString(statisticCreateDto)))
				//.andExpect(status().is4xxClientError())
				.andReturn()
				.getResponse()
				.getContentAsString();
		/*List<UserStatisticsDto> userStatisticsDto = objectMapper.readValue(response, new TypeReference<List<UserStatisticsDto>>() {
		});
	}

		assertEquals(userStatisticsDto, l);*/
	@Test
	void createStatisticsTest() throws Exception {
		StatisticCreateDto statisticCreateDto = StatisticCreateDto.builder().build();
		statisticCreateDto.setMonthNum(3);
		String jsonBody = objectMapper.writeValueAsString(statisticCreateDto);
		String response = mockMvc.perform(post(URL)
						.contentType(CONTENT_TYPE)
						.content(jsonBody))
				.andReturn()
				.getResponse()
				.getContentAsString();
	}
}