Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: CI

on:
pull_request:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ["3.4", "4.0"]
steps:
- uses: actions/checkout@v6

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true

- name: Run tests
run: bundle exec rake test
env:
API_URL: http://localhost:8888

rubocop:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.4"
bundler-cache: true

- name: Run Rubocop
run: bundle exec rubocop

typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.4"
bundler-cache: true

- name: Install RBS collections
run: bundle exec rbs collection install

- name: Run type checker
run: bundle exec steep check --severity-level=error
20 changes: 0 additions & 20 deletions .github/workflows/rubocop.yml

This file was deleted.

20 changes: 0 additions & 20 deletions .github/workflows/typecheck.yml

This file was deleted.

25 changes: 0 additions & 25 deletions .github/workflows/unit-tests.yml

This file was deleted.

5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
plugins:
- rubocop-minitest
- rubocop-rake

AllCops:
TargetRubyVersion: 3.4
Exclude:
- config/unicorn.rb
- db/**
- vendor/**/*
NewCops: enable

Layout/LineLength:
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ group :development, :test do
gem 'ostruct'
gem 'rake'
gem 'rubocop'
gem 'rubocop-minitest', require: false
gem 'rubocop-rake', require: false
gem 'simplecov', require: false
gem 'steep', require: false
gem 'vcr'
Expand Down
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ GEM
rubocop-ast (1.48.0)
parser (>= 3.3.7.2)
prism (~> 1.4)
rubocop-minitest (0.40.0)
lint_roller (~> 1.1)
rubocop (>= 1.75.0, < 2.0)
rubocop-ast (>= 1.38.0, < 2.0)
rubocop-rake (0.7.1)
lint_roller (~> 1.1)
rubocop (>= 1.72.1)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
securerandom (0.4.1)
Expand Down Expand Up @@ -145,6 +152,8 @@ DEPENDENCIES
ostruct
rake
rubocop
rubocop-minitest
rubocop-rake
simplecov
steep
vcr
Expand Down
4 changes: 4 additions & 0 deletions test/data_services_api/dsapi_response_converter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@
it 'should convert some SAPINT json to DSAPI format' do
actual_response = ppd_resp_conv.send(:to_dsapi_json, 'newBuild', ppd_sapint_items[0]['newBuild'])
expected_response = { 'ppd:newBuild' => ppd_dsapi_items[0]['ppd:newBuild'] }

_(actual_response).must_equal expected_response
end

it 'should convert SAPINT hash to DSAPI format' do
actual_response = ppd_resp_conv.send(:to_dsapi_json, 'propertyAddress', 'county' => 'SOMERSET')
expected_response = { 'ppd:propertyAddressCounty' => 'SOMERSET' }

_(actual_response).must_equal expected_response
end
end
Expand Down Expand Up @@ -341,12 +343,14 @@
it 'should convert some SAPINT json to DSAPI format' do
actual_response = ukhpi_resp_conv.send(:to_dsapi_json, 'averagePrice', ukhpi_sapint_items[0]['averagePrice'])
expected_response = { 'ukhpi:averagePrice' => ukhpi_dsapi_items[0]['ukhpi:averagePrice'] }

_(actual_response).must_equal expected_response
end

it 'should convert SAPINT hash to DSAPI format' do
actual_response = ukhpi_resp_conv.send(:to_dsapi_json, 'refRegion', '@id' => 'http://landregistry.data.gov.uk/id/region/redcar-and-cleveland')
expected_response = { 'ukhpi:refRegion' => { '@id' => 'http://landregistry.data.gov.uk/id/region/redcar-and-cleveland' } }

_(actual_response).must_equal expected_response
end
end
Expand Down
17 changes: 17 additions & 0 deletions test/data_services_api/query_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def assert_query(expected, json)
it 'should start with an empty query' do
pattern = {}
query = DataServicesApi::QueryGenerator.new

_(query.to_json).wont_be_nil
assert_query(pattern, query.to_json)
end
Expand All @@ -49,6 +50,7 @@ def assert_query(expected, json)

it 'should allow sorting to specified' do
query = DataServicesApi::QueryGenerator.new

assert_query({ '@sort' => [{ '@up' => 'foo' }] }, query.sort(:up, 'foo').to_json)
assert_query({ '@sort' => [{ '@up' => 'foo' }, { '@down' => 'bar' }] },
query.sort(:up, 'foo').sort(:down, 'bar').to_json)
Expand All @@ -65,6 +67,7 @@ def assert_query(expected, json)

it 'should allow an arbitrary relational operator to be added' do
query = DataServicesApi::QueryGenerator.new

