add misc releases support in API

This commit is contained in:
Bilal
2020-07-08 14:49:01 +02:00
parent 19b1e75384
commit 6e8788f9ea
6 changed files with 72 additions and 2 deletions

View File

@@ -0,0 +1,42 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::MiscReleasesController, type: :controller do
let(:current_user) { create(:user) }
let(:project) { create(:project, name: 'first', account: current_user.primary_account) }
describe '#index' do
it 'returns a succesful response' do
create(:misc_release, person_first_name: 'John', person_last_name: 'Lee', project_id: project.id)
create(:misc_release, person_first_name: 'Jane', person_last_name: 'Lee', project_id: project.id)
sign_in_to_api(current_user)
get :index, params: { project_id: project.id }
expect(response).to be_successful
expect(response.body).to include 'John'
expect(response.body).to include 'Jane'
end
end
describe '#show' do
it 'returns a succesful response' do
release1 = create(:misc_release, person_first_name: 'John', person_last_name: 'Lee', project_id: project.id)
release2 = create(:misc_release, person_first_name: 'Jane', person_last_name: 'Lee', project_id: project.id)
sign_in_to_api(current_user)
get :show, params: { id: release1 }
expect(response).to be_successful
expect(response.body).to include 'John'
expect(response.body).not_to include 'Jane'
get :show, params: { id: release2 }
expect(response).to be_successful
expect(response.body).not_to include 'John'
expect(response.body).to include 'Jane'
end
end
end

View File

@@ -18,6 +18,10 @@ releases = [
{
type: :material_release,
obligatory_attribute: :name
},
{
type: :misc_release,
obligatory_attribute: :person_name
}
]

View File

@@ -110,6 +110,16 @@ RSpec.describe Api::SyncController, type: :controller do
expect(guardian_photo).to include('id', 'type', 'attributes')
expect(photo_attributes).to include('filename', 'content_type', 'url', 'thumbnail_url')
end
it 'contains misc releases' do
create_default_data
get :index
misc_releases = attributes_for_type('misc_releases')
expect(misc_releases.first).to include('id')
end
end
private
@@ -120,6 +130,7 @@ RSpec.describe Api::SyncController, type: :controller do
create(:talent_release, project: project)
create(:location_release, project: project)
create(:material_release, project: project)
create(:misc_release, project: project)
end
def create_default_data_with_guardian_info