Skip to content

Commit

Permalink
Add save lesson progress test
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed Dec 8, 2024
1 parent 0ea8c03 commit 5b8e251
Showing 1 changed file with 49 additions and 8 deletions.
57 changes: 49 additions & 8 deletions server/src/test/kotlin/ivy/learn/api/LessonsApiTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,67 @@ import io.kotest.matchers.shouldBe
import ivy.data.source.LessonDataSource
import ivy.di.Di
import ivy.learn.testsupport.ServerTest
import ivy.learn.testsupport.data.repository.LessonProgressFixtures
import ivy.model.CourseId
import ivy.model.LessonId
import ivy.model.LessonItemId
import org.junit.Test

class LessonsApiTest : ServerTest() {
@Test
fun `fetches existing lesson`() = beTest {
fun `fetch existing lesson`() = beTest {
// Given
val auth = registerUser("[email protected]")
val datasource: LessonDataSource = Di.get()
val auth = registerUser()
val datasource = Di.get<LessonDataSource>()
val courseId = CourseId("demo-course")
val lessonId = LessonId("demo-lesson")


// When
val result = datasource.fetchLesson(
val response = datasource.fetchLesson(
session = auth.session.token,
course = courseId,
lesson = lessonId,
)

// Then
val successResponse = response.shouldBeRight()
successResponse.lesson.id shouldBe lessonId
successResponse.lesson.content.items.shouldNotBeEmpty()
}

@Test
fun `saves lesson progress`() = beTest {
// Given
val auth = registerUser()
val datasource = Di.get<LessonDataSource>()
val courseId = CourseId("demo-course")
val lessonId = LessonId("demo-lesson")

// When
val response1 = datasource.saveProgress(
session = auth.session.token,
course = courseId,
lesson = lessonId,
progress = LessonProgressFixtures.state(
openAnswersInput = mapOf(
LessonItemId("1") to "42"
)
)
)
val response2 = datasource.saveProgress(
session = auth.session.token,
course = CourseId("demo-course"),
lesson = LessonId("demo-lesson"),
course = courseId,
lesson = lessonId,
progress = LessonProgressFixtures.state(
openAnswersInput = mapOf(
LessonItemId("1") to "3.14"
)
)
)

// Then
result.shouldBeRight().lesson.id shouldBe LessonId("demo-lesson")
result.shouldBeRight().lesson.content.items.shouldNotBeEmpty()
response1.shouldBeRight()
response2.shouldBeRight()
}
}

0 comments on commit 5b8e251

Please sign in to comment.