-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ea8c03
commit 5b8e251
Showing
1 changed file
with
49 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
} | ||
} |