-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from turingschool/jm/create_tags
Feat: user can create new tags
- Loading branch information
Showing
5 changed files
with
95 additions
and
7 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
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 |
---|---|---|
|
@@ -74,6 +74,34 @@ | |
expect(first_tag[:name]).to eq("javascript") | ||
end | ||
|
||
it 'can create a new tag and add it to a link' do | ||
user1 = User.create(email: "[email protected]", password: "user123") | ||
post "/api/v1/users/#{user1.id}/links?link=long-link-example.com" | ||
|
||
post "/api/v1/tags?link=#{Link.last.id}&newTag=new tech topic" | ||
|
||
expect(response).to be_successful | ||
expect(response.status).to eq(200) | ||
|
||
link = JSON.parse(response.body, symbolize_names: true)[:data] | ||
|
||
expect(link).to be_a Hash | ||
expect(link).to have_key :id | ||
expect(link[:type]).to eq("link") | ||
|
||
attrs = link[:attributes] | ||
expect(attrs[:original]).to eq("long-link-example.com") | ||
expect(attrs[:short]).to be_a String | ||
expect(attrs[:user_id]).to eq(user1.id) | ||
|
||
tags = attrs[:tags] | ||
expect(tags).to be_a Array | ||
first_tag = tags[0] | ||
expect(first_tag).to be_a Hash | ||
expect(first_tag).to have_key :id | ||
expect(first_tag[:name]).to eq("new tech topic") | ||
end | ||
|
||
describe "sad path" do | ||
it "returns 404 when link or tag isn't passed or doesn't exist" do | ||
user1 = User.create(email: "[email protected]", password: "user123") | ||
|