Skip to content

Commit

Permalink
API v1 specs for user, config and navigation endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
wvengen committed Feb 5, 2019
1 parent d6a9c82 commit 3427cd0
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 2 deletions.
86 changes: 86 additions & 0 deletions doc/swagger.v1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,94 @@ produces:
- 'application/json'

paths:
/user:
get:
summary: info about the currently logged-in user
tags:
- 1. User
responses:
200:
description: success
schema:
type: object
properties:
user:
$ref: '#/definitions/User'
401:
description: not logged-in
schema:
$ref: '#/definitions/Error401'
security:
- foodsoft_auth: ['all']
/config:
get:
summary: configuration variables
tags:
- 7. General
responses:
200:
description: success
schema:
type: object
401:
description: not logged-in
schema:
$ref: '#/definitions/Error401'
security:
- foodsoft_auth: ['all']
/navigation:
get:
summary: navigation
tags:
- 7. General
responses:
200:
description: success
schema:
type: object
properties:
navigation:
$ref: '#/definitions/Navigation'
401:
description: not logged-in
schema:
$ref: '#/definitions/Error401'
security:
- foodsoft_auth: ['all']

definitions:
# models
User:
type: object
properties:
id:
type: integer
name:
type: string
description: full name
email:
type: string
description: email address
locale:
type: string
description: language code
required: ['id', 'name', 'email']
Navigation:
type: array
items:
type: object
properties:
name:
type: string
description: title
url:
type: string
description: link
items:
$ref: '#/definitions/Navigation'
required: ['name']
minProperties: 2 # name+url or name+items

Error:
type: object
properties:
Expand Down
34 changes: 32 additions & 2 deletions spec/api/v1/swagger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,37 @@ def fetch_swagger!

subject { SwaggerCheckerFile.instance_for Rails.root.join('doc', 'swagger.v1.yml') }

it 'tests all documented routes' do
is_expected.to validate_all_paths
context 'has valid paths' do
context 'user' do
# create multiple users to make sure we're getting the authenticated user, not just any
let!(:other_user_1) { create :user }
let!(:user) { create :user }
let!(:other_user_2) { create :user }

it { is_expected.to validate(:get, '/user', 200, auth) }
it { is_expected.to validate(:get, '/user', 401) }

context 'with invalid access token' do
let(:access_token) { 'abc' }
it { is_expected.to validate(:get, '/user', 401, auth) }
end
end

context 'config' do
it { is_expected.to validate(:get, '/config', 200, auth) }
it { is_expected.to validate(:get, '/config', 401) }
end

context 'navigation' do
it { is_expected.to validate(:get, '/navigation', 200, auth) }
it { is_expected.to validate(:get, '/navigation', 401) }
end
end

# needs to be last context so it is always run at the end
context 'and finally' do
it 'tests all documented routes' do
is_expected.to validate_all_paths
end
end
end
6 changes: 6 additions & 0 deletions spec/factories/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
create :workgroup, role_admin: true, user_ids: [user.id]
end
end

trait :ordergroup do
after :create do |user, evaluator|
create :ordergroup, user_ids: [user.id]
end
end
end

factory :group do
Expand Down

0 comments on commit 3427cd0

Please sign in to comment.