test: add backend tests for various controllers and services
Some checks failed
Pull Request Labeler / labeler (pull_request_target) Successful in 8s
CI / Get Changed Files (pull_request) Successful in 12s
Setup Gitea Tea CLI / setup-and-login (pull_request) Failing after 28s
CI / oxlint (pull_request) Successful in 23s
CI / eslint (pull_request) Successful in 32s
CI / prettier (pull_request) Successful in 31s
CI / test-build (pull_request) Successful in 1m3s
CI / Checkstyle Main (pull_request) Successful in 1m37s
CI / Docker frontend validation (pull_request) Failing after 1m50s
CI / Docker backend validation (pull_request) Successful in 2m48s
CI / Backend Tests (pull_request) Failing after 4m3s
Some checks failed
Pull Request Labeler / labeler (pull_request_target) Successful in 8s
CI / Get Changed Files (pull_request) Successful in 12s
Setup Gitea Tea CLI / setup-and-login (pull_request) Failing after 28s
CI / oxlint (pull_request) Successful in 23s
CI / eslint (pull_request) Successful in 32s
CI / prettier (pull_request) Successful in 31s
CI / test-build (pull_request) Successful in 1m3s
CI / Checkstyle Main (pull_request) Successful in 1m37s
CI / Docker frontend validation (pull_request) Failing after 1m50s
CI / Docker backend validation (pull_request) Successful in 2m48s
CI / Backend Tests (pull_request) Failing after 4m3s
This commit is contained in:
parent
7be0fc97bc
commit
aa18bf15f1
17 changed files with 416 additions and 0 deletions
|
@ -78,6 +78,32 @@ jobs:
|
||||||
working-directory: ./backend
|
working-directory: ./backend
|
||||||
run: gradle --stop
|
run: gradle --stop
|
||||||
|
|
||||||
|
backend-test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: "Backend Tests"
|
||||||
|
needs: changed_files
|
||||||
|
if: ${{ needs.changed_files.outputs.backend == 'true' || needs.changed_files.outputs.workflow == 'true' }}
|
||||||
|
container:
|
||||||
|
image: "cimg/openjdk:23.0-node"
|
||||||
|
steps:
|
||||||
|
- name: "Checkout"
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: "Cache Gradle dependencies"
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.gradle/caches
|
||||||
|
~/.gradle/wrapper
|
||||||
|
key: gradle-${{ runner.os }}-${{ hashFiles('backend/**/*.java', 'backend/build.gradle.kts', 'backend/settings.gradle.kts') }}
|
||||||
|
restore-keys: |
|
||||||
|
gradle-${{ runner.os }}-
|
||||||
|
- name: "Run backend tests"
|
||||||
|
working-directory: ./backend
|
||||||
|
run: ./gradlew test
|
||||||
|
- name: "Stop Gradle"
|
||||||
|
working-directory: ./backend
|
||||||
|
run: ./gradlew --stop
|
||||||
|
|
||||||
validate-docker-frontend:
|
validate-docker-frontend:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: Docker frontend validation
|
name: Docker frontend validation
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package de.szut.casino.blackjack;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class BlackJackGameControllerTest {
|
||||||
|
@InjectMocks
|
||||||
|
private BlackJackGameController controller;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
MockitoAnnotations.openMocks(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testControllerNotNull() {
|
||||||
|
assertNotNull(controller);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package de.szut.casino.blackjack;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class BlackJackServiceTest {
|
||||||
|
@InjectMocks
|
||||||
|
private BlackJackService blackJackService;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
MockitoAnnotations.openMocks(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testServiceNotNull() {
|
||||||
|
assertNotNull(blackJackService);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
package de.szut.casino.coinflip;
|
||||||
|
|
||||||
|
import de.szut.casino.exceptionHandling.exceptions.InsufficientFundsException;
|
||||||
|
import de.szut.casino.exceptionHandling.exceptions.UserNotFoundException;
|
||||||
|
import de.szut.casino.shared.service.BalanceService;
|
||||||
|
import de.szut.casino.user.UserEntity;
|
||||||
|
import de.szut.casino.user.UserService;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
class CoinflipControllerTest {
|
||||||
|
@Mock
|
||||||
|
private UserService userService;
|
||||||
|
@Mock
|
||||||
|
private BalanceService balanceService;
|
||||||
|
@Mock
|
||||||
|
private CoinflipService coinflipService;
|
||||||
|
@InjectMocks
|
||||||
|
private CoinflipController coinflipController;
|
||||||
|
|
||||||
|
private UserEntity user;
|
||||||
|
private CoinflipDto coinflipDto;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
MockitoAnnotations.openMocks(this);
|
||||||
|
user = new UserEntity();
|
||||||
|
user.setBalance(BigDecimal.valueOf(100));
|
||||||
|
coinflipDto = new CoinflipDto(BigDecimal.valueOf(10), CoinSide.HEAD);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testCoinFlip_success() {
|
||||||
|
when(userService.getCurrentUser()).thenReturn(Optional.of(user));
|
||||||
|
when(balanceService.hasFunds(user, coinflipDto)).thenReturn(true);
|
||||||
|
CoinflipResult result = new CoinflipResult(true, BigDecimal.valueOf(20), CoinSide.HEAD);
|
||||||
|
when(coinflipService.play(user, coinflipDto)).thenReturn(result);
|
||||||
|
|
||||||
|
ResponseEntity<Object> response = coinflipController.coinFlip(coinflipDto);
|
||||||
|
|
||||||
|
assertEquals(200, response.getStatusCodeValue());
|
||||||
|
assertEquals(result, response.getBody());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testCoinFlip_userNotFound() {
|
||||||
|
when(userService.getCurrentUser()).thenReturn(Optional.empty());
|
||||||
|
assertThrows(UserNotFoundException.class, () -> coinflipController.coinFlip(coinflipDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testCoinFlip_insufficientFunds() {
|
||||||
|
when(userService.getCurrentUser()).thenReturn(Optional.of(user));
|
||||||
|
when(balanceService.hasFunds(user, coinflipDto)).thenReturn(false);
|
||||||
|
assertThrows(InsufficientFundsException.class, () -> coinflipController.coinFlip(coinflipDto));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package de.szut.casino.deposit;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class DepositControllerTest {
|
||||||
|
@InjectMocks
|
||||||
|
private DepositController controller;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
MockitoAnnotations.openMocks(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testControllerNotNull() {
|
||||||
|
assertNotNull(controller);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package de.szut.casino.deposit;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class TransactionServiceTest {
|
||||||
|
@InjectMocks
|
||||||
|
private TransactionService transactionService;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
MockitoAnnotations.openMocks(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testServiceNotNull() {
|
||||||
|
assertNotNull(transactionService);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package de.szut.casino.deposit;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class WebhookControllerTest {
|
||||||
|
@InjectMocks
|
||||||
|
private WebhookController controller;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
MockitoAnnotations.openMocks(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testControllerNotNull() {
|
||||||
|
assertNotNull(controller);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package de.szut.casino.dice;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class DiceControllerTest {
|
||||||
|
@InjectMocks
|
||||||
|
private DiceController controller;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
MockitoAnnotations.openMocks(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testControllerNotNull() {
|
||||||
|
assertNotNull(controller);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package de.szut.casino.dice;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class DiceServiceTest {
|
||||||
|
@InjectMocks
|
||||||
|
private DiceService diceService;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
MockitoAnnotations.openMocks(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testServiceNotNull() {
|
||||||
|
assertNotNull(diceService);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package de.szut.casino.health;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class HealthControllerTest {
|
||||||
|
@InjectMocks
|
||||||
|
private HealthController controller;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
MockitoAnnotations.openMocks(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testControllerNotNull() {
|
||||||
|
assertNotNull(controller);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package de.szut.casino.lootboxes;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class LootBoxServiceTest {
|
||||||
|
@InjectMocks
|
||||||
|
private LootBoxService lootBoxService;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
MockitoAnnotations.openMocks(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testServiceNotNull() {
|
||||||
|
assertNotNull(lootBoxService);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package de.szut.casino.security;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class AuthControllerTest {
|
||||||
|
@InjectMocks
|
||||||
|
private AuthController controller;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
MockitoAnnotations.openMocks(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testControllerNotNull() {
|
||||||
|
assertNotNull(controller);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package de.szut.casino.slots;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class SlotControllerTest {
|
||||||
|
@InjectMocks
|
||||||
|
private SlotController controller;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
MockitoAnnotations.openMocks(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testControllerNotNull() {
|
||||||
|
assertNotNull(controller);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package de.szut.casino.slots;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class SlotServiceTest {
|
||||||
|
@InjectMocks
|
||||||
|
private SlotService slotService;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
MockitoAnnotations.openMocks(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testServiceNotNull() {
|
||||||
|
assertNotNull(slotService);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package de.szut.casino.user;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class UserControllerTest {
|
||||||
|
@InjectMocks
|
||||||
|
private UserController controller;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
MockitoAnnotations.openMocks(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testControllerNotNull() {
|
||||||
|
assertNotNull(controller);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package de.szut.casino.user;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class UserServiceTest {
|
||||||
|
@InjectMocks
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
MockitoAnnotations.openMocks(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testServiceNotNull() {
|
||||||
|
assertNotNull(userService);
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue