|
| 1 | +require 'rails_helper' |
| 2 | + |
| 3 | +RSpec.describe Api::V1::MarkersController, type: :controller 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: 'read:statuses write:statuses') } |
| 8 | + |
| 9 | + before { allow(controller).to receive(:doorkeeper_token) { token } } |
| 10 | + |
| 11 | + describe 'GET #index' do |
| 12 | + before do |
| 13 | + Fabricate(:marker, timeline: 'home', last_read_id: 123, user: user) |
| 14 | + Fabricate(:marker, timeline: 'notifications', last_read_id: 456, user: user) |
| 15 | + |
| 16 | + get :index, params: { timeline: %w(home notifications) } |
| 17 | + end |
| 18 | + |
| 19 | + it 'returns http success' do |
| 20 | + expect(response).to have_http_status(200) |
| 21 | + end |
| 22 | + |
| 23 | + it 'returns markers' do |
| 24 | + json = body_as_json |
| 25 | + |
| 26 | + expect(json.key?(:home)).to be true |
| 27 | + expect(json[:home][:last_read_id]).to eq '123' |
| 28 | + expect(json.key?(:notifications)).to be true |
| 29 | + expect(json[:notifications][:last_read_id]).to eq '456' |
| 30 | + end |
| 31 | + end |
| 32 | + |
| 33 | + describe 'POST #create' do |
| 34 | + context 'when no marker exists' do |
| 35 | + before do |
| 36 | + post :create, params: { home: { last_read_id: '69420' } } |
| 37 | + end |
| 38 | + |
| 39 | + it 'returns http success' do |
| 40 | + expect(response).to have_http_status(200) |
| 41 | + end |
| 42 | + |
| 43 | + it 'creates a marker' do |
| 44 | + expect(user.markers.first.timeline).to eq 'home' |
| 45 | + expect(user.markers.first.last_read_id).to eq 69420 |
| 46 | + end |
| 47 | + end |
| 48 | + |
| 49 | + context 'when a marker exists' do |
| 50 | + before do |
| 51 | + post :create, params: { home: { last_read_id: '69420' } } |
| 52 | + post :create, params: { home: { last_read_id: '70120' } } |
| 53 | + end |
| 54 | + |
| 55 | + it 'returns http success' do |
| 56 | + expect(response).to have_http_status(200) |
| 57 | + end |
| 58 | + |
| 59 | + it 'updates a marker' do |
| 60 | + expect(user.markers.first.timeline).to eq 'home' |
| 61 | + expect(user.markers.first.last_read_id).to eq 70120 |
| 62 | + end |
| 63 | + end |
| 64 | + end |
| 65 | +end |
0 commit comments