]> cat aescling's git repositories - mastodon.git/blob - spec/controllers/api/v1/accounts/credentials_controller_spec.rb
Merge branch 'master' into glitch-soc/merge-upstream
[mastodon.git] / spec / controllers / api / v1 / accounts / credentials_controller_spec.rb
1 require 'rails_helper'
2
3 describe Api::V1::Accounts::CredentialsController do
4 render_views
5
6 let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
7 let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
8
9 context 'with an oauth token' do
10 before do
11 allow(controller).to receive(:doorkeeper_token) { token }
12 end
13
14 describe 'GET #show' do
15 let(:scopes) { 'read:accounts' }
16
17 it 'returns http success' do
18 get :show
19 expect(response).to have_http_status(200)
20 end
21 end
22
23 describe 'PATCH #update' do
24 let(:scopes) { 'write:accounts' }
25
26 describe 'with valid data' do
27 before do
28 allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async)
29
30 patch :update, params: {
31 display_name: "Alice Isn't Dead",
32 note: "Hi!\n\nToot toot!",
33 avatar: fixture_file_upload('files/avatar.gif', 'image/gif'),
34 header: fixture_file_upload('files/attachment.jpg', 'image/jpeg'),
35 source: {
36 privacy: 'unlisted',
37 sensitive: true,
38 }
39 }
40 end
41
42 it 'returns http success' do
43 expect(response).to have_http_status(200)
44 end
45
46 it 'updates account info' do
47 user.account.reload
48
49 expect(user.account.display_name).to eq("Alice Isn't Dead")
50 expect(user.account.note).to eq("Hi!\n\nToot toot!")
51 expect(user.account.avatar).to exist
52 expect(user.account.header).to exist
53 expect(user.setting_default_privacy).to eq('unlisted')
54 expect(user.setting_default_sensitive).to eq(true)
55 end
56
57 it 'queues up an account update distribution' do
58 expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(user.account_id)
59 end
60 end
61
62 describe 'with invalid data' do
63 before do
64 note = 'This is too long. '
65 note = note + 'a' * (Account::MAX_NOTE_LENGTH - note.length + 1)
66 patch :update, params: { note: note }
67 end
68
69 it 'returns http unprocessable entity' do
70 expect(response).to have_http_status(:unprocessable_entity)
71 end
72 end
73 end
74 end
75
76 context 'without an oauth token' do
77 before do
78 allow(controller).to receive(:doorkeeper_token) { nil }
79 end
80
81 describe 'GET #show' do
82 it 'returns http unauthorized' do
83 get :show
84 expect(response).to have_http_status(:unauthorized)
85 end
86 end
87
88 describe 'PATCH #update' do
89 it 'returns http unauthorized' do
90 patch :update, params: { note: 'Foo' }
91 expect(response).to have_http_status(:unauthorized)
92 end
93 end
94 end
95 end
This page took 0.088815 seconds and 4 git commands to generate.