11167: Merge branch 'master' into 11167-wb-remove-arvget
[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
7 class ApiClientAuthorizationTest < ActiveSupport::TestCase
8   include CurrentApiClient
9
10   [:admin_trustedclient, :active_trustedclient].each do |token|
11     test "ApiClientAuthorization can be created then deleted by #{token}" do
12       set_user_from_auth token
13       x = ApiClientAuthorization.create!(user_id: current_user.id,
14                                          api_client_id: 0,
15                                          scopes: [])
16       newtoken = x.api_token
17       assert x.destroy, "Failed to destroy new ApiClientAuth"
18       assert_empty ApiClientAuthorization.where(api_token: newtoken), "Destroyed ApiClientAuth is still in database"
19     end
20   end
21 end