-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test that covers the missing username path
- Loading branch information
1 parent
85eb393
commit 64dbe4d
Showing
2 changed files
with
73 additions
and
55 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
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 |
---|---|---|
|
@@ -7,76 +7,83 @@ 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.bearerAuth | ||
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 : | ||
StringSpec({ | ||
val validUsername = "username" | ||
val validEmail = "[email protected]" | ||
val validPw = "123456789" | ||
val validUsernameFollowed = "username2" | ||
val validEmailFollowed = "[email protected]" | ||
|
||
"Can unfollow profile" { | ||
withServer { dependencies -> | ||
val token = dependencies.userService | ||
.register(RegisterUser(validUsername, validEmail, validPw)) | ||
.shouldBeRight() | ||
dependencies.userService | ||
.register(RegisterUser(validUsernameFollowed, validEmailFollowed, validPw)) | ||
.shouldBeRight() | ||
|
||
val response = delete(ProfilesResource.Follow(username = validUsernameFollowed)) { | ||
bearerAuth(token.value) | ||
} | ||
|
||
response.status shouldBe HttpStatusCode.OK | ||
with(response.body<ProfileWrapper<Profile>>().profile) { | ||
username shouldBe validUsernameFollowed | ||
bio shouldBe "" | ||
image shouldBe "" | ||
following shouldBe false | ||
} | ||
} | ||
} | ||
val validUsername = "username" | ||
val validEmail = "[email protected]" | ||
val validPw = "123456789" | ||
val validUsernameFollowed = "username2" | ||
val validEmailFollowed = "[email protected]" | ||
|
||
"Needs token to unfollow" { | ||
withServer { | ||
val response = delete(ProfilesResource.Follow(username = validUsernameFollowed)) | ||
"Can unfollow profile" { | ||
withServer { dependencies -> | ||
val token = | ||
dependencies.userService | ||
.register(RegisterUser(validUsername, validEmail, validPw)) | ||
.shouldBeRight() | ||
dependencies.userService | ||
.register(RegisterUser(validUsernameFollowed, validEmailFollowed, validPw)) | ||
.shouldBeRight() | ||
|
||
response.status shouldBe HttpStatusCode.Unauthorized | ||
} | ||
val response = | ||
delete(ProfilesResource.Follow(username = validUsernameFollowed)) { | ||
bearerAuth(token.value) | ||
} | ||
|
||
response.status shouldBe HttpStatusCode.OK | ||
with(response.body<ProfileWrapper<Profile>>().profile) { | ||
username shouldBe validUsernameFollowed | ||
bio shouldBe "" | ||
image shouldBe "" | ||
following shouldBe false | ||
} | ||
} | ||
} | ||
|
||
"Username invalid to unfollow" { | ||
withServer { dependencies -> | ||
val token = dependencies.userService | ||
.register(RegisterUser(validUsername, validEmail, validPw)) | ||
.shouldBeRight() | ||
"Needs token to unfollow" { | ||
withServer { | ||
val response = delete(ProfilesResource.Follow(username = validUsernameFollowed)) | ||
|
||
val response = delete(ProfilesResource.Follow(username = validUsernameFollowed)) { | ||
bearerAuth(token.value) | ||
} | ||
response.status shouldBe HttpStatusCode.Unauthorized | ||
} | ||
} | ||
|
||
response.status shouldBe HttpStatusCode.UnprocessableEntity | ||
} | ||
} | ||
"Username invalid to unfollow" { | ||
withServer { dependencies -> | ||
val token = | ||
dependencies.userService | ||
.register(RegisterUser(validUsername, validEmail, validPw)) | ||
.shouldBeRight() | ||
|
||
val response = | ||
delete(ProfilesResource.Follow(username = validUsernameFollowed)) { | ||
bearerAuth(token.value) | ||
} | ||
|
||
response.status shouldBe HttpStatusCode.UnprocessableEntity | ||
} | ||
} | ||
|
||
"Get profile with no following" { | ||
withServer { dependencies: Dependencies -> | ||
dependencies.userService | ||
.register(RegisterUser(userName, validEmail, validPw)) | ||
.register(RegisterUser(validUsername, validEmail, validPw)) | ||
.shouldBeRight() | ||
val response = | ||
get(ProfileResource.Username(username = userName)) { | ||
get(ProfilesResource.Username(username = validUsername)) { | ||
contentType(ContentType.Application.Json) | ||
} | ||
|
||
response.status shouldBe HttpStatusCode.OK | ||
with(response.body<Profile>()) { | ||
username shouldBe userName | ||
username shouldBe validUsername | ||
bio shouldBe "" | ||
image shouldBe "" | ||
following shouldBe false | ||
|
@@ -87,13 +94,26 @@ class ProfileRouteSpec : | |
"Get profile invalid username" { | ||
withServer { | ||
val response = | ||
get(ProfileResource.Username(username = userName)) { | ||
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("User with username=$userName not found") | ||
listOf("Missing username parameter in request") | ||
} | ||
} | ||
}) | ||
}) |