Skip to content

List followers of a user #810

Description

@abteilung6

Users.scala

  /**
   * Lists the people following the specified user.
   *
   * @param username of the user to retrieve
   * @param pagination Limit and Offset for pagination
   * @param headers optional user headers to include in the request
   * @return GHResponse[List[User]\] User details
   */
  def getFollowers(
      username: String,
      pagination: Option[Pagination] = None,
      headers: Map[String, String] = Map()
  ): F[GHResponse[List[User]]]

UsersInterpreter.scala

  override def getFollowers(
      username: String,
      pagination: Option[Pagination],
      headers: Map[String, String]
  ): F[GHResponse[List[User]]] =
    client
      .get[List[User]](s"users/$username/followers", headers, pagination = pagination)

UsersSpec.scala

  "Users >> GetFollowers" should "return the expected followers list for a valid username" taggedAs Integration in {
    val response = clientResource
      .use { client =>
        Github[IO](client, accessToken).users
          .getFollowers(validUsername, None, headerUserAgent)
      }
      .unsafeRunSync()

    testIsRight[List[User]](response, r => r.nonEmpty shouldBe true)
    response.statusCode shouldBe okStatusCode
  }

  it should "return error on Left for invalid username" taggedAs Integration in {
    val response = clientResource
      .use { client =>
        Github[IO](client, accessToken).users
          .getFollowers(invalidUsername, None, headerUserAgent)
      }
      .unsafeRunSync()

    testIsLeft[GHError.NotFoundError, List[User]](response)
    response.statusCode shouldBe notFoundStatusCode
  }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions