2022-03-01 15:48:58 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 05:12:25 +00:00
|
|
|
RSpec.describe ScopeTransformer do
|
2022-03-01 15:48:58 +00:00
|
|
|
describe '#apply' do
|
|
|
|
subject { described_class.new.apply(ScopeParser.new.parse(input)) }
|
|
|
|
|
|
|
|
shared_examples 'a scope' do |namespace, term, access|
|
2024-09-25 07:56:42 +00:00
|
|
|
it 'parses the attributes' do
|
|
|
|
expect(subject)
|
|
|
|
.to have_attributes(
|
|
|
|
term: term,
|
|
|
|
namespace: namespace,
|
|
|
|
access: access
|
|
|
|
)
|
2022-03-01 15:48:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-06-06 07:30:10 +00:00
|
|
|
context 'with scope "profile"' do
|
|
|
|
let(:input) { 'profile' }
|
|
|
|
|
|
|
|
it_behaves_like 'a scope', nil, 'profile', 'read'
|
|
|
|
end
|
|
|
|
|
2023-05-04 03:49:08 +00:00
|
|
|
context 'with scope "read"' do
|
2022-03-01 15:48:58 +00:00
|
|
|
let(:input) { 'read' }
|
|
|
|
|
|
|
|
it_behaves_like 'a scope', nil, 'all', 'read'
|
|
|
|
end
|
|
|
|
|
2023-05-04 03:49:08 +00:00
|
|
|
context 'with scope "write"' do
|
2022-03-01 15:48:58 +00:00
|
|
|
let(:input) { 'write' }
|
|
|
|
|
|
|
|
it_behaves_like 'a scope', nil, 'all', 'write'
|
|
|
|
end
|
|
|
|
|
2023-05-04 03:49:08 +00:00
|
|
|
context 'with scope "follow"' do
|
2022-03-01 15:48:58 +00:00
|
|
|
let(:input) { 'follow' }
|
|
|
|
|
|
|
|
it_behaves_like 'a scope', nil, 'follow', 'read/write'
|
|
|
|
end
|
|
|
|
|
2023-05-04 03:49:08 +00:00
|
|
|
context 'with scope "crypto"' do
|
2022-03-01 15:48:58 +00:00
|
|
|
let(:input) { 'crypto' }
|
|
|
|
|
|
|
|
it_behaves_like 'a scope', nil, 'crypto', 'read/write'
|
|
|
|
end
|
|
|
|
|
2023-05-04 03:49:08 +00:00
|
|
|
context 'with scope "push"' do
|
2022-03-01 15:48:58 +00:00
|
|
|
let(:input) { 'push' }
|
|
|
|
|
|
|
|
it_behaves_like 'a scope', nil, 'push', 'read/write'
|
|
|
|
end
|
|
|
|
|
2023-05-04 03:49:08 +00:00
|
|
|
context 'with scope "admin:read"' do
|
2022-03-01 15:48:58 +00:00
|
|
|
let(:input) { 'admin:read' }
|
|
|
|
|
|
|
|
it_behaves_like 'a scope', 'admin', 'all', 'read'
|
|
|
|
end
|
|
|
|
|
2023-05-04 03:49:08 +00:00
|
|
|
context 'with scope "admin:write"' do
|
2022-03-01 15:48:58 +00:00
|
|
|
let(:input) { 'admin:write' }
|
|
|
|
|
|
|
|
it_behaves_like 'a scope', 'admin', 'all', 'write'
|
|
|
|
end
|
|
|
|
|
2023-05-04 03:49:08 +00:00
|
|
|
context 'with scope "admin:read:accounts"' do
|
2022-03-01 15:48:58 +00:00
|
|
|
let(:input) { 'admin:read:accounts' }
|
|
|
|
|
|
|
|
it_behaves_like 'a scope', 'admin', 'accounts', 'read'
|
|
|
|
end
|
|
|
|
|
2023-05-04 03:49:08 +00:00
|
|
|
context 'with scope "admin:write:accounts"' do
|
2022-03-01 15:48:58 +00:00
|
|
|
let(:input) { 'admin:write:accounts' }
|
|
|
|
|
|
|
|
it_behaves_like 'a scope', 'admin', 'accounts', 'write'
|
|
|
|
end
|
|
|
|
|
2023-05-04 03:49:08 +00:00
|
|
|
context 'with scope "read:accounts"' do
|
2022-03-01 15:48:58 +00:00
|
|
|
let(:input) { 'read:accounts' }
|
|
|
|
|
|
|
|
it_behaves_like 'a scope', nil, 'accounts', 'read'
|
|
|
|
end
|
|
|
|
|
2023-05-04 03:49:08 +00:00
|
|
|
context 'with scope "write:accounts"' do
|
2022-03-01 15:48:58 +00:00
|
|
|
let(:input) { 'write:accounts' }
|
|
|
|
|
|
|
|
it_behaves_like 'a scope', nil, 'accounts', 'write'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|