diff --git a/src/main/kotlin/edu/ntnu/idi/idatt/backend/bootstrap/DevDataBootstrap.kt b/src/main/kotlin/edu/ntnu/idi/idatt/backend/bootstrap/DevDataBootstrap.kt index 8f9e5e9a..a7611edd 100644 --- a/src/main/kotlin/edu/ntnu/idi/idatt/backend/bootstrap/DevDataBootstrap.kt +++ b/src/main/kotlin/edu/ntnu/idi/idatt/backend/bootstrap/DevDataBootstrap.kt @@ -60,6 +60,7 @@ class DevDataBootstrap( private val notebookEntryRepository: NotebookEntryRepository, private val passwordEncoder: PasswordEncoder, private val mapStopBootstrap: MapStopBootstrap, + private val medalBootstrap: MedalBootstrap, private val taskBootstrap: TaskBootstrap, private val pupilProgressSeedingService: PupilProgressSeedingService, private val pupilStopProgressRepository: PupilStopProgressRepository, @@ -170,6 +171,7 @@ class DevDataBootstrap( ) mapStopBootstrap.seedAllMapStops() + medalBootstrap.seedAllMedals() val activeStops = taskBootstrap.seedAllTasks(classroom = sampleClassroom, teacher = teacher) seedNotebookEntries( classroom = sampleClassroom, diff --git a/src/main/kotlin/edu/ntnu/idi/idatt/backend/bootstrap/MedalBootstrap.kt b/src/main/kotlin/edu/ntnu/idi/idatt/backend/bootstrap/MedalBootstrap.kt new file mode 100644 index 00000000..20d2acbb --- /dev/null +++ b/src/main/kotlin/edu/ntnu/idi/idatt/backend/bootstrap/MedalBootstrap.kt @@ -0,0 +1,50 @@ +package edu.ntnu.idi.idatt.backend.bootstrap + +import edu.ntnu.idi.idatt.backend.game.mapstops.infrastructure.MapStopsRepository +import edu.ntnu.idi.idatt.backend.game.medals.domain.Medal +import edu.ntnu.idi.idatt.backend.game.medals.domain.MedalType +import edu.ntnu.idi.idatt.backend.game.medals.repository.MedalRepository +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty +import org.springframework.stereotype.Component + +@Component +@ConditionalOnProperty(name = ["app.bootstrap.enabled"], havingValue = "true") +class MedalBootstrap( + private val medalRepository: MedalRepository, + private val mapStopsRepository: MapStopsRepository, +) { + fun seedAllMedals() { + mapStopsRepository.findAllByIsActiveTrueOrderByDisplayOrderAsc().forEach { stop -> + val stopId = requireNotNull(stop.id) { "Seeded map stop must have an id" } + val slug = requireNotNull(stop.slug) { "Seeded map stop must have a slug" } + val title = requireNotNull(stop.title) { "Seeded map stop must have a title" } + val code = "${slug}-completion" + + if (medalRepository.findByCode(code) == null) { + medalRepository.save( + Medal( + code = code, + title = "$title fullført", + description = "Tildeles når eleven fullfører stop nummer $stopId: $title.", + medalType = MedalType.STOP_COMPLETION, + stop = stop, + iconUrl = null, + ), + ) + } + } + + if (medalRepository.findByCode("example-approval") == null) { + medalRepository.save( + Medal( + code = "example-approval", + title = "Eksempelgodkjenning", + description = "Tildeles når et eksempelinnhold blir godkjent.", + medalType = MedalType.EXAMPLE_APPROVAL, + stop = null, + iconUrl = null, + ), + ) + } + } +} diff --git a/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/mapstops/application/PupilStopProgressService.kt b/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/mapstops/application/PupilStopProgressService.kt index 1d8b2843..f2680a41 100644 --- a/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/mapstops/application/PupilStopProgressService.kt +++ b/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/mapstops/application/PupilStopProgressService.kt @@ -20,6 +20,10 @@ import java.time.Instant * Application service that handles progress lookup and state transitions for pupil map stops. * * @property progressRepository JPA repository for pupil stop progress records + * @property mapStopRepository Repository for map stop definitions + * @property medalService Service for awarding medals upon stop completion + * @property userRepository Repository for user lookup + * @property classroomRepository Repository for classroom lookup */ @Service class PupilStopProgressService( diff --git a/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/medals/api/MedalsController.kt b/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/medals/api/MedalsController.kt new file mode 100644 index 00000000..64ba75a5 --- /dev/null +++ b/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/medals/api/MedalsController.kt @@ -0,0 +1,83 @@ +package edu.ntnu.idi.idatt.backend.game.medals.api + +import edu.ntnu.idi.idatt.backend.game.medals.application.MedalService +import edu.ntnu.idi.idatt.backend.game.medals.domain.Medal +import edu.ntnu.idi.idatt.backend.game.medals.domain.PupilMedal +import edu.ntnu.idi.idatt.backend.iam.application.CurrentUserResolver +import edu.ntnu.idi.idatt.backend.iam.security.CurrentUser +import org.springframework.http.HttpStatus +import org.springframework.security.core.annotation.AuthenticationPrincipal +import org.springframework.web.bind.annotation.* +import org.springframework.web.server.ResponseStatusException + +/** + * API controller for pupil medal operations. + * + * @property medalService Service for managing medal logic + * @property currentUserResolver Resolver for authenticated user and classroom context + */ +@RestController +@RequestMapping("/api/v1/pupil/medals") +class MedalsController( + private val medalService: MedalService, + private val currentUserResolver: CurrentUserResolver +) { + /** + * Retrieves an overview of all medals and whether the current pupil has earned them. + * + * @param currentUser the authenticated principal + * @return a response containing all medals and their earned status + */ + @GetMapping + fun getMedals(@AuthenticationPrincipal currentUser: CurrentUser): MedalOverviewResponse { + val pupil = currentUserResolver.requirePupil(currentUser.subject) + val classroom = currentUserResolver.getClassroomByUser(currentUser) + + val allMedals = medalService.getAllMedals() + val earnedMedals = medalService.getPupilMedals(pupil, classroom) + + val earnedMedalIds = earnedMedals.map { it.medal.id }.toSet() + + return MedalOverviewResponse( + medals = allMedals.map { medal -> + MedalEntry( + medal = medal, + earned = earnedMedalIds.contains(medal.id) + ) + } + ) + } + + /** + * Retrieves detailed information about a specific medal. + * + * @param id the ID of the medal to retrieve + * @return the medal details + * @throws ResponseStatusException 404 if the medal is not found + */ + @GetMapping("/{id}") + fun getMedal(@PathVariable id: Long): Medal { + return medalService.getMedalById(id) + ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Medal not found") + } +} + +/** + * Response containing an overview of medals. + * + * @property medals list of medal entries + */ +data class MedalOverviewResponse( + val medals: List +) + +/** + * An entry in the medal overview, combining medal info with earned status. + * + * @property medal the medal definition + * @property earned whether the pupil has earned this medal + */ +data class MedalEntry( + val medal: Medal, + val earned: Boolean +) diff --git a/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/medals/application/MedalService.kt b/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/medals/application/MedalService.kt new file mode 100644 index 00000000..b053efac --- /dev/null +++ b/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/medals/application/MedalService.kt @@ -0,0 +1,98 @@ +package edu.ntnu.idi.idatt.backend.game.medals.application + +import edu.ntnu.idi.idatt.backend.game.medals.domain.Medal +import edu.ntnu.idi.idatt.backend.game.medals.domain.PupilMedal +import edu.ntnu.idi.idatt.backend.game.medals.repository.MedalRepository +import edu.ntnu.idi.idatt.backend.game.medals.repository.PupilMedalRepository +import edu.ntnu.idi.idatt.backend.iam.domain.User +import edu.ntnu.idi.idatt.backend.classroom.domain.Classroom +import org.springframework.dao.DataIntegrityViolationException +import org.springframework.stereotype.Service +import org.springframework.transaction.PlatformTransactionManager +import org.springframework.transaction.TransactionDefinition +import org.springframework.transaction.annotation.Transactional +import org.springframework.transaction.support.TransactionTemplate +import java.util.stream.Collectors + +/** + * Application service for managing medals and awarding them to pupils. + * + * @property medalRepository Repository for medal definitions + * @property pupilMedalRepository Repository for pupil-earned medals + */ +@Service +class MedalService( + private val medalRepository: MedalRepository, + private val pupilMedalRepository: PupilMedalRepository, + transactionManager: PlatformTransactionManager, +) { + private val awardTransaction = TransactionTemplate(transactionManager).apply { + propagationBehavior = TransactionDefinition.PROPAGATION_REQUIRES_NEW + } + + /** + * Retrieves a medal by its ID. + * + * @param id the ID of the medal to retrieve + * @return the medal if found, or null otherwise + */ + @Transactional(readOnly = true) + fun getMedalById(id: Long): Medal? = medalRepository.findById(id).orElse(null) + + /** + * Retrieves all available medal definitions. + * + * @return a list of all medals + */ + @Transactional(readOnly = true) + fun getAllMedals(): List = medalRepository.findAll() + + /** + * Retrieves all medals earned by a specific pupil in a specific classroom. + * + * @param pupil the pupil whose medals to retrieve + * @param classroom the classroom context + * @return a list of earned medals + */ + @Transactional(readOnly = true) + fun getPupilMedals(pupil: User, classroom: Classroom): List { + val pupilId = requireNotNull(pupil.id) { "Pupil is missing an id" } + val classroomId = requireNotNull(classroom.id) { "Classroom is missing an id" } + return pupilMedalRepository.findAllByPupilIdAndClassroomId(pupilId, classroomId).collect(Collectors.toList()) + } + + /** + * Awards a stop-related medal to a pupil if they haven't already earned it. + * + * @param pupil the pupil to award the medal to + * @param classroom the classroom context + * @param stopId the ID of the stop that triggers the medal + */ + fun awardStopMedal(pupil: User, classroom: Classroom, stopId: Long) { + val medal = medalRepository.findByStopId(stopId) ?: return + val pupilId = requireNotNull(pupil.id) { "Pupil is missing an id" } + val classroomId = requireNotNull(classroom.id) { "Classroom is missing an id" } + if (!pupilMedalRepository.existsByPupilIdAndClassroomIdAndMedalId(pupilId, classroomId, medal.id)) { + try { + awardTransaction.executeWithoutResult { + pupilMedalRepository.saveAndFlush( + PupilMedal( + pupil = pupil, + classroom = classroom, + medal = medal, + ) + ) + } + } catch (exception: DataIntegrityViolationException) { + val alreadyAwarded = pupilMedalRepository.existsByPupilIdAndClassroomIdAndMedalId( + pupilId, + classroomId, + medal.id, + ) + if (!alreadyAwarded) { + throw exception + } + } + } + } +} diff --git a/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/medals/domain/Medal.kt b/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/medals/domain/Medal.kt new file mode 100644 index 00000000..280cd12d --- /dev/null +++ b/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/medals/domain/Medal.kt @@ -0,0 +1,43 @@ +package edu.ntnu.idi.idatt.backend.game.medals.domain + +import edu.ntnu.idi.idatt.backend.game.mapstops.domain.MapStop +import jakarta.persistence.* + +/** + * Represents a medal that can be earned by a pupil. + * + * @property id Unique identifier for the medal. + * @property code Unique code identifying the medal (e.g., "stop-1-completion"). + * @property title Human-readable title of the medal. + * @property description Detailed description of how to earn the medal. + * @property medalType The type of medal (e.g., [MedalType.STOP_COMPLETION]). + * @property stop The map stop associated with this medal, if any. + * @property iconUrl URL to the icon representing the medal. + */ +@Entity +@Table(name = "medals") +class Medal( + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long = 0, + + @Column(nullable = false, unique = true) + val code: String, + + @Column(nullable = false) + val title: String, + + @Column + val description: String?, + + @Enumerated(EnumType.STRING) + @Column(nullable = false) + val medalType: MedalType, + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "stop_id") + val stop: MapStop?, + + @Column + val iconUrl: String? +) diff --git a/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/medals/domain/MedalType.kt b/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/medals/domain/MedalType.kt new file mode 100644 index 00000000..8388aeb8 --- /dev/null +++ b/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/medals/domain/MedalType.kt @@ -0,0 +1,6 @@ +package edu.ntnu.idi.idatt.backend.game.medals.domain + +enum class MedalType { + STOP_COMPLETION, + EXAMPLE_APPROVAL +} diff --git a/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/medals/domain/PupilMedal.kt b/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/medals/domain/PupilMedal.kt new file mode 100644 index 00000000..81452755 --- /dev/null +++ b/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/medals/domain/PupilMedal.kt @@ -0,0 +1,38 @@ +package edu.ntnu.idi.idatt.backend.game.medals.domain + +import edu.ntnu.idi.idatt.backend.iam.domain.User +import edu.ntnu.idi.idatt.backend.classroom.domain.Classroom +import jakarta.persistence.* +import java.time.Instant + +/** + * Represents a medal earned by a pupil within a specific classroom. + * + * @property id Unique identifier for the award record. + * @property pupil The pupil who earned the medal. + * @property classroom The classroom context in which the medal was earned. + * @property medal The medal that was awarded. + * @property awardedAt The timestamp when the medal was awarded. + */ +@Entity +@Table(name = "pupil_medals") +class PupilMedal( + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long = 0, + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "pupil_user_id", nullable = false) + val pupil: User, + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "classroom_id", nullable = false) + val classroom: Classroom, + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "medal_id", nullable = false) + val medal: Medal, + + @Column(nullable = false) + val awardedAt: Instant = Instant.now() +) diff --git a/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/medals/repository/MedalRepository.kt b/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/medals/repository/MedalRepository.kt new file mode 100644 index 00000000..5aa67708 --- /dev/null +++ b/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/medals/repository/MedalRepository.kt @@ -0,0 +1,14 @@ +package edu.ntnu.idi.idatt.backend.game.medals.repository + +import edu.ntnu.idi.idatt.backend.game.medals.domain.Medal +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository + +/** + * Repository for accessing [Medal] entities. + */ +@Repository +interface MedalRepository : JpaRepository { + fun findByCode(code: String): Medal? + fun findByStopId(stopId: Long): Medal? +} diff --git a/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/medals/repository/PupilMedalRepository.kt b/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/medals/repository/PupilMedalRepository.kt new file mode 100644 index 00000000..1ca0d753 --- /dev/null +++ b/src/main/kotlin/edu/ntnu/idi/idatt/backend/game/medals/repository/PupilMedalRepository.kt @@ -0,0 +1,15 @@ +package edu.ntnu.idi.idatt.backend.game.medals.repository + +import edu.ntnu.idi.idatt.backend.game.medals.domain.PupilMedal +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository +import java.util.stream.Stream + +/** + * Repository for accessing [PupilMedal] entities. + */ +@Repository +interface PupilMedalRepository : JpaRepository { + fun findAllByPupilIdAndClassroomId(pupilId: Long, classroomId: Long): Stream + fun existsByPupilIdAndClassroomIdAndMedalId(pupilId: Long, classroomId: Long, medalId: Long): Boolean +} diff --git a/src/main/resources/db/migration/V17__create_medals_tables.sql b/src/main/resources/db/migration/V17__create_medals_tables.sql new file mode 100644 index 00000000..ba90fb38 --- /dev/null +++ b/src/main/resources/db/migration/V17__create_medals_tables.sql @@ -0,0 +1,29 @@ +CREATE TABLE medals ( + id BIGINT NOT NULL AUTO_INCREMENT, + code VARCHAR(100) NOT NULL, + title VARCHAR(255) NOT NULL, + description TEXT, + medal_type ENUM('STOP_COMPLETION', 'EXAMPLE_APPROVAL') NOT NULL, + stop_id BIGINT, + icon_url VARCHAR(255), + CONSTRAINT pk_medals PRIMARY KEY (id), + CONSTRAINT uk_medals_code UNIQUE (code), + CONSTRAINT fk_medals_stop FOREIGN KEY (stop_id) REFERENCES map_stops (id) ON DELETE SET NULL +); + +CREATE TABLE pupil_medals ( + id BIGINT NOT NULL AUTO_INCREMENT, + pupil_user_id BIGINT NOT NULL, + classroom_id BIGINT NOT NULL, + medal_id BIGINT NOT NULL, + awarded_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), + CONSTRAINT pk_pupil_medals PRIMARY KEY (id), + CONSTRAINT uk_pupil_medals_pupil_classroom_medal UNIQUE (pupil_user_id, classroom_id, medal_id), + CONSTRAINT fk_pupil_medals_pupil FOREIGN KEY (pupil_user_id) REFERENCES users (id) ON DELETE CASCADE, + CONSTRAINT fk_pupil_medals_classroom FOREIGN KEY (classroom_id) REFERENCES classrooms (id) ON DELETE CASCADE, + CONSTRAINT fk_pupil_medals_medal FOREIGN KEY (medal_id) REFERENCES medals (id) ON DELETE CASCADE +); + +CREATE INDEX idx_pupil_medals_pupil_user ON pupil_medals (pupil_user_id); +CREATE INDEX idx_pupil_medals_classroom ON pupil_medals (classroom_id); +CREATE INDEX idx_pupil_medals_medal ON pupil_medals (medal_id); diff --git a/src/test/kotlin/edu/ntnu/idi/idatt/backend/game/mapstops/PupilStopProgressServiceTests.kt b/src/test/kotlin/edu/ntnu/idi/idatt/backend/game/mapstops/PupilStopProgressServiceTests.kt index f5b79379..dc4fd5e3 100644 --- a/src/test/kotlin/edu/ntnu/idi/idatt/backend/game/mapstops/PupilStopProgressServiceTests.kt +++ b/src/test/kotlin/edu/ntnu/idi/idatt/backend/game/mapstops/PupilStopProgressServiceTests.kt @@ -1,6 +1,7 @@ package edu.ntnu.idi.idatt.backend.game.mapstops import edu.ntnu.idi.idatt.backend.classroom.domain.Classroom +import edu.ntnu.idi.idatt.backend.classroom.infrastructure.ClassroomRepository import edu.ntnu.idi.idatt.backend.game.mapstops.application.PupilStopProgressService import edu.ntnu.idi.idatt.backend.game.mapstops.application.UpdateStopProgressCommand import edu.ntnu.idi.idatt.backend.game.mapstops.domain.MapStop @@ -28,6 +29,7 @@ import org.mockito.ArgumentMatchers.any import org.mockito.Mockito import org.springframework.http.HttpStatus import org.springframework.web.server.ResponseStatusException +import java.util.Optional class PupilStopProgressServiceTests { @@ -272,8 +274,6 @@ class PupilStopProgressServiceTests { } stubFindAndSave(progressRepository, record) - Mockito.`when`(mapStopRepository.findAllByIsActiveTrueOrderByDisplayOrderAsc()) - .thenReturn(listOf(MapStop().apply { id = 1L })) val result = service.updateProgress( pupilUserId = 1L, classroomId = 2L, stopId = 1L, diff --git a/src/test/kotlin/edu/ntnu/idi/idatt/backend/game/medals/MedalServiceTests.kt b/src/test/kotlin/edu/ntnu/idi/idatt/backend/game/medals/MedalServiceTests.kt new file mode 100644 index 00000000..dc0ec094 --- /dev/null +++ b/src/test/kotlin/edu/ntnu/idi/idatt/backend/game/medals/MedalServiceTests.kt @@ -0,0 +1,94 @@ +package edu.ntnu.idi.idatt.backend.game.medals + +import edu.ntnu.idi.idatt.backend.classroom.domain.Classroom +import edu.ntnu.idi.idatt.backend.game.medals.application.MedalService +import edu.ntnu.idi.idatt.backend.game.medals.domain.Medal +import edu.ntnu.idi.idatt.backend.game.medals.domain.MedalType +import edu.ntnu.idi.idatt.backend.game.medals.domain.PupilMedal +import edu.ntnu.idi.idatt.backend.game.medals.repository.MedalRepository +import edu.ntnu.idi.idatt.backend.game.medals.repository.PupilMedalRepository +import edu.ntnu.idi.idatt.backend.iam.domain.User +import edu.ntnu.idi.idatt.backend.iam.domain.UserRole +import edu.ntnu.idi.idatt.backend.iam.domain.UserStatus +import org.junit.jupiter.api.Assertions.assertDoesNotThrow +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.mockito.ArgumentMatchers.any +import org.mockito.Mockito +import org.springframework.dao.DataIntegrityViolationException +import org.springframework.transaction.PlatformTransactionManager +import org.springframework.transaction.support.SimpleTransactionStatus + +class MedalServiceTests { + + @Test + fun `award stop medal ignores duplicate award race`() { + val medalRepository = Mockito.mock(MedalRepository::class.java) + val pupilMedalRepository = Mockito.mock(PupilMedalRepository::class.java) + val service = MedalService(medalRepository, pupilMedalRepository, transactionManager()) + + Mockito.`when`(medalRepository.findByStopId(5L)).thenReturn(medal(stopId = 5L)) + Mockito.`when`(pupilMedalRepository.existsByPupilIdAndClassroomIdAndMedalId(1L, 2L, 10L)) + .thenReturn(false) + .thenReturn(true) + Mockito.`when`(pupilMedalRepository.saveAndFlush(any(PupilMedal::class.java))).thenThrow( + DataIntegrityViolationException("duplicate medal award"), + ) + + assertDoesNotThrow { + service.awardStopMedal(pupil(), classroom(), 5L) + } + } + + @Test + fun `award stop medal rethrows unexpected integrity failure`() { + val medalRepository = Mockito.mock(MedalRepository::class.java) + val pupilMedalRepository = Mockito.mock(PupilMedalRepository::class.java) + val service = MedalService(medalRepository, pupilMedalRepository, transactionManager()) + val exception = DataIntegrityViolationException("foreign key failure") + + Mockito.`when`(medalRepository.findByStopId(5L)).thenReturn(medal(stopId = 5L)) + Mockito.`when`(pupilMedalRepository.existsByPupilIdAndClassroomIdAndMedalId(1L, 2L, 10L)) + .thenReturn(false) + .thenReturn(false) + Mockito.`when`(pupilMedalRepository.saveAndFlush(any(PupilMedal::class.java))).thenThrow(exception) + + val thrown = assertThrows { + service.awardStopMedal(pupil(), classroom(), 5L) + } + + org.junit.jupiter.api.Assertions.assertSame(exception, thrown) + } + + private fun pupil(): User = + User( + id = 1L, + username = "pupil-one", + passwordHash = "hash", + role = UserRole.PUPIL, + status = UserStatus.ACTIVE, + ) + + private fun classroom(): Classroom = + Classroom( + id = 2L, + ownerTeacherId = 9L, + title = "Test Classroom", + ) + + private fun medal(stopId: Long): Medal = + Medal( + id = 10L, + code = "stop-$stopId-completion", + title = "Stop $stopId Complete", + description = "Awarded for completing stop $stopId", + medalType = MedalType.STOP_COMPLETION, + stop = null, + iconUrl = null, + ) + + private fun transactionManager(): PlatformTransactionManager = + Mockito.mock(PlatformTransactionManager::class.java).also { transactionManager -> + Mockito.`when`(transactionManager.getTransaction(any())).thenReturn(SimpleTransactionStatus()) + } +}