The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

66 lines
1.9 KiB

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