diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2017-01-29 12:35:55 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-01-29 12:35:55 +0100 |
commit | e70e721a0d90e7b9b8b9bbf45b92fec2eb7be26b (patch) | |
tree | 60f125566b627014e81acc2c958f3a81fa35cca9 /spec | |
parent | 83ccdeb87a6d9cd9b506707be8814cc7a0f242d2 (diff) |
Add tests for new API
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/api/v1/devices_controller_spec.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/spec/controllers/api/v1/devices_controller_spec.rb b/spec/controllers/api/v1/devices_controller_spec.rb new file mode 100644 index 000000000..745a462e3 --- /dev/null +++ b/spec/controllers/api/v1/devices_controller_spec.rb @@ -0,0 +1,38 @@ +require 'rails_helper' + +RSpec.describe Api::V1::DevicesController, type: :controller do + let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) } + let(:token) { double acceptable?: true, resource_owner_id: user.id } + + before do + allow(controller).to receive(:doorkeeper_token) { token } + end + + describe 'POST #register' do + before do + post :register, params: { registration_id: 'foo123' } + end + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + + it 'registers device' do + expect(Device.where(account: user.account, registration_id: 'foo123').first).to_not be_nil + end + end + + describe 'POST #unregister' do + before do + post :unregister, params: { registration_id: 'foo123' } + end + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + + it 'removes device' do + expect(Device.where(account: user.account, registration_id: 'foo123').first).to be_nil + end + end +end |