about summary refs log tree commit diff
path: root/spec/controllers/api/v1/accounts/credentials_controller_spec.rb
blob: 3f655c7b2350b07e42af0c71f00bd1950b92581f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'rails_helper'

describe Api::V1::Accounts::CredentialsController do
  render_views

  let(:user)  { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
  let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write') }

  before do
    allow(controller).to receive(:doorkeeper_token) { token }
  end

  describe 'GET #show' do
    it 'returns http success' do
      get :show
      expect(response).to have_http_status(:success)
    end
  end

  describe 'PATCH #update' do
    describe 'with valid data' do
      before do
        patch :update, params: {
          display_name: "Alice Isn't Dead",
          note: "Hi!\n\nToot toot!",
          avatar: fixture_file_upload('files/avatar.gif', 'image/gif'),
          header: fixture_file_upload('files/attachment.jpg', 'image/jpeg'),
        }
      end

      it 'returns http success' do
        expect(response).to have_http_status(:success)
      end

      it 'updates account info' do
        user.account.reload

        expect(user.account.display_name).to eq("Alice Isn't Dead")
        expect(user.account.note).to eq("Hi!\n\nToot toot!")
        expect(user.account.avatar).to exist
        expect(user.account.header).to exist
      end
    end

    describe 'with invalid data' do
      before do
        # note length limit is 501, presently hardcoded, so give it 510 to fail
        patch :update, params: { note: '1234567890' * 51 }
      end

      it 'returns http unprocessable entity' do
        expect(response).to have_http_status(:unprocessable_entity)
      end
    end
  end
end