combination_steps.rb revision 9205ceba0d0307830e78b9a414e1ff1bc06ac2ef
5836ee88700245635cd096f27bdc6279178f4583Tim ReddehaseGiven(/^that I have a valid API\-Key$/) do
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase @api_key = FactoryGirl.create :api_key
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase @user = @api_key.user
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehaseend
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase
5836ee88700245635cd096f27bdc6279178f4583Tim ReddehaseGiven(/^that I have an invalid API\-Key$/) do
97758b9192048e1cfcd47106cfba6852b1486eddTim Reddehase @api_key = FactoryGirl.create :api_key, :invalid
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase @user = @api_key.user
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehaseend
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase
5836ee88700245635cd096f27bdc6279178f4583Tim ReddehaseGiven(/^I have a repository with path: "([^"]+)"$/) do |path|
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase permission =
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase if @user
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase FactoryGirl.create :permission, subject: @user
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase else
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase FactoryGirl.create :permission
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase end
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase @repository = permission.item
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase @repository.path = path
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase @repository.save!
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehaseend
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase
5836ee88700245635cd096f27bdc6279178f4583Tim ReddehaseGiven(/^I know of a repository with path: "([^"]+)"$/) do |path|
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase @repository = FactoryGirl.create :repository, path: path
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehaseend
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase
5836ee88700245635cd096f27bdc6279178f4583Tim ReddehaseGiven(/^I have (\d+) ontologies$/) do |number|
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase @ontologies = (1..number.to_i).to_a.
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase map { FactoryGirl.create :ontology }
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehaseend
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase
5836ee88700245635cd096f27bdc6279178f4583Tim ReddehaseWhen(/^I create a combination via the API of these ontologies$/) do
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase header 'Accept', 'application/json'
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase header 'Content-Type', 'application/json'
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase header Api::V1::Base::API_KEY_HEADER, @api_key.try(:key)
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase request "/#{@repository.path}///combinations",\
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase method: :post,
9205ceba0d0307830e78b9a414e1ff1bc06ac2efTim Reddehase input: {
9205ceba0d0307830e78b9a414e1ff1bc06ac2efTim Reddehase nodes: @ontologies.map { |o| locid_for(o) }
9205ceba0d0307830e78b9a414e1ff1bc06ac2efTim Reddehase }.to_json
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehaseend
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase
34bd7b34347e21e8c06cf28bafea5f390830d4caTim ReddehaseWhen(/^I create a combination via the API with these:$/) do |table|
34bd7b34347e21e8c06cf28bafea5f390830d4caTim Reddehase header 'Accept', 'application/json'
34bd7b34347e21e8c06cf28bafea5f390830d4caTim Reddehase header 'Content-Type', 'application/json'
34bd7b34347e21e8c06cf28bafea5f390830d4caTim Reddehase header Api::V1::Base::API_KEY_HEADER, @api_key.try(:key)
34bd7b34347e21e8c06cf28bafea5f390830d4caTim Reddehase request "/#{@repository.path}///combinations",\
34bd7b34347e21e8c06cf28bafea5f390830d4caTim Reddehase method: :post,
34bd7b34347e21e8c06cf28bafea5f390830d4caTim Reddehase input: table.hashes.first.to_json
34bd7b34347e21e8c06cf28bafea5f390830d4caTim Reddehaseend
34bd7b34347e21e8c06cf28bafea5f390830d4caTim Reddehase
5836ee88700245635cd096f27bdc6279178f4583Tim ReddehaseThen(/^I should get a (\d+) response$/) do |number|
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase expect(last_response.status).to eq(number.to_i)
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehaseend
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase
5836ee88700245635cd096f27bdc6279178f4583Tim ReddehaseThen(/^a location\-header to the combination\-ontology$/) do
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehase expect(last_response.headers["Location"]).to eq(Ontology.last.locid)
5836ee88700245635cd096f27bdc6279178f4583Tim Reddehaseend
34bd7b34347e21e8c06cf28bafea5f390830d4caTim Reddehase
34bd7b34347e21e8c06cf28bafea5f390830d4caTim ReddehaseThen(/^the body should be valid for a (\d+) combination-response/) do |status|
34bd7b34347e21e8c06cf28bafea5f390830d4caTim Reddehase schema = schema_for("repository/combinations/POST/response/#{status}")
34bd7b34347e21e8c06cf28bafea5f390830d4caTim Reddehase VCR.use_cassette "api/json-schemata/repository/combinations/#{status}" do
34bd7b34347e21e8c06cf28bafea5f390830d4caTim Reddehase expect(last_response.body).to match_json_schema(schema)
34bd7b34347e21e8c06cf28bafea5f390830d4caTim Reddehase end
34bd7b34347e21e8c06cf28bafea5f390830d4caTim Reddehaseend