-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/get profile by username #186
Changes from all commits
6a95b59
437682c
0d90fea
b38fd78
0ead863
9a5bfdd
610ccfd
7e66235
95e523b
3a14800
5bf96cc
56bcca7
e820d09
8c1113f
87e0341
6064c0b
76bea8b
85eb393
64dbe4d
665b4ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
package io.github.nomisrev.routes | ||
|
||
import io.github.nomisrev.env.Dependencies | ||
import io.github.nomisrev.service.RegisterUser | ||
import io.github.nomisrev.withServer | ||
import io.kotest.assertions.arrow.core.shouldBeRight | ||
import io.kotest.core.spec.style.StringSpec | ||
import io.kotest.matchers.shouldBe | ||
import io.ktor.client.call.body | ||
import io.ktor.client.plugins.resources.delete | ||
import io.ktor.client.plugins.resources.get | ||
import io.ktor.client.request.bearerAuth | ||
import io.ktor.http.ContentType | ||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.http.contentType | ||
|
||
class ProfileRouteSpec : | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're missing a test case for when the path parameter is missing, I think that would've resulted There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume that the endpoint that we'd want to hit/test is However, I'm having difficulties actually hitting the above endpoint with the current I've read through the docs, and tried with the @Resource("/{$USERNAME?}")
data class Username(val parent: ProfileResource = ProfileResource(), val username: String) Do you have any suggestions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strange, I made a small change and it's working fine for me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm probably missing something obvious, I've tried various things to trigger the The username implementation is marked as optional and a placeholder test that fails on my side is added here I've tried also to write it without the |
||
StringSpec({ | ||
|
@@ -66,4 +70,50 @@ class ProfileRouteSpec : | |
response.status shouldBe HttpStatusCode.UnprocessableEntity | ||
} | ||
} | ||
|
||
"Get profile with no following" { | ||
withServer { dependencies: Dependencies -> | ||
dependencies.userService | ||
.register(RegisterUser(validUsername, validEmail, validPw)) | ||
.shouldBeRight() | ||
val response = | ||
get(ProfilesResource.Username(username = validUsername)) { | ||
contentType(ContentType.Application.Json) | ||
} | ||
|
||
response.status shouldBe HttpStatusCode.OK | ||
with(response.body<Profile>()) { | ||
username shouldBe validUsername | ||
bio shouldBe "" | ||
image shouldBe "" | ||
following shouldBe false | ||
} | ||
} | ||
} | ||
|
||
"Get profile invalid username" { | ||
withServer { | ||
val response = | ||
get(ProfilesResource.Username(username = validUsername)) { | ||
contentType(ContentType.Application.Json) | ||
} | ||
|
||
response.status shouldBe HttpStatusCode.UnprocessableEntity | ||
response.body<GenericErrorModel>().errors.body shouldBe | ||
listOf("User with username=$validUsername not found") | ||
} | ||
} | ||
|
||
"Get profile by username missing username" { | ||
withServer { | ||
val response = | ||
get(ProfilesResource.Username(username = "")) { | ||
contentType(ContentType.Application.Json) | ||
} | ||
|
||
response.status shouldBe HttpStatusCode.UnprocessableEntity | ||
response.body<GenericErrorModel>().errors.body shouldBe | ||
listOf("Missing username parameter in request") | ||
} | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to add this for detekt, I'd prefer not to change the filename. Perhaps we should disable this rule in some other issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, having to force every routes implementation to add the
@file:Suppress
for detekt isn't deal, something for a future PR 😄Addressed in 76bea8b