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 b1a4d9c5..b00a884a 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 @@ -356,6 +356,10 @@ class DevDataBootstrap( ) { val activeStopsBySlug = stops.associateBy { requireNotNull(it.slug) { "Seeded map stop must have a slug" } } + stops.forEach { stop -> + seedGameNotebookEntriesForStop(classroom, stop) + } + activeStopsBySlug["nyhetskvartalet"]?.let { stop -> seedNotebookEntry( pupil = pupilAda, @@ -366,16 +370,6 @@ class DevDataBootstrap( content = "Ada la merke til at overskriften brukte sterke følelser og manglet tydelige kilder.", ) } - activeStopsBySlug["postkontoret"]?.let { stop -> - seedNotebookEntry( - pupil = pupilAda, - classroom = classroom, - stop = stop, - sourceType = NotebookSourceType.GAME, - title = "Phishing-tegn", - content = "Spillet markerte dårlig språk, hastverk og mistenkelig lenke som tydelige faresignaler.", - ) - } activeStopsBySlug["fotografen"]?.let { stop -> seedNotebookEntry( pupil = pupilNoah, @@ -388,23 +382,50 @@ class DevDataBootstrap( } } + private fun seedGameNotebookEntriesForStop( + classroom: Classroom, + stop: MapStop, + ) { + val stopTitle = requireNotNull(stop.title) { "Seeded map stop must have a title" } + val notebookEntries = listOf( + "Hva vi oppdaget" to "Spillet oppsummerte de viktigste sporene fra $stopTitle og viste hvilke detaljer som burde undersøkes nærmere.", + "Tegn å passe på" to "Notatet fra $stopTitle fremhevet faresignaler som uklar avsender, manglende kontekst eller forsøk på å skape stress.", + "Huskeliste" to "Spillet foreslo å dobbeltsjekke kilder, sammenligne informasjon og ta vare på bevis før man går videre fra $stopTitle.", + ) + + notebookEntries.forEach { (title, content) -> + seedNotebookEntry( + pupil = null, + classroom = classroom, + stop = stop, + sourceType = NotebookSourceType.GAME, + title = title, + content = content, + ) + } + } + private fun seedNotebookEntry( - pupil: User, + pupil: User?, classroom: Classroom, stop: MapStop, sourceType: NotebookSourceType, title: String, content: String, ) { - val pupilId = requireNotNull(pupil.id) { "Pupil seed user must have an id" } val classroomId = classroom.id val stopId = requireNotNull(stop.id) { "Seeded map stop must have an id" } - val existingEntry = notebookEntryRepository.findAllByPupilId(pupilId).firstOrNull { - it.classroom.id == classroomId && it.stop.id == stopId && it.title == title + val existingEntry = notebookEntryRepository.findAll().firstOrNull { + it.classroom.id == classroomId && + it.stop.id == stopId && + it.title == title && + it.sourceType == sourceType && + it.pupil?.id == pupil?.id } if (existingEntry != null) { existingEntry.sourceType = sourceType existingEntry.content = content + existingEntry.pupil = pupil return } notebookEntryRepository.save( @@ -423,4 +444,4 @@ class DevDataBootstrap( HexFormat.of().formatHex( MessageDigest.getInstance("SHA-256").digest(rawToken.toByteArray(StandardCharsets.UTF_8)), ) -} \ No newline at end of file +} diff --git a/src/main/kotlin/edu/ntnu/idi/idatt/backend/notebook/api/NotebookEntryApiMappings.kt b/src/main/kotlin/edu/ntnu/idi/idatt/backend/notebook/api/NotebookEntryApiMappings.kt index d3ffd859..e10ba22a 100644 --- a/src/main/kotlin/edu/ntnu/idi/idatt/backend/notebook/api/NotebookEntryApiMappings.kt +++ b/src/main/kotlin/edu/ntnu/idi/idatt/backend/notebook/api/NotebookEntryApiMappings.kt @@ -14,7 +14,7 @@ import edu.ntnu.idi.idatt.backend.notebook.domain.NotebookEntry fun NotebookEntry.toResponse(): NotebookEntryResponse = NotebookEntryResponse( id = requireNotNull(id) { "Notebook entry is missing an id" }, - pupilUserId = requireNotNull(pupil.id) { "Notebook entry pupil is missing an id" }, + pupilUserId = pupil?.id, classroomId = classroom.id, stopId = requireNotNull(stop.id) { "Notebook entry stop is missing an id" }, sourceType = sourceType.name, diff --git a/src/main/kotlin/edu/ntnu/idi/idatt/backend/notebook/api/NotebookEntryResponses.kt b/src/main/kotlin/edu/ntnu/idi/idatt/backend/notebook/api/NotebookEntryResponses.kt index 216bc290..7817a3d6 100644 --- a/src/main/kotlin/edu/ntnu/idi/idatt/backend/notebook/api/NotebookEntryResponses.kt +++ b/src/main/kotlin/edu/ntnu/idi/idatt/backend/notebook/api/NotebookEntryResponses.kt @@ -6,7 +6,7 @@ import java.time.Instant * Serialized notebook entry returned by notebook endpoints. * * @property id notebook entry identifier - * @property pupilUserId owner pupil user id + * @property pupilUserId owner pupil user id when the entry originates from a pupil * @property classroomId classroom id for the entry context * @property stopId map stop id for the entry context * @property sourceType serialized notebook source type @@ -17,7 +17,7 @@ import java.time.Instant */ data class NotebookEntryResponse( val id: Long, - val pupilUserId: Long, + val pupilUserId: Long?, val classroomId: Long, val stopId: Long, val sourceType: String, diff --git a/src/main/kotlin/edu/ntnu/idi/idatt/backend/notebook/application/NotebookService.kt b/src/main/kotlin/edu/ntnu/idi/idatt/backend/notebook/application/NotebookService.kt index 2317c94d..1e5a65e5 100644 --- a/src/main/kotlin/edu/ntnu/idi/idatt/backend/notebook/application/NotebookService.kt +++ b/src/main/kotlin/edu/ntnu/idi/idatt/backend/notebook/application/NotebookService.kt @@ -1,9 +1,11 @@ package edu.ntnu.idi.idatt.backend.notebook.application +import edu.ntnu.idi.idatt.backend.game.gameProgress.infrastructure.PupilGameProgressRepository import edu.ntnu.idi.idatt.backend.game.mapstops.infrastructure.MapStopsRepository import edu.ntnu.idi.idatt.backend.iam.application.CurrentUserResolver import edu.ntnu.idi.idatt.backend.iam.security.CurrentUser import edu.ntnu.idi.idatt.backend.notebook.domain.NotebookEntry +import edu.ntnu.idi.idatt.backend.notebook.domain.NotebookSourceType import edu.ntnu.idi.idatt.backend.notebook.infrastructure.NotebookEntryRepository import org.springframework.http.HttpStatus import org.springframework.stereotype.Service @@ -22,6 +24,7 @@ class NotebookService( private val notebookEntryRepository: NotebookEntryRepository, private val currentUserResolver: CurrentUserResolver, private val mapStopsRepository: MapStopsRepository, + private val pupilGameProgressRepository: PupilGameProgressRepository, ) { /** * Returns all notebook entries owned by the authenticated pupil. @@ -33,7 +36,14 @@ class NotebookService( fun getAllNotebookEntries(currentUser: CurrentUser): List { val pupil = currentUserResolver.requirePupil(currentUser.subject) val pupilId = requireNotNull(pupil.id) { "Authenticated pupil is missing an id" } - return notebookEntryRepository.findAllByPupilId(pupilId) + + val classroom = currentUserResolver.getClassroomByUser(currentUser) + val classroomId = requireNotNull(classroom.id) { "Active classroom is missing an id" } + + val gameProgress = pupilGameProgressRepository.findByPupilIdAndClassroomId(pupilId, classroomId) + val completedStopsCount = gameProgress?.completedStopsCount ?: 0 + + return notebookEntryRepository.findAllVisibleToPupil(pupilId, classroomId, completedStopsCount) } /** @@ -47,6 +57,10 @@ class NotebookService( val pupil = currentUserResolver.requirePupil(command.currentUser.subject) val classroom = currentUserResolver.getClassroomByUser(command.currentUser) + if (command.sourceType == NotebookSourceType.GAME) { + throw ResponseStatusException(HttpStatus.FORBIDDEN, "Pupil cannot create notes with sourceType set to GAME") + } + if (classroom.id != command.classroomId) { throw ResponseStatusException(HttpStatus.FORBIDDEN, "Pupil cannot create notebook entries outside the active classroom") } @@ -57,7 +71,7 @@ class NotebookService( } val notebookEntry = NotebookEntry( - pupil = pupil, + pupil = if (command.sourceType == NotebookSourceType.PUPIL) pupil else null, classroom = classroom, stop = stop, sourceType = command.sourceType, @@ -93,6 +107,7 @@ class NotebookService( fun deleteNotebookEntry(command: DeleteNotebookEntryCommand) { val pupil = currentUserResolver.requirePupil(command.currentUser.subject) val notebookEntry = verifyOwnership(pupil.id, command.notebookEntryId) + notebookEntryRepository.delete(notebookEntry) } @@ -110,7 +125,11 @@ class NotebookService( ResponseStatusException(HttpStatus.NOT_FOUND, "Notebook entry not found") } - val ownerId = requireNotNull(notebookEntry.pupil.id) { "Notebook entry pupil is missing an id" } + if (notebookEntry.sourceType == NotebookSourceType.GAME) { + throw ResponseStatusException(HttpStatus.FORBIDDEN, "Pupil cannot create notebook entries outside the active classroom") + } + + val ownerId = notebookEntry.pupil?.id if (ownerId != resolvedPupilId) { throw ResponseStatusException(HttpStatus.FORBIDDEN, "Pupil cannot access another pupil's notebook entry") } diff --git a/src/main/kotlin/edu/ntnu/idi/idatt/backend/notebook/domain/NotebookEntry.kt b/src/main/kotlin/edu/ntnu/idi/idatt/backend/notebook/domain/NotebookEntry.kt index 544379a3..188b394a 100644 --- a/src/main/kotlin/edu/ntnu/idi/idatt/backend/notebook/domain/NotebookEntry.kt +++ b/src/main/kotlin/edu/ntnu/idi/idatt/backend/notebook/domain/NotebookEntry.kt @@ -13,6 +13,8 @@ import jakarta.persistence.GenerationType import jakarta.persistence.Id import jakarta.persistence.JoinColumn import jakarta.persistence.ManyToOne +import jakarta.persistence.PrePersist +import jakarta.persistence.PreUpdate import jakarta.persistence.Table import org.hibernate.annotations.CreationTimestamp import org.hibernate.annotations.UpdateTimestamp @@ -22,7 +24,7 @@ import java.time.Instant * Persisted notebook entry created for a pupil within a classroom and map stop context. * * @property id Database identifier. - * @property pupil Pupil that owns the notebook entry. + * @property pupil Pupil that owns the notebook entry when the source type is [NotebookSourceType.PUPIL]. * @property classroom Classroom the notebook entry belongs to. * @property stop Map stop the notebook entry is associated with. * @property sourceType Source that produced the entry content. @@ -37,9 +39,9 @@ class NotebookEntry( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) var id: Long? = null, - @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "pupil_user_id", nullable = false) - var pupil: User, + @ManyToOne(fetch = FetchType.LAZY, optional = true) + @JoinColumn(name = "pupil_user_id", nullable = true) + var pupil: User?, @ManyToOne(fetch = FetchType.LAZY, optional = false) @JoinColumn(name = "classroom_id", nullable = false) var classroom: Classroom, @@ -59,4 +61,18 @@ class NotebookEntry( @UpdateTimestamp @Column(name = "updated_at", nullable = false) var updatedAt: Instant? = null, -) +) { + @PrePersist + @PreUpdate + fun validatePupilOwnership() { + when (sourceType) { + NotebookSourceType.GAME -> require(pupil == null) { + "Notebook entries with source type GAME must not reference a pupil" + } + + NotebookSourceType.PUPIL -> requireNotNull(pupil) { + "Notebook entries with source type PUPIL must reference a pupil" + } + } + } +} diff --git a/src/main/kotlin/edu/ntnu/idi/idatt/backend/notebook/infrastructure/NotebookEntryRepository.kt b/src/main/kotlin/edu/ntnu/idi/idatt/backend/notebook/infrastructure/NotebookEntryRepository.kt index 4e249031..bf6cd2b1 100644 --- a/src/main/kotlin/edu/ntnu/idi/idatt/backend/notebook/infrastructure/NotebookEntryRepository.kt +++ b/src/main/kotlin/edu/ntnu/idi/idatt/backend/notebook/infrastructure/NotebookEntryRepository.kt @@ -2,6 +2,7 @@ package edu.ntnu.idi.idatt.backend.notebook.infrastructure import edu.ntnu.idi.idatt.backend.notebook.domain.NotebookEntry import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.Query import org.springframework.stereotype.Repository /** @@ -11,10 +12,22 @@ import org.springframework.stereotype.Repository interface NotebookEntryRepository : JpaRepository { /** - * Finds all entries owned by a given pupil + * Finds all notebook entries visible to a pupil: + * - pupil-authored entries owned by the pupil + * - game-authored entries for the pupil's active classroom * * @param pupilId the id of the pupil - * @return all entries connected to the pupil + * @param classroomId the id of the active classroom + * @return all visible notebook entries */ - fun findAllByPupilId(pupilId: Long): List + @Query( + """ + select notebookEntry + from NotebookEntry notebookEntry + where (notebookEntry.pupil.id = :pupilId + or (notebookEntry.pupil is null and notebookEntry.classroom.id = :classroomId)) + and notebookEntry.stop.displayOrder <= :completedStops + 1 + """ + ) + fun findAllVisibleToPupil(pupilId: Long, classroomId: Long, completedStops: Int): List } diff --git a/src/main/resources/db/migration/V16__allow_null_pupil_for_game_notebook_entries.sql b/src/main/resources/db/migration/V16__allow_null_pupil_for_game_notebook_entries.sql new file mode 100644 index 00000000..b7d25ca4 --- /dev/null +++ b/src/main/resources/db/migration/V16__allow_null_pupil_for_game_notebook_entries.sql @@ -0,0 +1,13 @@ +ALTER TABLE notebook_entries + MODIFY COLUMN pupil_user_id BIGINT NULL; + +UPDATE notebook_entries +SET pupil_user_id = NULL +WHERE source_type = 'GAME'; + +ALTER TABLE notebook_entries + ADD CONSTRAINT chk_notebook_entries_source_type_pupil + CHECK ( + (source_type = 'GAME' AND pupil_user_id IS NULL) OR + (source_type = 'PUPIL' AND pupil_user_id IS NOT NULL) + ); diff --git a/src/test/kotlin/edu/ntnu/idi/idatt/backend/notebook/NotebookEntryControllerIntegrationTests.kt b/src/test/kotlin/edu/ntnu/idi/idatt/backend/notebook/NotebookEntryControllerIntegrationTests.kt index 423196d7..a0718eba 100644 --- a/src/test/kotlin/edu/ntnu/idi/idatt/backend/notebook/NotebookEntryControllerIntegrationTests.kt +++ b/src/test/kotlin/edu/ntnu/idi/idatt/backend/notebook/NotebookEntryControllerIntegrationTests.kt @@ -79,7 +79,7 @@ class NotebookEntryControllerIntegrationTests { Classroom(ownerTeacherId = requireNotNull(teacher.id), title = "Class A") ) val stop = mapStopsRepository.save( - MapStop(slug = "intro", title = "Intro") + MapStop(slug = "intro", title = "Intro", displayOrder = 1) ) val pupil = userRepository.save(activePupil("ada")) val otherPupil = userRepository.save(activePupil("grace")) @@ -127,7 +127,7 @@ class NotebookEntryControllerIntegrationTests { Classroom(ownerTeacherId = requireNotNull(teacher.id), title = "Class A") ) val stop = mapStopsRepository.save( - MapStop(slug = "intro", title = "Intro") + MapStop(slug = "intro", title = "Intro", displayOrder = 1) ) val pupil = userRepository.save(activePupil("ada")) pupilProfileRepository.save(PupilProfile(user = pupil, displayName = "Ada", currentClassroomId = classroom.id)) @@ -169,7 +169,7 @@ class NotebookEntryControllerIntegrationTests { Classroom(ownerTeacherId = requireNotNull(teacher.id), title = "Class A") ) val stop = mapStopsRepository.save( - MapStop(slug = "intro", title = "Intro") + MapStop(slug = "intro", title = "Intro", displayOrder = 1) ) val pupil = userRepository.save(activePupil("ada")) pupilProfileRepository.save(PupilProfile(user = pupil, displayName = "Ada", currentClassroomId = classroom.id)) @@ -208,7 +208,7 @@ class NotebookEntryControllerIntegrationTests { Classroom(ownerTeacherId = requireNotNull(teacher.id), title = "Class A") ) val stop = mapStopsRepository.save( - MapStop(slug = "intro", title = "Intro") + MapStop(slug = "intro", title = "Intro", displayOrder = 1) ) val pupil = userRepository.save(activePupil("ada")) val otherPupil = userRepository.save(activePupil("grace")) diff --git a/src/test/kotlin/edu/ntnu/idi/idatt/backend/notebook/NotebookServiceTests.kt b/src/test/kotlin/edu/ntnu/idi/idatt/backend/notebook/NotebookServiceTests.kt index a10a5b49..099de886 100644 --- a/src/test/kotlin/edu/ntnu/idi/idatt/backend/notebook/NotebookServiceTests.kt +++ b/src/test/kotlin/edu/ntnu/idi/idatt/backend/notebook/NotebookServiceTests.kt @@ -1,6 +1,7 @@ package edu.ntnu.idi.idatt.backend.notebook import edu.ntnu.idi.idatt.backend.classroom.domain.Classroom +import edu.ntnu.idi.idatt.backend.game.gameProgress.infrastructure.PupilGameProgressRepository import edu.ntnu.idi.idatt.backend.game.mapstops.domain.MapStop import edu.ntnu.idi.idatt.backend.game.mapstops.infrastructure.MapStopsRepository import edu.ntnu.idi.idatt.backend.iam.application.CurrentUserResolver @@ -31,13 +32,22 @@ class NotebookServiceTests { val currentUserResolver = Mockito.mock(CurrentUserResolver::class.java) val notebookEntryRepository = Mockito.mock(NotebookEntryRepository::class.java) val mapStopsRepository = Mockito.mock(MapStopsRepository::class.java) - val service = NotebookService(notebookEntryRepository, currentUserResolver, mapStopsRepository) + val pupilGameProgressRepository = Mockito.mock(PupilGameProgressRepository::class.java) + val service = NotebookService( + notebookEntryRepository, + currentUserResolver, + mapStopsRepository, + pupilGameProgressRepository, + ) val currentUser = currentUser("42") val pupil = pupilUser(42L) + val classroom = classroom(7L) val entries = listOf(notebookEntry(1L, pupil), notebookEntry(2L, pupil)) Mockito.`when`(currentUserResolver.requirePupil("42")).thenReturn(pupil) - Mockito.`when`(notebookEntryRepository.findAllByPupilId(42L)).thenReturn(entries) + Mockito.`when`(currentUserResolver.getClassroomByUser(currentUser)).thenReturn(classroom) + Mockito.`when`(pupilGameProgressRepository.findByPupilIdAndClassroomId(42L, 7L)).thenReturn(null) + Mockito.`when`(notebookEntryRepository.findAllVisibleToPupil(42L, 7L, 0)).thenReturn(entries) val result = service.getAllNotebookEntries(currentUser) @@ -49,7 +59,13 @@ class NotebookServiceTests { val currentUserResolver = Mockito.mock(CurrentUserResolver::class.java) val notebookEntryRepository = Mockito.mock(NotebookEntryRepository::class.java) val mapStopsRepository = Mockito.mock(MapStopsRepository::class.java) - val service = NotebookService(notebookEntryRepository, currentUserResolver, mapStopsRepository) + val pupilGameProgressRepository = Mockito.mock(PupilGameProgressRepository::class.java) + val service = NotebookService( + notebookEntryRepository, + currentUserResolver, + mapStopsRepository, + pupilGameProgressRepository, + ) val currentUser = currentUser("42") val pupil = pupilUser(42L) val classroom = classroom(7L) @@ -83,12 +99,52 @@ class NotebookServiceTests { assertSame(saved, result) } + @Test + fun `create notebook entry rejects game source`() { + val currentUserResolver = Mockito.mock(CurrentUserResolver::class.java) + val notebookEntryRepository = Mockito.mock(NotebookEntryRepository::class.java) + val mapStopsRepository = Mockito.mock(MapStopsRepository::class.java) + val pupilGameProgressRepository = Mockito.mock(PupilGameProgressRepository::class.java) + val service = NotebookService( + notebookEntryRepository, + currentUserResolver, + mapStopsRepository, + pupilGameProgressRepository, + ) + val currentUser = currentUser("42") + val pupil = pupilUser(42L) + val classroom = classroom(7L) + val command = CreateNotebookEntryCommand( + currentUser = currentUser, + classroomId = 7L, + stopId = 9L, + sourceType = NotebookSourceType.GAME, + title = "Auto note", + content = "Generated note", + ) + + Mockito.`when`(currentUserResolver.requirePupil("42")).thenReturn(pupil) + Mockito.`when`(currentUserResolver.getClassroomByUser(currentUser)).thenReturn(classroom) + + val exception = assertThrows { + service.createNotebookEntry(command) + } + + assertEquals(HttpStatus.FORBIDDEN, exception.statusCode) + } + @Test fun `create notebook entry rejects classroom outside active classroom`() { val currentUserResolver = Mockito.mock(CurrentUserResolver::class.java) val notebookEntryRepository = Mockito.mock(NotebookEntryRepository::class.java) val mapStopsRepository = Mockito.mock(MapStopsRepository::class.java) - val service = NotebookService(notebookEntryRepository, currentUserResolver, mapStopsRepository) + val pupilGameProgressRepository = Mockito.mock(PupilGameProgressRepository::class.java) + val service = NotebookService( + notebookEntryRepository, + currentUserResolver, + mapStopsRepository, + pupilGameProgressRepository, + ) val currentUser = currentUser("42") val pupil = pupilUser(42L) val classroom = classroom(7L) @@ -116,7 +172,13 @@ class NotebookServiceTests { val currentUserResolver = Mockito.mock(CurrentUserResolver::class.java) val notebookEntryRepository = Mockito.mock(NotebookEntryRepository::class.java) val mapStopsRepository = Mockito.mock(MapStopsRepository::class.java) - val service = NotebookService(notebookEntryRepository, currentUserResolver, mapStopsRepository) + val pupilGameProgressRepository = Mockito.mock(PupilGameProgressRepository::class.java) + val service = NotebookService( + notebookEntryRepository, + currentUserResolver, + mapStopsRepository, + pupilGameProgressRepository, + ) val currentUser = currentUser("42") val pupil = pupilUser(42L) val classroom = classroom(7L) @@ -124,7 +186,7 @@ class NotebookServiceTests { currentUser = currentUser, classroomId = 7L, stopId = 9L, - sourceType = NotebookSourceType.GAME, + sourceType = NotebookSourceType.PUPIL, title = "Auto note", content = "Generated note", ) @@ -145,7 +207,13 @@ class NotebookServiceTests { val currentUserResolver = Mockito.mock(CurrentUserResolver::class.java) val notebookEntryRepository = Mockito.mock(NotebookEntryRepository::class.java) val mapStopsRepository = Mockito.mock(MapStopsRepository::class.java) - val service = NotebookService(notebookEntryRepository, currentUserResolver, mapStopsRepository) + val pupilGameProgressRepository = Mockito.mock(PupilGameProgressRepository::class.java) + val service = NotebookService( + notebookEntryRepository, + currentUserResolver, + mapStopsRepository, + pupilGameProgressRepository, + ) val currentUser = currentUser("42") val pupil = pupilUser(42L) val existing = notebookEntry(15L, pupil).apply { @@ -175,7 +243,13 @@ class NotebookServiceTests { val currentUserResolver = Mockito.mock(CurrentUserResolver::class.java) val notebookEntryRepository = Mockito.mock(NotebookEntryRepository::class.java) val mapStopsRepository = Mockito.mock(MapStopsRepository::class.java) - val service = NotebookService(notebookEntryRepository, currentUserResolver, mapStopsRepository) + val pupilGameProgressRepository = Mockito.mock(PupilGameProgressRepository::class.java) + val service = NotebookService( + notebookEntryRepository, + currentUserResolver, + mapStopsRepository, + pupilGameProgressRepository, + ) val currentUser = currentUser("42") val pupil = pupilUser(42L) val existing = notebookEntry(15L, pupilUser(99L)) @@ -201,7 +275,13 @@ class NotebookServiceTests { val currentUserResolver = Mockito.mock(CurrentUserResolver::class.java) val notebookEntryRepository = Mockito.mock(NotebookEntryRepository::class.java) val mapStopsRepository = Mockito.mock(MapStopsRepository::class.java) - val service = NotebookService(notebookEntryRepository, currentUserResolver, mapStopsRepository) + val pupilGameProgressRepository = Mockito.mock(PupilGameProgressRepository::class.java) + val service = NotebookService( + notebookEntryRepository, + currentUserResolver, + mapStopsRepository, + pupilGameProgressRepository, + ) val currentUser = currentUser("42") val pupil = pupilUser(42L) val existing = notebookEntry(15L, pupil) @@ -223,7 +303,13 @@ class NotebookServiceTests { val currentUserResolver = Mockito.mock(CurrentUserResolver::class.java) val notebookEntryRepository = Mockito.mock(NotebookEntryRepository::class.java) val mapStopsRepository = Mockito.mock(MapStopsRepository::class.java) - val service = NotebookService(notebookEntryRepository, currentUserResolver, mapStopsRepository) + val pupilGameProgressRepository = Mockito.mock(PupilGameProgressRepository::class.java) + val service = NotebookService( + notebookEntryRepository, + currentUserResolver, + mapStopsRepository, + pupilGameProgressRepository, + ) val currentUser = currentUser("42") val pupil = pupilUser(42L) val existing = notebookEntry(15L, pupilUser(99L)) @@ -271,7 +357,7 @@ class NotebookServiceTests { title = "Stop $id", ) - private fun notebookEntry(id: Long, pupil: User) = NotebookEntry( + private fun notebookEntry(id: Long, pupil: User?) = NotebookEntry( id = id, pupil = pupil, classroom = classroom(7L),