-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Api prog and meeting part 2 #194
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
73087ac
updated seed file and amended models and views
sibsmc 0ad8fbd
programming language and meeting interval information now pulled from…
sibsmc aa11e50
removed unneeded comments
sibsmc 9f957a0
made api_user email a unique attribute, updated tests
sibsmc 916cab1
added username field to api_user and made it unique, same with email
sibsmc cefe16f
edited api_user model
sibsmc bb21891
requested changes made
sibsmc 644632c
Merge branch 'master' into api_prog_and_meeting_part_2
sibsmc 2a52b79
Merge branch 'master' into api_prog_and_meeting_part_2
sibsmc ebb6ceb
Merge branch 'master' into api_prog_and_meeting_part_2
sibsmc f4220a2
remove unneeded comments from api_user spec
sibsmc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -4,16 +4,17 @@ | |
|
||
|
||
# initialize test data | ||
let!(:api_users){create_list(:api_user, 10)} | ||
let(:api_user_id) {api_users.first.id} | ||
let!(:api_users){create_list(:api_user, 2)} | ||
let!(:api_user_id) {api_users.first.id} | ||
|
||
|
||
# Test suite for GET /api/v1/api_users | ||
describe 'GET /api/v1/api_users' do | ||
before {get "/api/v1/api_users"} | ||
|
||
it 'returns api_users' do | ||
expect(json).not_to be_empty | ||
expect(json.size).to eq(10) | ||
expect(json.size).to eq(2) | ||
end | ||
|
||
it 'returns status code 200' do | ||
|
@@ -47,33 +48,28 @@ | |
expect(json['message']).to match(/Couldn't find ApiUser with 'id'=#{api_user_id}/) | ||
end | ||
end | ||
|
||
end | ||
|
||
# Test suite POST /api/v1/api_user | ||
describe 'POST /api/v1/api_users' do | ||
let(:valid_attributes) do | ||
# send json payload | ||
{ 'email': '[email protected]', 'password_digest': 'password1', 'username': 'user11'}.to_json | ||
|
||
context 'when request is valid' do | ||
before { post '/api/v1/api_users', params: valid_attributes} | ||
|
||
it 'returns status code 201' do | ||
expect(response).to have_http_status(201) | ||
end | ||
{ email: '[email protected]', password_digest: 'password1', username: 'user11', mentor: true, mentee: true} | ||
end | ||
before { post '/api/v1/api_users', params: valid_attributes, as: :json} | ||
context 'when request is valid' do | ||
it 'returns status code 201' do | ||
expect(response).to have_http_status(201) | ||
end | ||
|
||
it 'returns same params as entered' do | ||
expect(json['email'], json['password_digest']).to eq('[email protected]','password1', 'user11') | ||
end | ||
it 'returns same params as entered' do | ||
expect([json["email"], json["password_digest"], json["username"]]).to eq(["[email protected]", "password1", "user11"]) | ||
end | ||
end | ||
|
||
context 'when the request is invalid as no params' do | ||
let(:invalid_attributes) do | ||
{ email: nil } .to_json | ||
before { post '/api/v1/api_users', params: invalid_attributes } | ||
|
||
context 'when the request is invalid as no params' do | ||
invalid_attributes = { } | ||
before { post '/api/v1/api_users', params: invalid_attributes, as: :json } | ||
it 'returns status code 422' do | ||
expect(response).to have_http_status(422) | ||
end | ||
|
@@ -82,134 +78,113 @@ | |
expect(json['message']) | ||
.to match(/param is missing or the value is empty: api_user/) | ||
end | ||
end | ||
end | ||
|
||
context 'when the request is invalid as email already in use' do | ||
let(:invalid_email) do | ||
{ 'email': '[email protected]', 'password_digest': 'password2', 'username': 'user12' } .to_json | ||
before { post '/api/v1/api_users', params: invalid_email } | ||
let(:invalid_email) do | ||
{ 'email': '[email protected]', 'password_digest': 'password2', 'username': 'user12', mentor: true, mentee: true } | ||
end | ||
before { post '/api/v1/api_users', params: invalid_email, as: :json } | ||
|
||
it 'returns status code 422' do | ||
expect(response).to have_http_status(422) | ||
expect(response).to have_http_status(422) | ||
end | ||
|
||
it 'returns a validation failure message' do | ||
expect(json['message']) | ||
.to match(/Validation failed: Email has already been taken/) | ||
end | ||
end | ||
end | ||
|
||
context 'when the request is invalid as username already in use' do | ||
let(:invalid_username) do | ||
{ 'email': '[email protected]', 'password_digest': 'password2', 'username': 'user11' } .to_json | ||
before { post '/api/v1/api_users', params: invalid_username } | ||
let(:invalid_username) do | ||
{ 'email': '[email protected]', 'password_digest': 'password2', 'username': 'user11' , mentor: true, mentee: true} | ||
end | ||
before { post '/api/v1/api_users', params: invalid_username, as: :json } | ||
|
||
it 'returns status code 422' do | ||
expect(response).to have_http_status(422) | ||
end | ||
it 'returns status code 422' do | ||
expect(response).to have_http_status(422) | ||
end | ||
|
||
it 'returns a validation failure message' do | ||
expect(json['message']) | ||
.to match(/Validation failed: Username has already been taken/) | ||
end | ||
it 'returns a validation failure message' do | ||
expect(json['message']) | ||
.to match(/Validation failed: Username has already been taken/) | ||
end | ||
end | ||
|
||
context 'when the request is invalid as only some requird params' do | ||
let(:invalid_attributes) { { 'api_user': { 'email': '[email protected]' } }.to_json } | ||
before { post '/api/v1/api_users', params: invalid_attributes } | ||
let(:some_invalid_attributes) {{ 'email': '[email protected]' }} | ||
before { post '/api/v1/api_users', params: some_invalid_attributes, as: :json } | ||
|
||
it 'returns status code 422' do | ||
expect(response).to have_http_status(422) | ||
end | ||
it 'returns a validation failure message' do | ||
expect(json['message']) | ||
.to match(/param is missing or the value is empty: api_user/) | ||
.to match(/Validation failed: Password digest can't be blank, Username can't be blank, Mentor can't be blank, Mentee can't be blank/) | ||
end | ||
end | ||
|
||
end | ||
|
||
# Test suite for Patch /api/v1/api_userss/:id | ||
describe 'PATCH /api/v1/api_users/:id' do | ||
let(:valid_attributes) do | ||
# send json payload | ||
{ 'first_name': 'Bobby','last_name': 'Dylan', 'city': 'Mexico', 'email': '[email protected]', 'password_digest': 'password1', 'mentor': True, 'mentee': False}.to_json | ||
let(:api_user_id) {api_users.first.id} | ||
|
||
context 'when request is valid' do | ||
before { patch "/api/v1/api_users/#{api_user_id}/", params: valid_attributes} | ||
let!(:api_user_id) {api_users.first.id} | ||
let(:valid_attributes) do | ||
{ first_name: 'Bobby',last_name: 'Dylan', city: 'Mexico', email: '[email protected]', username: 'user13', password_digest: 'password1' } | ||
end | ||
|
||
it 'returns status code 204' do | ||
expect(response).to have_http_status(204) | ||
end | ||
end | ||
|
||
context 'check that parameters have updated correctly' do | ||
before { get "/api/v1/api_users/#{api_user_id}/", params: valid_attributes} | ||
end | ||
|
||
it 'returns same params as entered' do | ||
expect(json['first_name'],json['last_name'],json['city'], json['email'], json['password_digest'],json['mentor'],json['mentee']).to eq('Bobby', 'Dylan','Mexico', '[email protected]','password1', True, False) | ||
end | ||
end | ||
|
||
|
||
|
||
context 'when email already in use' do | ||
let(:api_user_id) {api_users.first.id} | ||
let(:invalid_email_update) do | ||
# send json payload | ||
{ 'email': '[email protected]'}.to_json | ||
before { patch "/api/v1/api_users/#{api_user_id}/", params: invalid_email_updates} | ||
|
||
it 'returns status code 422' do | ||
expect(response).to have_http_status(422) | ||
end | ||
|
||
it 'returns message informing no user with that id' do | ||
expect(json['message']).to match(/Validation failed: Email has already been taken/) | ||
end | ||
end | ||
end | ||
|
||
context 'when username already in use' do | ||
let(:api_user_id) {api_users.first.id} | ||
let(:invalid_username_update) do | ||
# send json payload | ||
{ 'username': 'user11'}.to_json | ||
before { patch "/api/v1/api_users/#{api_user_id}/", params: invalid_username_updates} | ||
|
||
it 'returns status code 422' do | ||
expect(response).to have_http_status(422) | ||
end | ||
|
||
it 'returns message informing no user with that id' do | ||
expect(json['message']).to match(/Validation failed: Username has already been taken/) | ||
end | ||
end | ||
end | ||
|
||
|
||
|
||
context 'when api_user does not exist' do | ||
let(:api_user_id) {0} | ||
let(:valid_attributes) do | ||
# send json payload | ||
{ 'email': '[email protected]', 'password_digest': 'password1'}.to_json | ||
before { patch "/api/v1/api_users/#{api_user_id}/", params: valid_attributes} | ||
|
||
it 'returns status code 404' do | ||
expect(response).to have_http_status(404) | ||
end | ||
|
||
it 'returns message informing no user with that id' do | ||
expect(json['message']).to match(/Couldn't find ApiUser with 'id'=#{api_user_id}/) | ||
end | ||
end | ||
end | ||
|
||
before { patch "/api/v1/api_users/#{api_user_id}/", params: valid_attributes, as: :json} | ||
it 'returns status code 204' do | ||
expect(response).to have_http_status(204) | ||
end | ||
|
||
context 'check update worked' do | ||
before { get "/api/v1/api_users/#{api_user_id}/"} | ||
it 'returns same params as entered' do | ||
|
||
expect([json["first_name"], json["last_name"], json["city"], json["email"], json["password_digest"], json["username"]]).to eq(['Bobby', 'Dylan','Mexico', '[email protected]','password1','user13']) | ||
end | ||
end | ||
|
||
# context 'when email already in use' do | ||
# let(:api_users.first | ||
|
||
context 'invalid email' do | ||
before { patch "/api/v1/api_users/#{api_user_id}/", params: {email: api_users.second.email} , as: :json} | ||
|
||
it 'returns status code 422' do | ||
expect(response).to have_http_status(422) | ||
end | ||
|
||
it 'returns message informing no user with that id' do | ||
expect(json["message"]).to match(/Validation failed: Email has already been taken/) | ||
end | ||
end | ||
|
||
context 'when username already in use' do | ||
before { patch "/api/v1/api_users/#{api_user_id}/", params: {username: api_users.second.username}, as: :json} | ||
|
||
it 'returns status code 422' do | ||
expect(response).to have_http_status(422) | ||
end | ||
|
||
it 'returns message informing no user with that id' do | ||
expect(json["message"]).to match(/Validation failed: Username has already been taken/) | ||
end | ||
end | ||
|
||
context 'when api_user does not exist' do | ||
let(:api_user_id) {0} | ||
before { patch "/api/v1/api_users/#{api_user_id}/", params: valid_attributes, as: :json} | ||
it 'returns status code 404' do | ||
expect(response).to have_http_status(404) | ||
end | ||
|
||
it 'returns message informing no user with that id' do | ||
expect(json['message']).to match(/Couldn't find ApiUser with 'id'=#{api_user_id}/) | ||
end | ||
end | ||
end | ||
|
||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to leave these here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These have been removed