|
| 1 | +package com.faforever.api.data; |
| 2 | + |
| 3 | +import com.faforever.api.AbstractIntegrationTest; |
| 4 | +import com.faforever.api.data.domain.BanStatus; |
| 5 | +import com.faforever.api.email.EmailSender; |
| 6 | +import com.faforever.api.player.PlayerRepository; |
| 7 | +import org.junit.Ignore; |
| 8 | +import org.junit.Test; |
| 9 | +import org.mockito.Mockito; |
| 10 | +import org.springframework.beans.factory.annotation.Autowired; |
| 11 | +import org.springframework.boot.test.mock.mockito.MockBean; |
| 12 | +import org.springframework.security.test.context.support.WithUserDetails; |
| 13 | +import org.springframework.test.context.jdbc.Sql; |
| 14 | +import org.springframework.test.context.jdbc.Sql.ExecutionPhase; |
| 15 | + |
| 16 | +import static org.hamcrest.core.Is.is; |
| 17 | +import static org.junit.Assert.assertThat; |
| 18 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; |
| 19 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
| 20 | + |
| 21 | +@Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/prepDefaultUser.sql") |
| 22 | +@Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/prepBanRevokeData.sql") |
| 23 | +@Sql(executionPhase = ExecutionPhase.AFTER_TEST_METHOD, scripts = "classpath:sql/cleanBanRevokeData.sql") |
| 24 | +public class BanRevokeElideTest extends AbstractIntegrationTest { |
| 25 | + @MockBean |
| 26 | + private EmailSender emailSender; |
| 27 | + @Autowired |
| 28 | + private PlayerRepository playerRepository; |
| 29 | + /* |
| 30 | +{"data":{"type":"banRevokeData","attributes":{"reason":"unban"},"relationships":{"ban":{"data":{"type":"banInfo","id":"1"}},"author":{"data":{"type":"player","id":"2"}}}}} */ |
| 31 | + private static final String TEST_REVOKE="{\"data\":{\"type\":\"banRevokeData\",\"attributes\":{\"reason\":\"unban\"},\"relationships\":{\"ban\":{\"data\":{\"type\":\"banInfo\",\"id\":\"1\"}},\"author\":{\"data\":{\"type\":\"player\",\"id\":\"2\"}}}}}"; |
| 32 | + |
| 33 | + @Ignore(value = "Posting of ban revokes never worked, moderator use to change expire date instead see issue #259") |
| 34 | + @WithUserDetails(AUTH_MODERATOR) |
| 35 | + @Test |
| 36 | + public void testRevokeBanWithId1() throws Exception { |
| 37 | + assertThat(playerRepository.getOne(4).getBans().size(), is(1)); |
| 38 | + assertThat(playerRepository.getOne(4).getBans().iterator().next().getBanStatus(), is(BanStatus.BANNED)); |
| 39 | + |
| 40 | + mockMvc.perform(post("/data/banRevokeData") |
| 41 | + .content(TEST_REVOKE)) |
| 42 | + .andExpect(status().isCreated()); |
| 43 | + |
| 44 | + assertThat(playerRepository.getOne(4).getBans().iterator().next().getBanStatus(), is(BanStatus.DISABLED)); |
| 45 | + Mockito.verify(emailSender).sendMail("","","","",""); |
| 46 | + } |
| 47 | +} |
0 commit comments