Skip to content

Commit

Permalink
Make test fixes for the NRTM json generation and update docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
plural committed Dec 27, 2021
1 parent 0bfcb91 commit 63b4685
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 15 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ docker-compose run app bundle exec rake assets:precompile
docker-compose up -d
```

To run tests in your docker container, you will need to override the environment, like so:
```
docker-compose exec -e RAILS_ENV=test app rspec
```

## Requirements
To deploy Cobra, you only need Docker Compose and a way of getting the repository onto your server (such as git).

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/tournaments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def destroy
def upload_to_abr
authorize @tournament

response = AbrUpload.upload!(@tournament)
response = AbrUpload.upload!(@tournament, tournament_url(@tournament.slug, @request))

if(response[:code])
@tournament.update(abr_code: response[:code])
Expand Down
15 changes: 8 additions & 7 deletions app/services/abr_upload.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
class AbrUpload
attr_reader :tournament

def initialize(tournament)
def initialize(tournament, tournament_url)
@tournament = tournament
@tournament_url = tournament_url
end

def upload!
JSON.parse(send_data).with_indifferent_access
end

def self.upload!(tournament)
new(tournament).upload!
def self.upload!(tournament, tournament_url)
new(tournament, tournament_url).upload!
end

private

def send_data
def send_data()
Faraday.new do |conn|
conn.request :multipart
conn.adapter :net_http
conn.request :basic_auth, 'cobra', Rails.application.secrets.abr_auth
end.post endpoint do |req|
upload = Faraday::UploadIO.new(StringIO.new(json), 'text/json')
upload = Faraday::UploadIO.new(StringIO.new(json(@tournament, @tournament_url)), 'text/json')
req.body = { jsonresults: upload }
end.body
end
Expand All @@ -30,7 +31,7 @@ def endpoint
"#{Rails.configuration.abr_host}/api/nrtm"
end

def json
NrtmJson.new(tournament).data.to_json
def json(tournament, tournament_url)
NrtmJson.new(@tournament).data(@tournament_url).to_json
end
end
2 changes: 1 addition & 1 deletion spec/fixtures/files/nrtm_json_cut.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,6 @@
"uploadedFrom": "Cobra",
"links": [
{ "rel": "schemaderivedfrom", "href": "http://steffens.org/nrtm/nrtm-schema.json" },
{ "rel": "uploadedfrom", "href": "http://cobr.ai/SLUG" }
{ "rel": "uploadedfrom", "href": "https://server/SLUG" }
]
}
2 changes: 1 addition & 1 deletion spec/fixtures/files/nrtm_json_swiss.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@
"uploadedFrom": "Cobra",
"links": [
{ "rel": "schemaderivedfrom", "href": "http://steffens.org/nrtm/nrtm-schema.json" },
{ "rel": "uploadedfrom", "href": "http://cobr.ai/SLUG" }
{ "rel": "uploadedfrom", "href": "https://server/SLUG" }
]
}
6 changes: 3 additions & 3 deletions spec/services/abr_upload_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RSpec.describe AbrUpload do
let(:upload) { described_class.new(tournament) }
let(:upload) { described_class.new(tournament, 'https://server/SLUG') }
let(:tournament) { create(:tournament, name: 'Some Tournament') }
let(:jack) { create(:player, corp_identity: 'ETF', runner_identity: 'Noise') }
let(:jill) { create(:player, corp_identity: 'PE', runner_identity: 'Gabe') }
Expand All @@ -11,12 +11,12 @@

describe '.upload!' do
before do
allow(described_class).to receive(:new).with(tournament).and_return(upload)
allow(described_class).to receive(:new).with(tournament, 'https://server/SLUG').and_return(upload)
allow(upload).to receive(:upload!)
end

it 'calls new instance' do
described_class.upload!(tournament)
described_class.upload!(tournament, 'https://server/SLUG')

expect(upload).to have_received(:upload!)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/services/nrtm_json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
end

it 'returns hash of data' do
expect(json.data.with_indifferent_access).to eq(
expect(json.data('https://server/SLUG').with_indifferent_access).to eq(
JSON.parse(file_fixture('nrtm_json_swiss.json').read)
)
end
Expand All @@ -68,7 +68,7 @@
end

it 'returns hash of data' do
expect(JSON.parse(json.data.to_json)).to eq(
expect(JSON.parse(json.data('https://server/SLUG').to_json)).to eq(
JSON.parse(file_fixture('nrtm_json_cut.json').read)
)
end
Expand Down

0 comments on commit 63b4685

Please sign in to comment.