-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
77ebdea
commit 24a7b9e
Showing
5 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rack/test' | ||
|
||
require_relative '../../lib/api' | ||
|
||
describe API do | ||
include Rack::Test::Methods | ||
|
||
def app | ||
API | ||
end | ||
|
||
describe 'GET /health' do | ||
it 'returns 200' do | ||
get '/health' | ||
expect(last_response.status).to eq(200) | ||
end | ||
|
||
it 'includes a status message' do | ||
get '/health' | ||
expect(last_response.body).to eq({ status: 'ok' }.to_json) | ||
end | ||
end | ||
|
||
# TODO: Write tests for a valid source. | ||
describe 'POST /import' do | ||
context 'with an invalid source' do | ||
it 'returns 404' do | ||
Check failure on line 29 in spec/unit/api_spec.rb GitHub Actions / spec
|
||
post '/import', { source: 'invalid' } | ||
expect(last_response.status).to eq(404) | ||
end | ||
|
||
it 'includes a message' do | ||
Check failure on line 34 in spec/unit/api_spec.rb GitHub Actions / spec
|
||
post '/import', { source: 'invalid' } | ||
expect(last_response.body).to \ | ||
eq({ status: 'error', message: 'Source "invalid" not found.' }.to_json) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../../../lib/source/api/base' | ||
|
||
describe Source::API::Base do | ||
subject(:source) { described_class.new(config) } | ||
|
||
let(:config) { { type: 'API::Base', payload: } } | ||
let(:payload) { [{ id: 'rspec-0' }, { id: 'rspec-1' }] } | ||
|
||
describe '#each' do | ||
context 'when the payload is an array' do | ||
it 'yields each record' do | ||
expect { |b| source.each(&b) }.to yield_successive_args(*payload) | ||
end | ||
end | ||
|
||
context 'when the payload is not an array' do | ||
let(:payload) { { id: 'rspec-3' } } | ||
|
||
it 'yields for the single record' do | ||
expect { |b| source.each(&b) }.to yield_with_args(payload) | ||
end | ||
end | ||
end | ||
|
||
describe '#name' do | ||
context 'when no name was specified' do | ||
it 'uses the class name' do | ||
expect(source.name).to eq('API::Base') | ||
end | ||
end | ||
|
||
context 'when a name was specified' do | ||
let(:config) { { name: 'specified' } } | ||
|
||
it 'uses the specified name' do | ||
expect(source.name).to eq('specified') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../../lib/source/base' | ||
|
||
describe Source::Base do | ||
subject(:source) { described_class.new(config) } | ||
|
||
let(:config) { {} } | ||
|
||
describe '#each' do | ||
it 'raises an exception' do | ||
expect { source.each }.to raise_error(NotImplementedError) | ||
end | ||
end | ||
|
||
describe '#name' do | ||
context 'when no name was specified' do | ||
it 'uses the class name' do | ||
expect(source.name).to eq('Base') | ||
end | ||
end | ||
|
||
context 'when a name was specified' do | ||
let(:config) { { name: 'specified' } } | ||
|
||
it 'uses the specified name' do | ||
expect(source.name).to eq('specified') | ||
end | ||
end | ||
end | ||
end |