markers_controller_spec.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Api::V1::MarkersController do
  4. render_views
  5. let!(:user) { Fabricate(:user) }
  6. let!(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:statuses write:statuses') }
  7. before { allow(controller).to receive(:doorkeeper_token) { token } }
  8. describe 'GET #index' do
  9. before do
  10. Fabricate(:marker, timeline: 'home', last_read_id: 123, user: user)
  11. Fabricate(:marker, timeline: 'notifications', last_read_id: 456, user: user)
  12. get :index, params: { timeline: %w(home notifications) }
  13. end
  14. it 'returns http success' do
  15. expect(response).to have_http_status(200)
  16. end
  17. it 'returns markers' do
  18. json = body_as_json
  19. expect(json.key?(:home)).to be true
  20. expect(json[:home][:last_read_id]).to eq '123'
  21. expect(json.key?(:notifications)).to be true
  22. expect(json[:notifications][:last_read_id]).to eq '456'
  23. end
  24. end
  25. describe 'POST #create' do
  26. context 'when no marker exists' do
  27. before do
  28. post :create, params: { home: { last_read_id: '69420' } }
  29. end
  30. it 'returns http success' do
  31. expect(response).to have_http_status(200)
  32. end
  33. it 'creates a marker' do
  34. expect(user.markers.first.timeline).to eq 'home'
  35. expect(user.markers.first.last_read_id).to eq 69_420
  36. end
  37. end
  38. context 'when a marker exists' do
  39. before do
  40. post :create, params: { home: { last_read_id: '69420' } }
  41. post :create, params: { home: { last_read_id: '70120' } }
  42. end
  43. it 'returns http success' do
  44. expect(response).to have_http_status(200)
  45. end
  46. it 'updates a marker' do
  47. expect(user.markers.first.timeline).to eq 'home'
  48. expect(user.markers.first.last_read_id).to eq 70_120
  49. end
  50. end
  51. end
  52. end