diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 647d01678..67a2a8c3b 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -81,7 +81,7 @@ def show # Use callbacks to share common setup or constraints between actions. def set_provider - @provider = Provider.unscoped.where("allocator.role_name IN ('ROLE_ALLOCATOR', 'ROLE_MEMBER')").where(deleted_at: nil).where(symbol: params[:id]).first + @provider = Provider.unscoped.where("allocator.role_name IN ('ROLE_FOR_PROFIT_PROVIDER', 'ROLE_CONTRACTUAL_PROVIDER', 'ROLE_CONSORTIUM_LEAD' , 'ROLE_ALLOCATOR', 'ROLE_MEMBER')").where(deleted_at: nil).where(symbol: params[:id]).first fail ActiveRecord::RecordNotFound unless @provider.present? end end diff --git a/app/controllers/providers_controller.rb b/app/controllers/providers_controller.rb index 03bb1422b..dcad98d51 100644 --- a/app/controllers/providers_controller.rb +++ b/app/controllers/providers_controller.rb @@ -179,7 +179,7 @@ def destroy # Use callbacks to share common setup or constraints between actions. def set_provider - @provider = Provider.unscoped.where("allocator.role_name IN ('ROLE_ALLOCATOR', 'ROLE_ADMIN')").where(deleted_at: nil).where(symbol: params[:id]).first + @provider = Provider.unscoped.where("allocator.role_name IN ('ROLE_FOR_PROFIT_PROVIDER', 'ROLE_CONTRACTUAL_PROVIDER', 'ROLE_CONSORTIUM_LEAD' , 'ROLE_ALLOCATOR', 'ROLE_ADMIN')").where(deleted_at: nil).where(symbol: params[:id]).first fail ActiveRecord::RecordNotFound unless @provider.present? end @@ -194,16 +194,18 @@ def safe_params ActiveModelSerializers::Deserialization.jsonapi_parse!( params, only: [ - :name, :symbol, :description, :website, :joined, "organizationType", "focusArea", :phone, "contactName", "contactEmail", "isActive", "passwordInput", :country, "billingInformation",{ "billingInformation": ["postCode", :state, :city, :address, :department, :organization, :country]}, "rorId", "twitterHandle", - "generalContact",{ "generalContact": [:email, "givenName", "familyName"]}, + :name, :symbol, :description, :website, :joined, "organizationType", "focusArea", :phone, "contactName", "contactEmail", "isActive", "passwordInput", :country, "billingInformation",{ "billingInformation": ["postCode", :state, :city, :address, :department, :organization, :country]}, "rorId", "twitterHandle","roleName", "technicalContact",{ "technicalContact": [:email, "givenName", "familyName"]}, + "secondaryBillingContact",{ "secondaryBillingContact": [:email, "givenName", "familyName"]}, + "billingContact",{ "billingContact": [:email, "givenName", "familyName"]}, "serviceContact",{ "serviceContact": [:email, "givenName", "familyName"]}, "votingContact",{ "votingContact": [:email, "givenName", "familyName"]} ], keys: { - "organizationType" => :organization_type, "focusArea" => :focus_area, "contactName" => :contact_name, "contactEmail" => :contact_email, :country => :country_code, "isActive" => :is_active, "passwordInput" => :password_input, "billingInformation" => :billing_information , "postCode" => :post_code, "rorId" => :ror_id, "twitterHandle" =>:twitter_handle, - "generalContact" => :general_contact, + "organizationType" => :organization_type, "focusArea" => :focus_area, "contactName" => :contact_name, "contactEmail" => :contact_email, :country => :country_code, "isActive" => :is_active, "passwordInput" => :password_input, "billingInformation" => :billing_information , "postCode" => :post_code, "rorId" => :ror_id, "twitterHandle" =>:twitter_handle, "roleName" =>:role_name, "technicalContact" => :technical_contact, + "secondaryBillingContact" => :secondary_billing_contact, + "billingContact" => :billing_contact, "serviceContact" => :service_contact, "votingContact" => :voting_contact } diff --git a/app/models/concerns/authenticable.rb b/app/models/concerns/authenticable.rb index db3fe0fb4..b569c6fa7 100644 --- a/app/models/concerns/authenticable.rb +++ b/app/models/concerns/authenticable.rb @@ -66,11 +66,14 @@ def decode_auth_param(username: nil, password: nil) end def get_payload(uid: nil, user: nil, password: nil) - roles = { - "ROLE_ADMIN" => "staff_admin", - "ROLE_ALLOCATOR" => "provider_admin", - "ROLE_DATACENTRE" => "client_admin" - } + roles = { + "ROLE_ADMIN" => "staff_admin", + "ROLE_DATACENTRE" => "client_admin", + "ROLE_ALLOCATOR" => "provider_admin", + "ROLE_CONSORTIUM_LEAD" => "provider_admin", + "ROLE_CONTRACTUAL_PROVIDER" => "provider_admin", + "ROLE_FOR_PROFIT_PROVIDER" => "provider_admin" + } payload = { "uid" => uid, "role_id" => roles.fetch(user.role_name, "user"), @@ -144,11 +147,14 @@ def generate_token(attributes={}) end def get_payload(uid: nil, user: nil, password: nil) - roles = { - "ROLE_ADMIN" => "staff_admin", - "ROLE_ALLOCATOR" => "provider_admin", - "ROLE_DATACENTRE" => "client_admin" - } + roles = { + "ROLE_ADMIN" => "staff_admin", + "ROLE_DATACENTRE" => "client_admin", + "ROLE_ALLOCATOR" => "provider_admin", + "ROLE_CONSORTIUM_LEAD" => "provider_admin", + "ROLE_CONTRACTUAL_PROVIDER" => "provider_admin", + "ROLE_FOR_PROFIT_PROVIDER" => "provider_admin" + } payload = { "uid" => uid, "role_id" => roles.fetch(user.role_name, "user"), diff --git a/app/models/concerns/indexable.rb b/app/models/concerns/indexable.rb index a7e7b0209..766c24271 100644 --- a/app/models/concerns/indexable.rb +++ b/app/models/concerns/indexable.rb @@ -168,9 +168,9 @@ def query(query, options={}) must << { term: { focus_area: options[:focus_area] }} if options[:focus_area].present? if options[:all_members] - must << { terms: { role_name: %w(ROLE_ALLOCATOR ROLE_MEMBER) }} + must << { terms: { role_name: %w( ROLE_FOR_PROFIT_PROVIDER ROLE_CONTRACTUAL_PROVIDER ROLE_CONSORTIUM_LEAD ROLE_ALLOCATOR ROLE_MEMBER) }} else - must << { term: { role_name: "ROLE_ALLOCATOR" }} + must << { terms: { role_name: %w( ROLE_FOR_PROFIT_PROVIDER ROLE_CONTRACTUAL_PROVIDER ROLE_CONSORTIUM_LEAD ROLE_ALLOCATOR) }} end must_not << { exists: { field: "deleted_at" }} unless options[:include_deleted] diff --git a/app/models/provider.rb b/app/models/provider.rb index 19042eb39..a44bebc1c 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -35,16 +35,18 @@ class Provider < ActiveRecord::Base validates_uniqueness_of :symbol, message: "This name has already been taken" validates_format_of :contact_email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, message: "contact_email should be an email" validates_format_of :website, :with => /https?:\/\/[\S]+/ , if: :website?, message: "Website should be an url" - validates_inclusion_of :role_name, :in => %w( ROLE_ALLOCATOR ROLE_MEMBER ROLE_ADMIN ROLE_DEV ), :message => "Role %s is not included in the list" + validates_inclusion_of :role_name, :in => %w( ROLE_FOR_PROFIT_PROVIDER ROLE_CONTRACTUAL_PROVIDER ROLE_CONSORTIUM_LEAD ROLE_ALLOCATOR ROLE_MEMBER ROLE_ADMIN ROLE_DEV ), :message => "Role %s is not included in the list" validates_inclusion_of :organization_type, :in => %w(nationalInstitution nationalLibrary academicInstitution academicLibrary researchInstitution governmentAgency publisher professionalSociety serviceProvider vendor), :message => "organization type %s is not included in the list", if: :organization_type? validates_inclusion_of :focus_area, :in => %w(biomedicalAndHealthSciences earthSciences humanities mathematicsAndComputerScience physicalSciencesAndEngineering socialSciences general), :message => "focus area %s is not included in the list", if: :focus_area? validate :freeze_symbol, :on => :update validates_format_of :ror_id, :with => /\A(?:(http|https):\/\/)?(?:ror\.org\/)?(0\w{6}\d{2})\z/, if: :ror_id? - validates_format_of :twitter_handle, :with => /\A[a-zA-Z0-9_]{1,15}\z/, if: :twitter_handle? - validates :general_contact, contact: true + validates_format_of :twitter_handle, :with => /\A@[a-zA-Z0-9_]{1,16}\z/, if: :twitter_handle? validates :technical_contact, contact: true + validates :billing_contact, contact: true + validates :secondary_billing_contact, contact: true validates :service_contact, contact: true validates :voting_contact, contact: true + #validates :billing_information, billing_information: true ##commented while we collect data before_validation :set_region @@ -112,12 +114,17 @@ class Provider < ActiveRecord::Base city: { type: :text }, country: { type: :text }, address: { type: :text }} - indexes :general_contact, type: :object, properties: { + indexes :technical_contact, type: :object, properties: { email: { type: :text }, given_name: { type: :text}, family_name: { type: :text } } - indexes :technical_contact, type: :object, properties: { + indexes :billing_contact, type: :object, properties: { + email: { type: :text }, + given_name: { type: :text}, + family_name: { type: :text } + } + indexes :secondary_billing_contact, type: :object, properties: { email: { type: :text }, given_name: { type: :text}, family_name: { type: :text } @@ -176,8 +183,9 @@ def as_indexed_json(options={}) "country" => billing_country, "city" => billing_city }, - "general_contact" => general_contact, "technical_contact" => technical_contact, + "billing_contact" => billing_contact, + "secondary_billing_contact" => secondary_billing_contact, "service_contact" => service_contact, "voting_contact" => voting_contact, "created" => created, @@ -212,11 +220,11 @@ def csv description: description, website: website, region: region_human_name, - country: country_name, + country: country_code, logo_url: logo_url, focus_area: focus_area, organization_type: organization_type, - member_type: member_type, + member_type: member_type_label, billing_address: billing_address, billing_post_code: billing_post_code, billing_city: billing_city, @@ -276,6 +284,36 @@ def billing_country billing_information.fetch("country",nil) if billing_information.present? end + def member_type_label + member_type_labels[role_name] + end + + def member_type_labels + { + "ROLE_MEMBER" => "Member Only", + "ROLE_ALLOCATOR" => "Member Provider", + "ROLE_CONSORTIUM_LEAD" => "Consortium Lead", + "ROLE_CONTRACTUAL_PROVIDER" => "Contractual Provider", + "ROLE_ADMIN" => "DataCite admin", + "ROLE_DEV" => "DataCite admin", + "ROLE_FOR_PROFIT_PROVIDER" => "For-profit Provider" + } + end + + def member_type + member_types[role_name] + end + + def member_types + { + "ROLE_MEMBER" => "member_only", + "ROLE_ALLOCATOR" => "provider", + "ROLE_CONSORTIUM_LEAD" => "consortium_lead", + "ROLE_CONTRACTUAL_PROVIDER" => "contractual_provider", + "ROLE_FOR_PROFIT_PROVIDER" => "for_profit_provider" + } + end + # count years account has been active. Ignore if deleted the same year as created def cumulative_years if deleted_at && deleted_at.year > created_at.year @@ -322,13 +360,13 @@ def password_input=(value) write_attribute(:password, encrypt_password_sha256(value)) if value.present? end - def member_type - if role_name == "ROLE_ALLOCATOR" - "provider" - elsif role_name == "ROLE_MEMBER" - "member_only" - end - end + # def member_type + # if role_name == "ROLE_ALLOCATOR" + # "provider" + # elsif role_name == "ROLE_MEMBER" + # "member_only" + # end + # end def client_ids clients.where(deleted_at: nil).pluck(:symbol).map(&:downcase) diff --git a/app/serializers/provider_serializer.rb b/app/serializers/provider_serializer.rb index c8740f31f..304856ce8 100644 --- a/app/serializers/provider_serializer.rb +++ b/app/serializers/provider_serializer.rb @@ -5,7 +5,7 @@ class ProviderSerializer set_id :uid # cache_options enabled: true, cache_length: 24.hours ### we cannot filter if we cache - attributes :name, :symbol, :website, :contact_name, :contact_email, :phone, :description, :region, :country, :logo_url, :organization_type, :focus_area, :is_active, :has_password, :joined, :twitter_handle, :billing_information, :ror_id, :general_contact, :technical_contact, :service_contact, :voting_contact, :created, :updated + attributes :name, :symbol, :website, :contact_name, :contact_email, :phone, :description, :region, :country, :logo_url, :organization_type, :focus_area, :is_active, :has_password, :joined, :twitter_handle, :billing_information, :ror_id, :technical_contact,:billing_contact, :secondary_billing_contact, :service_contact, :voting_contact, :created, :updated has_many :clients, record_type: :clients has_many :prefixes, record_type: :prefixes @@ -31,14 +31,18 @@ class ProviderSerializer end # Convert all contacts json models back to json style camelCase - attribute :general_contact do |object| - object.general_contact.present? ? object.general_contact.transform_keys!{ |key| key.to_s.camelcase(:lower) } : {} - end - attribute :technical_contact do |object| object.technical_contact.present? ? object.technical_contact.transform_keys!{ |key| key.to_s.camelcase(:lower) } : {} end + attribute :billing_contact do |object| + object.billing_contact.present? ? object.billing_contact.transform_keys!{ |key| key.to_s.camelcase(:lower) } : {} + end + + attribute :secondary_billing_contact do |object| + object.secondary_billing_contact.present? ? object.secondary_billing_contact.transform_keys!{ |key| key.to_s.camelcase(:lower) } : {} + end + attribute :service_contact do |object| object.service_contact.present? ? object.service_contact.transform_keys!{ |key| key.to_s.camelcase(:lower) } : {} end diff --git a/app/validators/billing_information_validator.rb b/app/validators/billing_information_validator.rb new file mode 100644 index 000000000..ff46ad9ac --- /dev/null +++ b/app/validators/billing_information_validator.rb @@ -0,0 +1,31 @@ +class BillingInformationValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + # Don't try to validate if we have nothing + return unless value.present? + + unless value["city"].present? + record.errors[attribute] << "has no city specified" + end + + unless value["state"].present? + record.errors[attribute] << "has no state/province specified" + end + unless value["country"].present? + record.errors[attribute] << "has no country specified" + end + unless value["department"].present? + record.errors[attribute] << "has no department specified" + end + + unless value["address"].present? + record.errors[attribute] << "has no street address specified" + end + + unless value["postCode"].present? || value["post_code"].present? + record.errors[attribute] << "has no post/zip code specified" + end + unless value["organization"].present? + record.errors[attribute] << "has no organization specified" + end + end +end \ No newline at end of file diff --git a/db/migrate/20190521152430_add_billing_contact.rb b/db/migrate/20190521152430_add_billing_contact.rb new file mode 100644 index 000000000..768ca19a0 --- /dev/null +++ b/db/migrate/20190521152430_add_billing_contact.rb @@ -0,0 +1,11 @@ +class AddBillingContact < ActiveRecord::Migration[5.2] + def up + add_column :allocator, :billing_contact, :json + add_column :allocator, :secondary_billing_contact, :json + end + + def down + remove_column :allocator, :billing_contact + remove_column :allocator, :secondary_billing_contact + end +end diff --git a/db/migrate/20190522162430_remove_general_contact.rb b/db/migrate/20190522162430_remove_general_contact.rb new file mode 100644 index 000000000..97bf2ec25 --- /dev/null +++ b/db/migrate/20190522162430_remove_general_contact.rb @@ -0,0 +1,9 @@ +class RemoveGeneralContact < ActiveRecord::Migration[5.2] + def up + remove_column :allocator, :general_contact + end + + def down + add_column :allocator, :general_contact, :json + end +end diff --git a/db/schema.rb b/db/schema.rb index 0291b06ac..b789ac3d4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,9 +10,9 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_05_17_154500) do +ActiveRecord::Schema.define(version: 2019_05_22_162430) do - create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin", force: :cascade do |t| + create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name", limit: 191, null: false t.string "record_type", null: false t.bigint "record_id", null: false @@ -22,7 +22,7 @@ t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true end - create_table "active_storage_blobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin", force: :cascade do |t| + create_table "active_storage_blobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "key", limit: 191, null: false t.string "filename", limit: 191, null: false t.string "content_type", limit: 191 @@ -33,7 +33,7 @@ t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true end - create_table "allocator", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT", force: :cascade do |t| + create_table "allocator", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.string "contact_email", null: false t.string "contact_name", limit: 80, null: false t.datetime "created" @@ -61,15 +61,16 @@ t.json "billing_information" t.string "twitter_handle", limit: 20 t.string "ror_id" - t.json "general_contact" t.json "technical_contact" t.json "service_contact" t.json "voting_contact" + t.json "billing_contact" + t.json "secondary_billing_contact" t.index ["organization_type"], name: "index_allocator_organization_type" t.index ["symbol"], name: "symbol", unique: true end - create_table "allocator_prefixes", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT", force: :cascade do |t| + create_table "allocator_prefixes", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.bigint "allocator", null: false t.bigint "prefixes", null: false t.datetime "created_at" @@ -79,7 +80,7 @@ t.index ["prefixes"], name: "FKE7FBD674AF86A1C7" end - create_table "audits", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin", force: :cascade do |t| + create_table "audits", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.integer "auditable_id" t.string "auditable_type" t.integer "associated_id" @@ -101,18 +102,7 @@ t.index ["user_id", "user_type"], name: "user_index" end - create_table "contacts", options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| - t.bigint "allocator" - t.string "email" - t.string "given_name" - t.string "family_name" - t.string "role" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["allocator"], name: "fk_rails_5c598567a8" - end - - create_table "datacentre", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT", force: :cascade do |t| + create_table "datacentre", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.text "comments", limit: 4294967295 t.string "contact_email", null: false t.string "contact_name", limit: 80, null: false @@ -140,7 +130,7 @@ t.index ["url"], name: "index_datacentre_on_url", length: 100 end - create_table "datacentre_prefixes", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT", force: :cascade do |t| + create_table "datacentre_prefixes", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.bigint "datacentre", null: false t.bigint "prefixes", null: false t.datetime "created_at" @@ -152,7 +142,7 @@ t.index ["prefixes"], name: "FK13A1B3BAAF86A1C7" end - create_table "dataset", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT", force: :cascade do |t| + create_table "dataset", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.datetime "created" t.string "doi", null: false t.binary "is_active", limit: 1, null: false @@ -207,7 +197,7 @@ t.index ["url"], name: "index_dataset_on_url", length: 100 end - create_table "media", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT", force: :cascade do |t| + create_table "media", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.datetime "created" t.string "media_type", limit: 80 t.datetime "updated" @@ -219,7 +209,7 @@ t.index ["url"], name: "index_media_on_url", length: 100 end - create_table "metadata", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT", force: :cascade do |t| + create_table "metadata", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.datetime "created" t.integer "metadata_version" t.integer "version" @@ -231,7 +221,7 @@ t.index ["dataset"], name: "FKE52D7B2F4D3D6B1B" end - create_table "prefix", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT", force: :cascade do |t| + create_table "prefix", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.datetime "created" t.string "prefix", limit: 80, null: false t.integer "version" @@ -241,7 +231,6 @@ add_foreign_key "allocator_prefixes", "allocator", column: "allocator", name: "FKE7FBD67446EBD781" add_foreign_key "allocator_prefixes", "prefix", column: "prefixes", name: "FKE7FBD674AF86A1C7" - add_foreign_key "contacts", "allocator", column: "allocator" add_foreign_key "datacentre", "allocator", column: "allocator", name: "FK6695D60546EBD781" add_foreign_key "datacentre_prefixes", "datacentre", column: "datacentre", name: "FK13A1B3BA47B5F5FF" add_foreign_key "datacentre_prefixes", "prefix", column: "prefixes", name: "FK13A1B3BAAF86A1C7" diff --git a/spec/factories/default.rb b/spec/factories/default.rb index 478df557a..dceea0e0c 100644 --- a/spec/factories/default.rb +++ b/spec/factories/default.rb @@ -206,24 +206,32 @@ name { "My provider" } country_code { "DE" } password_input { "12345" } - twitter_handle { "megaTwitterlace" } + twitter_handle { "@egaTwitterlac" } ror_id { "https://ror.org/05njkjr15" } billing_information {{ "city": "barcelona", "state": "cataluyna", + "department": "sales", + "country": "CN", + "organization": "testing org", "address": Faker::Address.street_address, "postCode": "10777" }} - general_contact {{ - "email": "richard@example.com", - "given_name": "Richard", - "family_name": "Hallett" - }} technical_contact {{ "email": "kristian@example.com", "given_name": "Kristian", "family_name": "Garza" }} + billing_contact {{ + "email": "Trisha@example.com", + "given_name": "Trisha", + "family_name": "cruse" + }} + secondary_billing_contact {{ + "email": "Trisha@example.com", + "given_name": "Trisha", + "family_name": "cruse" + }} service_contact {{ "email": "martin@example.com", "given_name": "Martin", diff --git a/spec/models/provider_spec.rb b/spec/models/provider_spec.rb index 6caeefd88..399a07944 100644 --- a/spec/models/provider_spec.rb +++ b/spec/models/provider_spec.rb @@ -22,6 +22,16 @@ end end + describe "provider with ROLE_CONTRACTUAL_PROVIDER" do + subject { create(:provider, role_name: "ROLE_CONTRACTUAL_PROVIDER", name: "Contractor", symbol: "CONTRACT_SLASH") } + + it "works" do + expect(subject.role_name).to eq("ROLE_CONTRACTUAL_PROVIDER") + expect(subject.member_type).to eq("contractual_provider") + expect(subject.member_type_label).to eq("Contractual Provider") + end + end + describe "to_jsonapi" do it "works" do params = provider.to_jsonapi diff --git a/spec/requests/providers_spec.rb b/spec/requests/providers_spec.rb index 144e8677d..1497e1ca1 100644 --- a/spec/requests/providers_spec.rb +++ b/spec/requests/providers_spec.rb @@ -23,6 +23,7 @@ end it 'returns providers' do + # puts response.inspect expect(json['data'].size).to eq(4) expect(json.dig('meta', 'total')).to eq(4) end @@ -52,6 +53,24 @@ end end + context 'create provider type ROLE_CONTRACTUAL_PROVIDER and check it works ' do + let(:provider) { create(:provider, role_name: "ROLE_CONTRACTUAL_PROVIDER", name: "Contractor", symbol: "CONTRACT_SLASH") } + + + before do + get "/providers/#{provider.symbol.downcase}", headers: headers + end + + it 'creates a provider' do + expect(json).not_to be_empty + expect(json['data']['id']).to eq(provider.symbol.downcase) + end + + it 'returns status code 201' do + expect(response).to have_http_status(200) + end + end + context 'when the record does not exist' do before { get "/providers/xxx" , headers: headers} @@ -120,6 +139,40 @@ end end + context 'create provider type ROLE_CONTRACTUAL_PROVIDER ' do + let(:params) do + { "data" => { "type" => "providers", + "attributes" => { + "symbol" => "FG", + "name" => "Figshare", + "region" => "EMEA", + "contactEmail" => "doe@joe.joe", + "contactName" => "timAus", + "roleName" => "ROLE_CONTRACTUAL_PROVIDER", + "country" => "GB" } } } + end + + before do + post '/providers', params: params.to_json, headers: headers + end + + it 'creates a provider' do + puts json + expect(json.dig('data', 'attributes', 'contactEmail')).to eq("doe@joe.joe") + expect(json.dig('data', 'attributes', 'name')).to eq("Figshare") + end + + it 'provider model get computed' do + report = Provider.where(symbol: json.dig('data', 'attributes','symbol')).first + expect(report.role_name).to eq("ROLE_CONTRACTUAL_PROVIDER") + expect(report.member_type).to eq("contractual_provider") + expect(report.member_type_label).to eq("Contractual Provider") + end + + it 'returns status code 201' do + expect(response).to have_http_status(200) + end + end context 'request is valid with billing information' do let(:params) do @@ -142,11 +195,15 @@ "organizationType"=>"academicInstitution", "passwordInput"=>"[FILTERED]", "phone"=>"", - "twitterHandle"=>"meekakitty", + "twitterHandle"=>"@meekakitty", "rorId"=>"https://ror.org/05njkjr15", "billingInformation":{ "city"=>"barcelona", "state"=>"Rennes", + "country"=>"Rennes", + "organization"=>"Rennes", + "department"=>"Rennes", + "address"=>"Rennes", "postCode"=>"122dc" }, "region"=>"", @@ -163,11 +220,11 @@ end it 'creates a provider' do - puts json + puts response.inspect expect(json.dig('data', 'attributes', 'contactEmail')).to eq("jkiritha@andrew.cmu.edu") expect(json.dig('data', 'attributes', 'billingInformation',"state")).to eq("Rennes") expect(json.dig('data', 'attributes', 'billingInformation',"postCode")).to eq("122dc") - expect(json.dig('data', 'attributes', 'twitterHandle')).to eq("meekakitty") + expect(json.dig('data', 'attributes', 'twitterHandle')).to eq("@meekakitty") expect(json.dig('data', 'attributes', 'rorId')).to eq("https://ror.org/05njkjr15") end @@ -197,13 +254,8 @@ "organizationType"=>"academicInstitution", "passwordInput"=>"[FILTERED]", "phone"=>"", - "twitterHandle"=>"meekakitty", + "twitterHandle"=>"@eekakitty", "rorId"=>"https://ror.org/05njkjr15", - "generalContact":{ - "email"=>"richard@example.com", - "givenName"=>"Richard", - "familyName"=>"Hallett" - }, "technicalContact": { "email": "kristian@example.com", "givenName": "Kristian", @@ -214,6 +266,16 @@ "givenName": "Martin", "familyName": "Fenner" }, + "billingContact": { + "email": "Trisha@example.com", + "givenName": "Trisha", + "familyName": "cruse" + }, + "secondaryBillingContact": { + "email": "Trisha@example.com", + "givenName": "Trisha", + "familyName": "cruse" + }, "votingContact": { "email": "robin@example.com", "givenName": "Robin", @@ -233,12 +295,15 @@ end it 'creates a provider' do - expect(json.dig('data', 'attributes', 'generalContact',"email")).to eq("richard@example.com") - expect(json.dig('data', 'attributes', 'generalContact',"givenName")).to eq("Richard") - expect(json.dig('data', 'attributes', 'generalContact',"familyName")).to eq("Hallett") expect(json.dig('data', 'attributes', 'technicalContact',"email")).to eq("kristian@example.com") expect(json.dig('data', 'attributes', 'technicalContact',"givenName")).to eq("Kristian") expect(json.dig('data', 'attributes', 'technicalContact',"familyName")).to eq("Garza") + expect(json.dig('data', 'attributes', 'billingContact',"email")).to eq("Trisha@example.com") + expect(json.dig('data', 'attributes', 'billingContact',"givenName")).to eq("Trisha") + expect(json.dig('data', 'attributes', 'billingContact',"familyName")).to eq("cruse") + expect(json.dig('data', 'attributes', 'secondaryBillingContact',"email")).to eq("Trisha@example.com") + expect(json.dig('data', 'attributes', 'secondaryBillingContact',"givenName")).to eq("Trisha") + expect(json.dig('data', 'attributes', 'secondaryBillingContact',"familyName")).to eq("cruse") expect(json.dig('data', 'attributes', 'serviceContact',"email")).to eq("martin@example.com") expect(json.dig('data', 'attributes', 'serviceContact',"givenName")).to eq("Martin") expect(json.dig('data', 'attributes', 'serviceContact',"familyName")).to eq("Fenner")