+ describe "POST /friendships/destroy.json" do
+ setup [:valid_user]
+ test "without valid credentials", %{conn: conn} do
+ conn = post conn, "/api/friendships/destroy.json"
+ assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
+ end
+
+ test "with credentials", %{conn: conn, user: current_user} do
+ {:ok, followed } = UserBuilder.insert(%{name: "some guy"})
+
+ {:ok, current_user} = User.follow(current_user, followed)
+ assert current_user.following == [User.ap_followers(followed)]
+
+ conn = conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/friendships/destroy.json", %{user_id: followed.id})
+
+ current_user = Repo.get(User, current_user.id)
+ assert current_user.following == []
+ assert json_response(conn, 200) == UserRepresenter.to_map(followed)
+ end
+ end
+