14287: Make collection name "" equivalent to null.
[arvados.git] / services / api / test / unit / api_client_authorization_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'test_helper'
6 require 'sweep_trashed_objects'
7
8 class ApiClientAuthorizationTest < ActiveSupport::TestCase
9   include CurrentApiClient
10
11   [:admin_trustedclient, :active_trustedclient].each do |token|
12     test "ApiClientAuthorization can be created then deleted by #{token}" do
13       set_user_from_auth token
14       x = ApiClientAuthorization.create!(user_id: current_user.id,
15                                          api_client_id: 0,
16                                          scopes: [])
17       newtoken = x.api_token
18       assert x.destroy, "Failed to destroy new ApiClientAuth"
19       assert_empty ApiClientAuthorization.where(api_token: newtoken), "Destroyed ApiClientAuth is still in database"
20     end
21   end
22
23   test "delete expired in SweepTrashedObjects" do
24     assert_not_empty ApiClientAuthorization.where(uuid: api_client_authorizations(:expired).uuid)
25     SweepTrashedObjects.sweep_now
26     assert_empty ApiClientAuthorization.where(uuid: api_client_authorizations(:expired).uuid)
27   end
28
29 end