-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Simon Vergauwen <[email protected]>
- Loading branch information
Showing
7 changed files
with
83 additions
and
5 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
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
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
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ 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.plugins.resources.post | ||
import io.ktor.client.request.bearerAuth | ||
import io.ktor.http.ContentType | ||
import io.ktor.http.HttpStatusCode | ||
|
@@ -22,6 +23,31 @@ class ProfileRouteSpec : | |
val validUsernameFollowed = "username2" | ||
val validEmailFollowed = "[email protected]" | ||
|
||
"Can follow profile" { | ||
withServer { dependencies -> | ||
val token = | ||
dependencies.userService | ||
.register(RegisterUser(validUsername, validEmail, validPw)) | ||
.shouldBeRight() | ||
dependencies.userService | ||
.register(RegisterUser(validUsernameFollowed, validEmailFollowed, validPw)) | ||
.shouldBeRight() | ||
|
||
val response = | ||
post(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 true | ||
} | ||
} | ||
} | ||
|
||
"Can unfollow profile" { | ||
withServer { dependencies -> | ||
val token = | ||
|
@@ -47,6 +73,14 @@ class ProfileRouteSpec : | |
} | ||
} | ||
|
||
"Needs token to follow" { | ||
withServer { | ||
val response = post(ProfilesResource.Follow(username = validUsernameFollowed)) | ||
|
||
response.status shouldBe HttpStatusCode.Unauthorized | ||
} | ||
} | ||
|
||
"Needs token to unfollow" { | ||
withServer { | ||
val response = delete(ProfilesResource.Follow(username = validUsernameFollowed)) | ||
|
@@ -55,6 +89,22 @@ class ProfileRouteSpec : | |
} | ||
} | ||
|
||
"Username invalid to follow" { | ||
withServer { dependencies -> | ||
val token = | ||
dependencies.userService | ||
.register(RegisterUser(validUsername, validEmail, validPw)) | ||
.shouldBeRight() | ||
|
||
val response = | ||
post(ProfilesResource.Follow(username = validUsernameFollowed)) { | ||
bearerAuth(token.value) | ||
} | ||
|
||
response.status shouldBe HttpStatusCode.UnprocessableEntity | ||
} | ||
} | ||
|
||
"Username invalid to unfollow" { | ||
withServer { dependencies -> | ||
val token = | ||
|