assert_query(conjunction([{ foo: { '@le' => 1000 } }, { foo: { '@ge' => 100 } }]),
query.op(:le, :foo, 1000)
.op('@ge', :foo, 100)
Expand All @@ -80,41 +83,47 @@ def assert_query(expected, json)

it 'should add a value type when required' do
query = DataServicesApi::QueryGenerator.new

assert_query(conjunction(foo: { '@ge' => { '@value' => '2014-01-01', '@type' => 'xsd:date' } }),
query.op(:ge, :foo, Date.parse('2014-01-01'))
.to_json)
end

it 'should allow a text search option to be added' do
query = DataServicesApi::QueryGenerator.new

assert_query(conjunction('@search' => 'foo'),
query.search('foo')
.to_json)
end

it 'should allow a text search against a specific property to be added' do
query = DataServicesApi::QueryGenerator.new

assert_query(conjunction('@search' => { '@value' => 'foo', '@property' => 'foo:bar' }),
query.search_property('foo:bar', 'foo')
.to_json)
end

it 'should allow a text search against a specific aspect to be added' do
query = DataServicesApi::QueryGenerator.new

assert_query(conjunction('foo:aspect' => { '@search' => 'foo' }),
query.search_aspect('foo:aspect', 'foo')
.to_json)
end

it 'should allow a text search against a specific property of an aspect to be added' do
query = DataServicesApi::QueryGenerator.new

assert_query(conjunction('foo:aspect' => { '@search' => { '@value' => 'foo', '@property' => 'foo:bar' } }),
query.search_aspect_property('foo:aspect', 'foo:bar', 'foo')
.to_json)
end

it 'should allow the limit to be set on a search query' do
query = DataServicesApi::QueryGenerator.new

assert_query(conjunction('foo:aspect' => { '@search' => { '@value' => 'foo',
'@property' => 'foo:bar',
'@limit' => 997 } }),
Expand All @@ -129,6 +138,7 @@ def assert_query(expected, json)

it 'should allow a simple boolean expression to be added' do
query = DataServicesApi::QueryGenerator.new

assert_query(conjunction('foo:aspect' => { '@oneof' => [{ '@id' => 'foo:bar' }, { '@id' => 'foo:bam' }] }),
query.eq_any_uri('foo:aspect', %w[foo:bar foo:bam])
.to_json)
Expand All @@ -140,6 +150,7 @@ def assert_query(expected, json)

it 'should allow a type to be specified for a boolean expression value' do
query = DataServicesApi::QueryGenerator.new

assert_query(conjunction('foo:aspect' => { '@oneof' => [{ '@value' => 'foo:bar', '@type' => 'xsd:coconut' },
{ '@value' => 'foo:bam', '@type' => 'xsd:coconut' }] }),
query.eq_any_value('foo:aspect', %w[foo:bar foo:bam], type: 'xsd:coconut')
Expand All @@ -148,6 +159,7 @@ def assert_query(expected, json)

it 'should allow a terms to be composed' do
query = DataServicesApi::QueryGenerator.new

assert_query(conjunction([
{ foo: { '@eq' => 'bar' } },
{ cat: { '@eq' => 'cow' } },
Expand All @@ -159,6 +171,7 @@ def assert_query(expected, json)
.to_json)

query = DataServicesApi::QueryGenerator.new

assert_query(conjunction([
{ 'foo:aspect' => { '@search' => { '@value' => 'foo', '@property' => 'foo:bar' } } },
{ 'foo:aspect' => { '@search' => { '@value' => 'fim', '@property' => 'foo:blom' } } }
Expand All @@ -170,18 +183,21 @@ def assert_query(expected, json)

it 'should allow a regex match to be specified' do
query = DataServicesApi::QueryGenerator.new

assert_query(conjunction('foo:aspect' => { '@matches' => 'bing.*' }),
query.matches('foo:aspect', 'bing.*')
.to_json)

query = DataServicesApi::QueryGenerator.new

assert_query(conjunction('foo:aspect' => { '@matches' => ['bing.*', 'i'] }),
query.matches('foo:aspect', 'bing.*', flags: 'i')
.to_json)
end

it 'should allow an overall query limit to be set' do
query = DataServicesApi::QueryGenerator.new

assert_query({ '@limit' => 101, '@offset' => 20 },
query.limit(101)
.offset(20)
Expand All @@ -190,6 +206,7 @@ def assert_query(expected, json)

it 'should allow a query to be run in count mode' do
query = DataServicesApi::QueryGenerator.new

assert_query({ '@count' => true }, query.count_only.to_json)
end

Expand Down
1 change: 1 addition & 0 deletions test/data_services_api/sapint_converter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@

it 'should convert DSAPI and to SAPINT format' do
and_json = JSON.parse(dsapi_query)['@and']

_(sapi_conv.send(:and_list, and_json)).must_equal(
sapint_query.map do |key, value|
[key, value] unless %w[_count _limit].include?(key)
Expand Down
Loading