create_spec.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Service::User::AccessToken::Create do
  4. let(:user) { create(:user) }
  5. let(:name) { Faker::Lorem.word }
  6. let(:permission) { %w[ticket.agent] }
  7. let(:expires_at) { 1.day.from_now.to_date }
  8. it 'creates persistent API token with given permissions' do
  9. token = described_class.new(user, name:, permission:).execute
  10. expect(token).to have_attributes(
  11. user: user,
  12. name: name,
  13. action: 'api',
  14. persistent: true,
  15. expires_at: nil,
  16. preferences: include(permission: permission)
  17. )
  18. end
  19. it 'creates token with given expiration time' do
  20. token = described_class.new(user, name:, permission:, expires_at:).execute
  21. expect(token).to have_attributes(
  22. user: user,
  23. name: name,
  24. action: 'api',
  25. persistent: true,
  26. expires_at: expires_at,
  27. preferences: include(permission: permission)
  28. )
  29. end
  30. end