# Copyright 2018 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

defmodule GoogleApi.Drive.FilesTest do
  use GoogleApi.Drive.TestHelper
  alias GoogleApi.Drive.V3.Connection
  alias GoogleApi.Drive.V3.Model.File
  alias GoogleApi.Drive.V3.Model.FileList
  alias GoogleApi.Drive.V3.Api.Files

  if System.get_env("GOOGLE_APPLICATION_CREDENTIALS") == nil do
    @tag :skip
  end
  test "upload file" do
    conn = Connection.new(&for_scope/1)

    assert {:ok, file} =
             Files.drive_files_create_simple(
               conn,
               "multipart",
               %File{
                 name: "README.md"
               },
               "README.md"
             )

    assert %File{} = file
  end

  if System.get_env("GOOGLE_APPLICATION_CREDENTIALS") == nil do
    @tag :skip
  end
  test "list files" do
    conn = Connection.new(&for_scope/1)

    assert {:ok, file_list} = Files.drive_files_list(conn)
    assert %FileList{} = file_list
  end
end
