@@ -30,104 +30,106 @@ import kotlinx.serialization.json.Json
3030
3131@TestRegistering
3232fun TestSuite.testService (
33- @TestElementName name : String ,
34- testConfig : TestConfig = TestConfig ,
35- test : suspend context(Dependencies ) Test .ExecutionScope .() -> Unit ,
33+ @TestElementName name : String ,
34+ testConfig : TestConfig = TestConfig ,
35+ test : suspend context(Dependencies ) Test .ExecutionScope .() -> Unit ,
3636) =
37- test(name, testConfig) {
38- withTestDependencies { dependencies ->
39- test.invoke(dependencies, this @test)
37+ test(name, testConfig) {
38+ withTestDependencies { dependencies ->
39+ test.invoke(dependencies, this @test)
40+ }
4041 }
41- }
4242
4343@TestRegistering
4444fun TestSuite.testDependencies (
45- @TestElementName name : String ,
46- testConfig : TestConfig = TestConfig ,
47- test :
48- suspend context(Dependencies , Raise <DomainError >) Test .ExecutionScope .(
49- ) -> Unit ,
50- ) = test(name, testConfig) {
51- withTestDependencies { dependencies ->
52- either<DomainError , Unit > {
53- test.invoke(
54- dependencies,
55- contextOf<Raise <DomainError >>(),
56- this @test,
57- )
45+ @TestElementName name : String ,
46+ testConfig : TestConfig = TestConfig ,
47+ test : suspend context(Dependencies , Raise <DomainError >) Test .ExecutionScope .() -> Unit ,
48+ ) =
49+ test(name, testConfig) {
50+ withTestDependencies { dependencies ->
51+ either<DomainError , Unit > {
52+ test.invoke(
53+ dependencies,
54+ contextOf<Raise <DomainError >>(),
55+ this @test,
56+ )
57+ }
58+ .shouldBeRight()
59+ }
5860 }
59- .shouldBeRight()
60- }
61- }
6261
6362@TestRegistering
6463fun TestSuite.testServer (
65- @TestElementName name : String ,
66- testConfig : TestConfig = TestConfig ,
67- test :
68- suspend context(Dependencies , HttpClient , Raise <DomainError >) Test .ExecutionScope .(
69- ) -> Unit ,
64+ @TestElementName name : String ,
65+ testConfig : TestConfig = TestConfig ,
66+ test :
67+ suspend context(Dependencies , HttpClient , Raise <DomainError >) Test .ExecutionScope .(
68+ ) -> Unit ,
7069) =
71- test(name, testConfig) {
72- withTestDependencies { dependencies ->
73- testApplication {
74- application { app(dependencies) }
75- createClient {
76- expectSuccess = false
77- install(ContentNegotiation ) {
78- json(Json { serializersModule = kotlinXSerializersModule })
79- }
80- }
81- .use { client ->
82- either<DomainError , Unit > {
83- test.invoke(
84- dependencies,
85- client,
86- contextOf<Raise <DomainError >>(),
87- this @test,
88- )
70+ test(name, testConfig) {
71+ withTestDependencies { dependencies ->
72+ testApplication {
73+ application { app(dependencies) }
74+ createClient {
75+ expectSuccess = false
76+ install(ContentNegotiation ) {
77+ json(Json { serializersModule = kotlinXSerializersModule })
78+ }
79+ }
80+ .use { client ->
81+ either<DomainError , Unit > {
82+ test.invoke(
83+ dependencies,
84+ client,
85+ contextOf<Raise <DomainError >>(),
86+ this @test,
87+ )
88+ }
89+ .shouldBeRight()
90+ }
8991 }
90- .shouldBeRight()
91- }
92- }
92+ }
9393 }
94- }
9594
9695context(client: HttpClient )
9796val client: HttpClient
98- get() = client
97+ get() = client
9998
10099context(dependencies: Dependencies )
101100val dependencies: Dependencies
102- get() = dependencies
101+ get() = dependencies
103102
104103context(_: Raise <DomainError >)
105- suspend fun ArticleService.createArticle (userId : UserId , article : ArticleFixture = articleFixture()): Article =
106- createArticle(
107- CreateArticle (
108- userId,
109- article.title,
110- article.description,
111- article.body,
112- article.tags,
104+ suspend fun ArticleService.createArticle (
105+ userId : UserId ,
106+ article : ArticleFixture = articleFixture(),
107+ ): Article =
108+ createArticle(
109+ CreateArticle (
110+ userId,
111+ article.title,
112+ article.description,
113+ article.body,
114+ article.tags,
115+ )
113116 )
114- )
115117
116118context(dependencies: Dependencies , _: Raise <DomainError >)
117119fun registerUser (fixture : UserFixture = userFixture()): RegisteredUser {
118- val token =
119- dependencies.userService.register(
120- RegisterUser (fixture.username, fixture.email, fixture.password)
121- )
122- val jwt =
123- withError({ JwtInvalid (it.toString()) }) {
124- JWT .decodeT(token.value, JWSHMAC512Algorithm )
125- .bind<KJWTVerificationError , DecodedJWT <JWSHMAC512Algorithm >>()
126- }
127- val id =
128- ensureNotNull(jwt.claimValueAsLong(" id" ).getOrNull()) {
129- JwtInvalid (" id missing from JWT Token" )
130- }
120+ val token =
121+ dependencies.userService.register(
122+ RegisterUser (fixture.username, fixture.email, fixture.password)
123+ )
124+ val jwt =
125+ withError({ JwtInvalid (it.toString()) }) {
126+ JWT .decodeT(token.value, JWSHMAC512Algorithm )
127+ .bind<KJWTVerificationError , DecodedJWT <JWSHMAC512Algorithm >>()
128+ }
129+ val id =
130+ ensureNotNull(jwt.claimValueAsLong(" id" ).getOrNull()) {
131+ JwtInvalid (" id missing from JWT Token" )
132+ }
131133
132- return RegisteredUser (fixture, token, UserId (id))
134+ return RegisteredUser (fixture, token, UserId (id))
133135}
0 commit comments