|
4 | 4 |
|
5 | 5 | RSpec.describe 'Domain Blocks' do |
6 | 6 | describe 'GET /api/v1/instance/domain_blocks' do |
7 | | - before do |
8 | | - Fabricate(:domain_block) |
9 | | - end |
| 7 | + let(:user) { Fabricate(:user) } |
| 8 | + let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id).token } |
| 9 | + |
| 10 | + before { Fabricate(:domain_block) } |
10 | 11 |
|
11 | 12 | context 'with domain blocks set to all' do |
12 | 13 | before { Setting.show_domain_blocks = 'all' } |
|
30 | 31 | context 'with domain blocks set to users' do |
31 | 32 | before { Setting.show_domain_blocks = 'users' } |
32 | 33 |
|
33 | | - it 'returns http not found' do |
34 | | - get api_v1_instance_domain_blocks_path |
| 34 | + context 'without authentication token' do |
| 35 | + it 'returns http not found' do |
| 36 | + get api_v1_instance_domain_blocks_path |
35 | 37 |
|
36 | | - expect(response) |
37 | | - .to have_http_status(404) |
| 38 | + expect(response) |
| 39 | + .to have_http_status(404) |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + context 'with authentication token' do |
| 44 | + context 'with unapproved user' do |
| 45 | + before { user.update(approved: false) } |
| 46 | + |
| 47 | + it 'returns http not found' do |
| 48 | + get api_v1_instance_domain_blocks_path, headers: { 'Authorization' => "Bearer #{token}" } |
| 49 | + |
| 50 | + expect(response) |
| 51 | + .to have_http_status(404) |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + context 'with unconfirmed user' do |
| 56 | + before { user.update(confirmed_at: nil) } |
| 57 | + |
| 58 | + it 'returns http not found' do |
| 59 | + get api_v1_instance_domain_blocks_path, headers: { 'Authorization' => "Bearer #{token}" } |
| 60 | + |
| 61 | + expect(response) |
| 62 | + .to have_http_status(404) |
| 63 | + end |
| 64 | + end |
| 65 | + |
| 66 | + context 'with disabled user' do |
| 67 | + before { user.update(disabled: true) } |
| 68 | + |
| 69 | + it 'returns http not found' do |
| 70 | + get api_v1_instance_domain_blocks_path, headers: { 'Authorization' => "Bearer #{token}" } |
| 71 | + |
| 72 | + expect(response) |
| 73 | + .to have_http_status(404) |
| 74 | + end |
| 75 | + end |
| 76 | + |
| 77 | + context 'with suspended user' do |
| 78 | + before { user.account.update(suspended_at: Time.zone.now) } |
| 79 | + |
| 80 | + it 'returns http not found' do |
| 81 | + get api_v1_instance_domain_blocks_path, headers: { 'Authorization' => "Bearer #{token}" } |
| 82 | + |
| 83 | + expect(response) |
| 84 | + .to have_http_status(403) |
| 85 | + end |
| 86 | + end |
| 87 | + |
| 88 | + context 'with moved user' do |
| 89 | + before { user.account.update(moved_to_account_id: Fabricate(:account).id) } |
| 90 | + |
| 91 | + it 'returns http success' do |
| 92 | + get api_v1_instance_domain_blocks_path, headers: { 'Authorization' => "Bearer #{token}" } |
| 93 | + |
| 94 | + expect(response) |
| 95 | + .to have_http_status(200) |
| 96 | + |
| 97 | + expect(response.content_type) |
| 98 | + .to start_with('application/json') |
| 99 | + |
| 100 | + expect(response.parsed_body) |
| 101 | + .to be_present |
| 102 | + .and(be_an(Array)) |
| 103 | + .and(have_attributes(size: 1)) |
| 104 | + end |
| 105 | + end |
| 106 | + |
| 107 | + context 'with normal user' do |
| 108 | + it 'returns http success' do |
| 109 | + get api_v1_instance_domain_blocks_path, headers: { 'Authorization' => "Bearer #{token}" } |
| 110 | + |
| 111 | + expect(response) |
| 112 | + .to have_http_status(200) |
| 113 | + |
| 114 | + expect(response.content_type) |
| 115 | + .to start_with('application/json') |
| 116 | + |
| 117 | + expect(response.parsed_body) |
| 118 | + .to be_present |
| 119 | + .and(be_an(Array)) |
| 120 | + .and(have_attributes(size: 1)) |
| 121 | + end |
| 122 | + end |
38 | 123 | end |
39 | 124 | end |
40 | 125 |
|
|
0 commit comments