mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-25 17:51:36 +01:00
Expand coverage for User#token_for_app
(#32434)
This commit is contained in:
parent
63df649fe5
commit
ae676edc2b
1 changed files with 30 additions and 10 deletions
|
@ -387,23 +387,43 @@ RSpec.describe User do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'token_for_app' do
|
describe '#token_for_app' do
|
||||||
let(:user) { Fabricate(:user) }
|
let(:user) { Fabricate(:user) }
|
||||||
|
|
||||||
|
context 'when user owns app but does not have tokens' do
|
||||||
let(:app) { Fabricate(:application, owner: user) }
|
let(:app) { Fabricate(:application, owner: user) }
|
||||||
|
|
||||||
it 'returns a token' do
|
it 'creates and returns a persisted token' do
|
||||||
expect(user.token_for_app(app)).to be_a(Doorkeeper::AccessToken)
|
expect { user.token_for_app(app) }
|
||||||
|
.to change(Doorkeeper::AccessToken.where(resource_owner_id: user.id, application: app), :count).by(1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'persists a token' do
|
context 'when user owns app and already has tokens' do
|
||||||
t = user.token_for_app(app)
|
let(:app) { Fabricate(:application, owner: user) }
|
||||||
expect(user.token_for_app(app)).to eql(t)
|
let!(:token) { Fabricate :access_token, application: app, resource_owner_id: user.id }
|
||||||
|
|
||||||
|
it 'returns a persisted token' do
|
||||||
|
expect(user.token_for_app(app))
|
||||||
|
.to be_a(Doorkeeper::AccessToken)
|
||||||
|
.and eq(token)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'is nil if user does not own app' do
|
context 'when user does not own app' do
|
||||||
app.update!(owner: nil)
|
let(:app) { Fabricate(:application) }
|
||||||
|
|
||||||
expect(user.token_for_app(app)).to be_nil
|
it 'returns nil' do
|
||||||
|
expect(user.token_for_app(app))
|
||||||
|
.to be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when app is nil' do
|
||||||
|
it 'returns nil' do
|
||||||
|
expect(user.token_for_app(nil))
|
||||||
|
.to be_nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue