diff --git a/config/schema/api.json b/config/schema/api.json index f7c29f6..8086346 100644 --- a/config/schema/api.json +++ b/config/schema/api.json @@ -632,9 +632,9 @@ "description": "unique identifier of user", "readOnly": true, "type": [ - "integer" + "string" ], - "example": 1294 + "example": "1294" }, "first_name": { "description": "first name of user", @@ -827,9 +827,6 @@ }, "country": { "$ref": "#/definitions/user/definitions/country" - }, - "password": { - "$ref": "#/definitions/user/definitions/password" } } } @@ -953,9 +950,6 @@ }, "country": { "$ref": "#/definitions/user/definitions/country" - }, - "password": { - "$ref": "#/definitions/user/definitions/password" } } } diff --git a/config/schema/api.md b/config/schema/api.md index 18d0505..bec0802 100644 --- a/config/schema/api.md +++ b/config/schema/api.md @@ -490,7 +490,7 @@ The User resource for the API | **country** | *string* | country of user | `"USA"` | | **created_at** | *date-time* | when user was created | `"2015-01-01T12:00:00Z"` | | **first_name** | *string* | first name of user | `"Nate"` | -| **id** | *integer* | unique identifier of user | `1294` | +| **id** | *string* | unique identifier of user | `"1294"` | | **last_name** | *string* | last name of user | `"Pauzenga"` | | **state** | *string* | state of user | `"Maryland"` | | **updated_at** | *date-time* | when user was updated | `"2015-01-01T12:00:00Z"` | @@ -511,7 +511,7 @@ POST /users | **country** | *string* | country of user | `"USA"` | | **email** | *string* | unique email of user | `"test@admin.com"` | | **first_name** | *string* | first name of user | `"Nate"` | -| **id** | *integer* | unique identifier of user | `1294` | +| **id** | *string* | unique identifier of user | `"1294"` | | **last_name** | *string* | last name of user | `"Pauzenga"` | | **password** | *string* | password of user | `"helloworld"` | | **state** | *string* | state of user | `"Maryland"` | @@ -523,7 +523,7 @@ POST /users ```bash $ curl -n -X POST http://localhost:3000/users \ -d '{ - "id": 1294, + "id": "1294", "first_name": "Nate", "last_name": "Pauzenga", "email": "test@admin.com", @@ -575,7 +575,7 @@ HTTP/1.1 200 OK ```json { "created_at": "2015-01-01T12:00:00Z", - "id": 1294, + "id": "1294", "first_name": "Nate", "updated_at": "2015-01-01T12:00:00Z", "last_name": "Pauzenga", @@ -610,14 +610,13 @@ HTTP/1.1 200 OK ```json { - "id": 1294, + "id": "1294", "first_name": "Nate", "last_name": "Pauzenga", "email": "test@admin.com", "city": "Annapolis", "state": "Maryland", - "country": "USA", - "password": "helloworld" + "country": "USA" } ``` @@ -647,7 +646,7 @@ HTTP/1.1 200 OK ```json [ { - "id": 1294, + "id": "1294", "first_name": "Nate", "last_name": "Pauzenga", "email": "test@admin.com", @@ -675,7 +674,7 @@ PATCH /users/{user_id_or_email} | **country** | *string* | country of user | `"USA"` | | **email** | *string* | unique email of user | `"test@admin.com"` | | **first_name** | *string* | first name of user | `"Nate"` | -| **id** | *integer* | unique identifier of user | `1294` | +| **id** | *string* | unique identifier of user | `"1294"` | | **last_name** | *string* | last name of user | `"Pauzenga"` | | **password** | *string* | password of user | `"helloworld"` | | **state** | *string* | state of user | `"Maryland"` | @@ -687,7 +686,7 @@ PATCH /users/{user_id_or_email} ```bash $ curl -n -X PATCH http://localhost:3000/users/$USER_ID_OR_EMAIL \ -d '{ - "id": 1294, + "id": "1294", "first_name": "Nate", "last_name": "Pauzenga", "email": "test@admin.com", @@ -709,14 +708,13 @@ HTTP/1.1 200 OK ```json { - "id": 1294, + "id": "1294", "first_name": "Nate", "last_name": "Pauzenga", "email": "test@admin.com", "city": "Annapolis", "state": "Maryland", - "country": "USA", - "password": "helloworld" + "country": "USA" } ``` diff --git a/config/schema/schemata/user.json b/config/schema/schemata/user.json index 2556444..fb0ea7e 100644 --- a/config/schema/schemata/user.json +++ b/config/schema/schemata/user.json @@ -12,9 +12,9 @@ "description": "unique identifier of user", "readOnly": true, "type": [ - "integer" + "string" ], - "example": 1294 + "example": "1294" }, "first_name": { "description": "first name of user", @@ -148,7 +148,7 @@ "method": "GET", "rel": "self", "http_header": { -"Authorization": "Bearer: iOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE0NTM5MzkwMjYsImF1ZCI6bnVsbCwic3ViIjoxfQ.TSgJie1vAWxR_ym_uazjKs43rpQ50OKmb2KZ2N6ALs4" + "Authorization": "Bearer: iOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE0NTM5MzkwMjYsImF1ZCI6bnVsbCwic3ViIjoxfQ.TSgJie1vAWxR_ym_uazjKs43rpQ50OKmb2KZ2N6ALs4" }, "title": "Info", "targetSchema": { @@ -160,8 +160,7 @@ "email": { "$ref": "/schemata/user#/definitions/email" }, "city": { "$ref": "/schemata/user#/definitions/city" }, "state": { "$ref": "/schemata/user#/definitions/state" }, - "country": { "$ref": "/schemata/user#/definitions/country" }, - "password": { "$ref": "/schemata/user#/definitions/password" } + "country": { "$ref": "/schemata/user#/definitions/country" } } } }, @@ -223,8 +222,7 @@ "email": { "$ref": "/schemata/user#/definitions/email" }, "city": { "$ref": "/schemata/user#/definitions/city" }, "state": { "$ref": "/schemata/user#/definitions/state" }, - "country": { "$ref": "/schemata/user#/definitions/country" }, - "password": { "$ref": "/schemata/user#/definitions/password" } + "country": { "$ref": "/schemata/user#/definitions/country" } } } } diff --git a/spec/acceptance/profiles_spec.rb b/spec/acceptance/profiles_spec.rb index 0d41143..92478c1 100644 --- a/spec/acceptance/profiles_spec.rb +++ b/spec/acceptance/profiles_spec.rb @@ -9,6 +9,10 @@ Knock::AuthToken.new(payload: { sub: authenticated_user.id }).token end + def schema_path + "./config/schema/api.json" + end + shared_context "user parameters" do parameter "first_name", <<-DESC, scope: :user, required: true The first name of the user. diff --git a/spec/acceptance/users_spec.rb b/spec/acceptance/users_spec.rb index 758bcb6..72a387d 100644 --- a/spec/acceptance/users_spec.rb +++ b/spec/acceptance/users_spec.rb @@ -9,6 +9,10 @@ Knock::AuthToken.new(payload: { sub: authenticated_user.id }).token end + def schema_path + "./config/schema/schemata/user.json" + end + shared_context "user parameters" do parameter "first_name", <<-DESC, scope: :user, required: true The first name of the user. @@ -64,9 +68,6 @@ header "Authorization", :auth_token - # Currently update will only update the current user, no matter the id - let(:id) { authenticated_user.id } - example_request "PATCH /user" do expect(status).to eq 200 user = JSON.parse(response_body) diff --git a/spec/controllers/profiles_controller_spec.rb b/spec/controllers/profiles_controller_spec.rb index 8b01fe1..7e79452 100644 --- a/spec/controllers/profiles_controller_spec.rb +++ b/spec/controllers/profiles_controller_spec.rb @@ -1,8 +1,14 @@ +include Committee::Test::Methods + RSpec.describe ProfilesController do + let(:schema_path) { "#{Rails.root}/config/schema/api.json" } + let(:last_response) { response } + let(:last_request) { request } + describe "GET #show" do let(:user) { create(:confirmed_user) } let(:params) { { id: user.id } } - let(:show_profile_input) { { id: params.fetch(:id).to_s } } + let(:show_profile_input) { { id: params.fetch(:id).to_s} } let(:show_profile_context) do Interactor::Context.new(errors: :val, user: user) @@ -32,6 +38,11 @@ get :show, params expect(serialize(user)).to eq(response.body) end + + it "conforms to JSON schema" do + get :show, params + assert_schema_conform + end end context "when ShowProfile fails" do @@ -82,8 +93,14 @@ it "render the profiles as JSON" do get :index - expect(response.body). - to eq([serialize(user), serialize(user2), serialize(user3)]) + expect(json["data"][0].has_value?(user.id.to_s)).to be_truthy + expect(json["data"][1].has_value?(user2.id.to_s)).to be_truthy + expect(json["data"][2].has_value?(user3.id.to_s)).to be_truthy + end + + it "conforms to JSON schema" do + get :index + assert_schema_conform end end