# frozen_string_literal: true # == Schema Information # # Table name: accounts # # id :uuid not null, primary key # created_at :datetime not null # updated_at :datetime not null # require 'test_helper' class AccountTest < ActiveSupport::TestCase test '::authenticate_by_api_key! returns the user who owns the api key' do token = accounts(:stouset).api_keys.generate! account = Account.authenticate_by_api_key!(token) assert_equal accounts(:stouset), account end test '::authenticate_by_api_key! allows multiple API keys per account' do account = accounts(:stouset) keys = [ account.api_keys.generate!, account.api_keys.generate!, account.api_keys.generate!, ] keys.each do |key| assert_equal account, Account.authenticate_by_api_key!(key) end end test '::authenticate_by_api_key! raises if the key is incorrect' do assert_raises(ActiveRecord::RecordNotFound) do Account.authenticate_by_api_key!('fake') end end end