diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 443fa48..637c3c9 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -18,6 +18,7 @@ def show # POST /members def create result = MemberManager::Registrate.call(member_params, opt_params) + if result.success? render json: result.member, include: [:teams, :roles], status: :created, location: result.member @@ -63,7 +64,7 @@ def member_params end def opt_params - params.permit(:hard_delete, roles: [:id, :leave_role]) + params.permit(:hard_delete, join_roles: [], leave_roles: []) end end diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb index 4efa304..cd0d0e3 100644 --- a/app/controllers/teams_controller.rb +++ b/app/controllers/teams_controller.rb @@ -1,6 +1,8 @@ class TeamsController < ApplicationController before_action :set_team, only: [:show, :update, :destroy] + include TeamManager + # GET /teams def index @teams = Team.all @@ -15,12 +17,12 @@ def show # POST /teams def create - @team = Team.new(team_params) + result = TeamManager::Registrate.call(team_params, roles_params) - if @team.save - render json: @team, status: :created, location: @team + if result.success? + render json: result.team, status: :created, location: result.team else - render json: @team.errors, status: :unprocessable_entity + render json: result.errors, status: :unprocessable_entity end end @@ -52,4 +54,13 @@ def set_team def team_params params.require(:team).permit(:name, :initials) end + + def roles_params + roles = params.fetch(roles, []) + roles_params = [] + roles.each do |r| + roles_params += r.permit(:name, :leader) + end + roles_params + end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 764b0e7..14fad72 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,6 +1,6 @@ class UsersController < ApplicationController before_action :set_user, only: [:show, :update, :destroy] - before_action :authenticate_user, only: [:update, :destroy] + before_action :authenticate_user, only: [:create, :update, :destroy] include UserManager @@ -16,8 +16,11 @@ def show # POST /users def create - result = UserManager::Registrate.call(user_params, member_params) - + if @current_user.is_admin? + result = UserManager::Registrate.call(user_params, member_params) + else + result = false + end if result.success? render json: result.user, include: [:member], status: :created, location: result.user else @@ -57,8 +60,8 @@ def user_params def member_params member_params = { - member: params.fetch(:member, {}).permit(:name, :deleted_at), - options: params.permit(:role_id, :leave_role, :hard_delete) + member: params.fetch(:member, {}).permit(:name), + options: params.permit(:hard_delete, join_roles: [], leave_roles: []) } member_params ? member_params : nil diff --git a/app/models/member.rb b/app/models/member.rb index 61eb690..4eb8a2c 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -12,6 +12,10 @@ def join_role(role_id) MemberRole.find_or_create_by!({member_id: self.id, role_id: role_id}) end + def join_roles(role_ids) + join_role(role_ids) + end + def leave_role(role_id) relation = MemberRole.where({member_id: self.id, role_id: role_id}) relation = relation.first @@ -20,4 +24,10 @@ def leave_role(role_id) end end + def leave_roles(role_ids) + leave_role(role_ids) + end + + + end diff --git a/app/models/role.rb b/app/models/role.rb index 2f5af93..ee2e69e 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -1,12 +1,14 @@ class Role < ApplicationRecord - has_many :member_roles + has_many :member_roles, dependent: :destroy has_many :members, through: :member_roles - has_many :children, class_name: 'Role', foreign_key: 'parent_id' belongs_to :team - belongs_to :parent, class_name: 'Role', optional: true + + # Adicionar flag que identifica se o cargo é de um 'leader' + # Dica: Criar migration para adicionar atributo 'leader' do tipo 'boolean' include SoftDeletable validates :name, presence: true validates :team, presence: true + end diff --git a/app/models/team.rb b/app/models/team.rb index 2c33e06..048dd94 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -1,9 +1,22 @@ class Team < ApplicationRecord has_many :members, through: :roles has_many :roles, dependent: :destroy + + belongs_to :parent, class_name: 'Team', optional: true + has_many :children, class_name: 'Team', foreign_key: 'parent_id' include SoftDeletable validates :name, uniqueness: true, presence: true + # Validar se apenas um cargo (ou nenhum) tem a flag de 'leader' + # Dica: Usar método 'validate' como: + # + # validate :has_a_single_leader + # + # private + # + # def has_a single_leader + # errors.add(:roles, 'Não pode ter mais de um líder') unless # Seu código aqui + # end end diff --git a/app/models/user.rb b/app/models/user.rb index 8cb71e7..15a05a4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,8 +1,7 @@ class User < ApplicationRecord has_secure_password has_one :member - - validates :name, presence: true + validates :email, presence: true, uniqueness: true def is_admin? diff --git a/app/services/member_manager/member_service.rb b/app/services/member_manager/member_service.rb new file mode 100644 index 0000000..38018a1 --- /dev/null +++ b/app/services/member_manager/member_service.rb @@ -0,0 +1,24 @@ +module MemberManager + class MemberService < ApplicationService + + protected + + def check_roles + @options[:join_roles] ||= [] + @options[:leave_roles] ||= [] + + return @member.join_role(@defaults[:role].id) unless @options[:join_roles].any? || @options[:leave_roles].any? + + @options[:join_roles].each do |role_id| + @member.join_roles(role_id) + end + + @options[:leave_roles].each do |role_id| + @member.leave_roles(role_id) + end + + @member.reload + end + + end +end \ No newline at end of file diff --git a/app/services/member_manager/registrate.rb b/app/services/member_manager/registrate.rb index 413de21..73d63fa 100644 --- a/app/services/member_manager/registrate.rb +++ b/app/services/member_manager/registrate.rb @@ -1,5 +1,5 @@ module MemberManager - class Registrate < ApplicationService + class Registrate < MemberService attr_reader :member, :options @@ -14,7 +14,7 @@ def execute return OpenStruct.new( success?: false, member: nil, errors: @member.errors) unless @member.save - check_role + check_roles OpenStruct.new(success?: true, member: @member, errors: nil) end @@ -26,13 +26,5 @@ def set_defaults @defaults[:role] = Role.find_or_create_by({name: 'Visitante', team: @defaults[:team]}) end - def check_role - return @member.join_role(@defaults[:role].id) unless @options[:roles] - - @options[:roles].each do |role| - @member.join_role(role[:id]) - end - end - end end \ No newline at end of file diff --git a/app/services/member_manager/update.rb b/app/services/member_manager/update.rb index bb3113b..8b0c49f 100644 --- a/app/services/member_manager/update.rb +++ b/app/services/member_manager/update.rb @@ -1,6 +1,5 @@ module MemberManager - class Update < ApplicationService - + class Update < MemberService attr_reader :current_user, :member, :member_params def initialize(current_user, member, params = {}, options = {}) @@ -39,15 +38,6 @@ def set_defaults @defaults[:role] = Role.find_or_create_by({name: 'Visitante', team: @defaults[:team]}) end - def check_roles - return @member.join_role(@defaults[:role].id) unless @options[:roles] - - @options[:roles].each do |role| - role[:leave_role] ? @member.leave_role(role[:id]) : @member.join_role(role[:id]) - end - @member.reload - end - # Para atualizar as informações de um membro, o usuário deve ser admin # ou o próprio membro que está sendo editado. def can_update? diff --git a/app/services/team_manager/registrate.rb b/app/services/team_manager/registrate.rb new file mode 100644 index 0000000..f5e9522 --- /dev/null +++ b/app/services/team_manager/registrate.rb @@ -0,0 +1,29 @@ +module TeamManager + class Registrate < ApplicationService + + def initialize(team_params = {}, roles_params = []) + @team = Team.new(team_params) + @roles_params = roles_params + end + + def execute + return OpenStruct.new( success?: false, + team: nil, + errors: @team.errors) unless create_team + OpenStruct.new(success?: true, team: @team, errors: nil) + end + + private + + def create_team + return unless @team.save + unless @roles_params.empty? + @roles_params.each do |role_params| + Role.create(name: role_params[:name], team: @team) + end + @team.reload + end + @team + end + end +end \ No newline at end of file diff --git a/db/migrate/20200722172237_create_teams.rb b/db/migrate/20200722172237_create_teams.rb index d20df68..91fc13e 100644 --- a/db/migrate/20200722172237_create_teams.rb +++ b/db/migrate/20200722172237_create_teams.rb @@ -1,6 +1,7 @@ class CreateTeams < ActiveRecord::Migration[5.2] def change create_table :teams do |t| + t.belongs_to :parent, foreign_key: { to_table: :teams } t.string :name t.string :initials diff --git a/db/migrate/20200722172245_create_roles.rb b/db/migrate/20200722172245_create_roles.rb index b2d6a1a..d596041 100644 --- a/db/migrate/20200722172245_create_roles.rb +++ b/db/migrate/20200722172245_create_roles.rb @@ -1,7 +1,6 @@ class CreateRoles < ActiveRecord::Migration[5.2] def change create_table :roles do |t| - t.belongs_to :parent, foreign_key: { to_table :roles } t.references :team, foreign_key: true t.string :name diff --git a/db/migrate/20210913205929_add_flag_to_roles.rb b/db/migrate/20210913205929_add_flag_to_roles.rb new file mode 100644 index 0000000..70e7d28 --- /dev/null +++ b/db/migrate/20210913205929_add_flag_to_roles.rb @@ -0,0 +1,5 @@ +class AddFlagToRoles < ActiveRecord::Migration[6.1] + def change + add_column :roles, :leader, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index 325b9b4..69b6429 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -2,15 +2,15 @@ # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_08_30_155133) do +ActiveRecord::Schema.define(version: 2021_09_13_205929) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -36,11 +36,14 @@ end create_table "roles", force: :cascade do |t| + t.bigint "parent_id" t.bigint "team_id" t.string "name" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.datetime "deleted_at" + t.boolean "leader" + t.index ["parent_id"], name: "index_roles_on_parent_id" t.index ["team_id"], name: "index_roles_on_team_id" end @@ -64,5 +67,6 @@ add_foreign_key "member_roles", "members" add_foreign_key "member_roles", "roles" add_foreign_key "members", "users" + add_foreign_key "roles", "roles", column: "parent_id" add_foreign_key "roles", "teams" end diff --git a/spec/factories.rb b/spec/factories.rb deleted file mode 100644 index ec320ef..0000000 --- a/spec/factories.rb +++ /dev/null @@ -1,24 +0,0 @@ -FactoryBot.define do - - factory :member do - name { "Neiralay" } - roles { [] } - end - - factory :user do - name { "Neiralay" } - email { "neiralay@gmail.com" } - password { "popao123" } - password_confirmation { "popao123" } - end - - factory :team do - name { "Núcleo de Talentos" } - initials { "NUT" } - end - - factory :role do - name { "Consultor de Talentos"} - team - end -end \ No newline at end of file diff --git a/spec/factories/member.rb b/spec/factories/member.rb new file mode 100644 index 0000000..8430ce7 --- /dev/null +++ b/spec/factories/member.rb @@ -0,0 +1,6 @@ +FactoryBot.define do + factory :member do + name { "Neiralay" } + roles { [] } + end +end \ No newline at end of file diff --git a/spec/factories/role.rb b/spec/factories/role.rb new file mode 100644 index 0000000..75a4917 --- /dev/null +++ b/spec/factories/role.rb @@ -0,0 +1,6 @@ +FactoryBot.define do + factory :role do + name { "Consultor de Talentos"} + team + end +end \ No newline at end of file diff --git a/spec/factories/team.rb b/spec/factories/team.rb new file mode 100644 index 0000000..b641800 --- /dev/null +++ b/spec/factories/team.rb @@ -0,0 +1,6 @@ +FactoryBot.define do + factory :team do + name { "Núcleo de Talentos" } + initials { "NUT" } + end +end \ No newline at end of file diff --git a/spec/factories/user.rb b/spec/factories/user.rb new file mode 100644 index 0000000..fa6bbf7 --- /dev/null +++ b/spec/factories/user.rb @@ -0,0 +1,16 @@ +FactoryBot.define do + factory :user do + name { "Neiralay" } + email { "neiralay@gmail.com" } + password { "popao123" } + password_confirmation { "popao123" } + end + + factory :admin, class: User do + name {"Alice"} + email {"alcebories@cjr.org.br"} + password { "123popao" } + password_confirmation { "123popao" } + admin { true } + end +end \ No newline at end of file diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index d1f2d15..220a836 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -8,10 +8,10 @@ expect(user).to be_valid end - it "is not valid if the name is blank" do - new_user = build(:user, email: "popao@gmail.com", name: nil) - expect(new_user).to_not be_valid - end + # it "is not valid if the name is blank" do + # new_user = build(:user, email: "popao@gmail.com", name: nil) + # expect(new_user).to_not be_valid + # end it "is not valid if the email has already been taken" do new_user = build(:user, name: "Valentin Ferreira Paes") diff --git a/spec/requests/members_spec.rb b/spec/requests/members_spec.rb index cbe5e10..68361b6 100644 --- a/spec/requests/members_spec.rb +++ b/spec/requests/members_spec.rb @@ -1,76 +1,305 @@ require "rails_helper" RSpec.describe "MembersController", :type => :request do + + before(:all) { + @members_path = "/members" + @role = create(:role) + @team = @role.team + } + + after(:all){ + @role.hard_destroy + @team.hard_destroy + } + + # GET /members + describe "#index" do + before(:context) do + get @members_path + end + + describe "response" do + it "returns a JSON" do + expect(response.content_type).to match(/application\/json/) + end + + it "returns HTTP status 200 (OK)" do + expect(response).to have_http_status(:ok) + end + end + end + + # POST /members + describe "#create" do + before(:all){ + @previous_count = Member.count + @headers = { "ACCEPT" => "application/json" } + @new_member = { :name => "Valentin Ferreira Paes" } + } + + context "without a role" do + before(:context) do + post @members_path, :params => { :member => @new_member }, :headers => @headers + @body = JSON.parse(response.body) + end + + after(:context) do + Member.find_by(name: @new_member[:name]).destroy + end + + describe "response" do + it "returns a JSON" do + expect(response.content_type).to match(/application\/json/) + end + + it "returns HTTP status 201 (Created)" do + expect(response).to have_http_status(:created) + end + + it "returns a member with their matching the name given" do + expect(@body['name']).to eq(@new_member[:name]) + end + + it "creates a new member" do + expect(Member.count).to eq(@previous_count + 1) + end + end + end + + context "with a role" do + context "the role is valid" do + before(:context) do + post @members_path, :params => { :member => @new_member, :join_roles => [@role.id] }, :headers => @headers + @body = JSON.parse(response.body) + end - let(:team) { create(:team)} - let(:role) { create(:role) } + after(:context) do + Member.find_by(name: @new_member[:name]).destroy + end + + describe "response" do + it "returns a JSON" do + expect(response.content_type).to match(/application\/json/) + end - let(:team2) { create(:team, name: "Núcleo de Atendimento e Vendas", initials: "NAV")} - let(:role2) {create(:role, name: "Líder de Atendimento e Vendas", team: team2)} - let(:member) { create(:member, name: "Larissa Santana de Freitas Andrade", roles: [role2])} - - it "creates a Member" do - headers = { "ACCEPT" => "application/json" } - new_member = { :name => "Valentin Ferreira Paes" } - post "/members", :params => { :member => new_member }, :headers => headers - body = JSON.parse(response.body) - - expect(response.content_type).to match(/application\/json/) - expect(response).to have_http_status(:created) - expect(body['name']).to eq(new_member[:name]) + it "returns HTTP status 201 (Created)" do + expect(response).to have_http_status(:created) + end + + it "returns a member with their name matching the name given" do + expect(@body['name']).to eq(@new_member[:name]) + end + + it "returns a member with a role matching the role given" do + expect(@body['roles'].last['id']).to eq(@role.id) + end + + it "creates a new Member" do + expect(Member.count).to eq(@previous_count + 1) + end + end + end + + context "the role is not valid" do + end + end end - it "shows all Members information" do - get "/members" + context "existing member actions" do + before(:context) do + @member = create(:member, roles: [@role]) + @member_path = @members_path + "/#{@member.id}" + end - expect(response.content_type).to match(/application\/json/) - expect(response).to have_http_status(:ok) - end + after(:context) do + @member.hard_destroy + end + + # GET /members/:id + describe "#show" do + before(:context) do + get (@member_path) + @body = JSON.parse(response.body) + end + + describe "response" do + it "returns a JSON" do + expect(response.content_type).to match(/application\/json/) + end + + it "returns a HTTP status 200 (OK)" do + expect(response).to have_http_status(:ok) + end + + it "returns a JSON matching the member's attributes" do + expect(@body['name']).to eq(@member.name) + end + end + end + + # PATCH/PUT /members/:id + describe "#update" do + describe "errors" do + context "trying to update without permission" do + # "permission" = Current user is NEITHER an admin OR current member's user + before(:context) do + @new_member = {name: "Natália"} + put @member_path, :params => {member: @new_member} + @body = JSON.parse(response.body) + end - it "shows a Member's information" do - get "/members/#{member.id}" - body = JSON.parse(response.body) + describe "response" do + it "returns a JSON" do + expect(response.content_type).to match(/application\/json/) + end - expect(response.content_type).to match(/application\/json/) - expect(response).to have_http_status(:ok) - expect(body['name']).to eq(member.name) + it "returns a HTTP status 401 (Unauthorized)" do + expect(response).to have_http_status(:unauthorized) + end + + it "returns a member with their name not matching the name given" do + expect(@body['name']).to_not eq(@new_member[:name]) + end + end + end + + context "trying to update without valid params" do + before(:context) do + token = login_admin + @new_member = {name: nil} + put @member_path, :params => {member: @new_member}, :headers => {"Authorization" => token} + @body = JSON.parse(response.body) + end + + describe "response" do + it "returns a JSON" do + expect(response.content_type).to match(/application\/json/) + end + + it "returns a HTTP status 422 (Unprocessable Entity)" do + expect(response).to have_http_status(:unprocessable_entity) + end + + it "returns a member with their name not matching the name given" do + expect(@body['name']).to_not eq(@new_member[:name]) + end + end + end + + context "trying to update a member that it not accessible (soft delete / does not exist)" do + describe "response" do + it "returns a JSON (?)" #verificar o que retorna nesse caso + it "returns a HTTP status 404 (Not Found)" + end + end + end + + context "add a single role" do + before(:context) do + token = login_admin + @new_role = create(:role, team: create(:team, name: "Equipe CGR"), name: "Dev") + put @member_path, :params => {:join_roles => [@new_role.id]}, :headers => {"Authorization" => token} + @body = JSON.parse(response.body) + end + + after(:context) do + team = @new_role.team + @new_role.hard_destroy + team.hard_destroy + end + + describe "response" do + it "returns a JSON" do + expect(response.content_type).to match(/application\/json/) + end + + it "returns a HTTP status 200 (OK)" do + expect(response).to have_http_status(:ok) + end + + it "returns a member with their name matching the given member's name" do + expect(@body['name']).to eq(@member[:name]) + end + + it "returns a member with a role matching the role given" do + expect(@body['roles'].last['id']).to eq(@new_role.id) + end + end + end + + context "remove a single role" do + before(:context) do + token = login_admin + put @member_path, :params => { :leave_roles => [@role.id]}, :headers => {"Authorization" => token} + @body = JSON.parse(response.body) + end + + describe "response" do + it "returns a JSON" do + expect(response.content_type).to match(/application\/json/) + end + + it "returns a HTTP status 200 (OK)" do + expect(response).to have_http_status(:ok) + end + + it "returns a member with their name matching the given member's name'" do + expect(@body['name']).to eq(@member[:name]) + end + + it "returns a member without a role matching the role given" do + expect(@body['roles'].pluck("id")).to_not include(@role.id) + end + end + end + + context "change attributes" do + describe "response" do + it "returns a JSON" + it "returns a HTTP status 200 (OK)" + it "returns a member with their name matching the name given" + end + end + end + + describe "#delete" do + describe "errors" do + context "trying to delete without permission" do + end + + context "trying to soft delete a member that it not accessible (soft delete / does not exist)" do + describe "response" do + it "returns a JSON (?)" #verificar o que retorna nesse caso + it "returns a HTTP status 404 (Not Found)" + end + end + + context "trying to hard delete without beeing logged in as an admin" do + it "returns a JSON (?)" #verificar o que retorna nesse caso + it "returns a HTTP status 401 (Unauthorized)" + end + end + context "soft delete" do + describe "response" do + it "returns a JSON (?)" #verificar o que retorna nesse caso + it "returns a HTTP status 200 (OK)" + it "fills the member's field 'deleted_at'" #verificar se o campo deleted_at não está nulo + end + end + context "hard delete" do + describe "response" do + it "returns a JSON (?)" #verificar o que retorna nesse caso + it "returns a HTTP status 200 (OK)" + it "removes the member from the database" #verificar se o membro foi removido do banco + end + end + end end +end - # it "updates a Member info" do - # headers = { "ACCEPT" => "application/json" } - # put "/members/#{larissa.id}", :params => { :member => {:name => "Larissinha lindinha"} }, :headers => headers - # body = JSON.parse(response.body) - - # expect(response.content_type).to match(/application\/json/) - # expect(response).to have_http_status(:ok) - # expect(body['name']).to eq("Larissinha lindinha") - # end - - # it "makes a Member join a role" do - # headers = { "ACCEPT" => "application/json" } - # new_role = Role.create!({:name => "Consultora de Atendimento e Vendas", :team => bope}) - # put "/members/#{larissa.id}", :params => { :member => {:id => larissa.id}, :role_id => new_role.id}, :headers => headers - # body = JSON.parse(response.body) - - # expect(response.content_type).to match(/application\/json/) - # expect(response).to have_http_status(:ok) - # expect(body['roles'][-1]['name']).to eq(new_role.name) - # end - - # it "makes a Member leave a role" do - # headers = { "ACCEPT" => "application/json" } - # put "/members/#{larissa.id}", :params => { :member => {:id => larissa.id}, :role_id => lider.id, :leave_role => true}, :headers => headers - # body = JSON.parse(response.body) - - # expect(response.content_type).to match(/application\/json/) - # expect(response).to have_http_status(:ok) - # expect(body['roles'][-1]).to eq(nil) - # end - - # it "deletes a Member" do - # headers = { "ACCEPT" => "application/json" } - # delete "/members/#{larissa.id}", :headers => headers - - # expect(response).to have_http_status(:no_content) - # end +def login_admin + post '/authenticate', :params => {email: "admin@admin.com", password: "popao123"} + body = JSON.parse(response.body) + body["auth_token"] end \ No newline at end of file diff --git a/spec/requests/teams_spec.rb b/spec/requests/teams_spec.rb index 0a6015b..a7d0aaa 100644 --- a/spec/requests/teams_spec.rb +++ b/spec/requests/teams_spec.rb @@ -15,6 +15,18 @@ expect(response).to have_http_status(:created) end + it "creates a Team with a role" do + headers = { "ACCEPT" => "application/json" } + team = { :name => "Núcleo de Organização Empresarial", + :initials => "NOE" } + role = { :name => "Assessor de Organização Empresarial"} + post "/teams", :params => { :team => team, :roles => [ role ] }, :headers => headers + + expect(response.content_type).to match(/application\/json/) + expect(response).to have_http_status(:created) + end + + it "shows all Teams information" do get "/teams" diff --git a/support/cgr_api_insomnia_doc.yaml b/support/cgr_api_insomnia_doc.yaml new file mode 100644 index 0000000..58ca48a --- /dev/null +++ b/support/cgr_api_insomnia_doc.yaml @@ -0,0 +1,218 @@ +openapi: 3.0.0 +info: + description: "Esse documento lista e exemplifica as requisições da API do + sistema CGR." + + version: 0.1.0 + title: CGR - API +tags: + - name: member + description: membros + - name: team + description: times + - name: role + description: cargos + - name: user + description: usuários + - name: authentication + description: autenticação +paths: + /member: + post: + tags: + - member + summary: Cadastra um novo membro + description: "" + operationId: createMember + requestBody: + $ref: "#/components/requestBodies/Member" + responses: + "200": + description: Criado com sucesso + content: + application/json: + schema: + $ref: "#/components/schemas/Member-Response" + "405": + description: Invalid input + put: + tags: + - member + summary: Atualiza os dados de um membro cadastrado + description: "" + operationId: updateMember + requestBody: + $ref: "#/components/requestBodies/Member" + "200": + description: Atualizado com sucesso + content: + application/json: + schema: + $ref: "#/components/schemas/Member-Response" + "405": + description: Invalid input +components: + requestBodies: + Member: + content: + application/json: + schema: + $ref: "#/components/schemas/Member" + description: Um membro que partipa(ou) da empresa. + required: true + schemas: + Member: + type: object + required: + - name + properties: + member: + type: object + properties: + name: + type: string + example: Alice da Costa Borges + deleted-at: + type: string + format: date-time + example: null + hard_delete: + type: boolean + example: false + description: \[PERIGO!\] Informa se o membro da requisição deve ser apagado. + roles: + type: array + items: + type: object + properties: + id: + type: integer + format: int64 + example: 1 + leave_role: + description: Informa se a operação relativa ao cargo deve ser participar + (false), ou sair (true) + type: boolean + example: false + Member-Response: + type: object + required: + - name + properties: + id: + type: integer + format: int64 + example: 1 + user_id: + type: integer + format: int64 + example: null + name: + type: string + example: Alice da Costa Borges + created_at: + type: string + format: date-time + updated_at: + type: string + format: date-time + deleted_at: + type: string + format: date-time + example: null + Team: + type: object + required: + - name + properties: + id: + type: integer + format: int64 + name: + type: string + example: Núcleo de Talentos + initials: + type: string + example: NUT + created_at: + type: string + format: date-time + updated_at: + type: string + format: date-time + deleted_at: + type: string + format: date-time + Role: + type: object + required: + - team_id + - name + properties: + team_id: + type: integer + format: int64 + example: 1 + name: + type: string + example: Consultor de Talentos + created_at: + type: string + format: date-time + updated_at: + type: string + format: date-time + deleted_at: + type: string + format: date-time + example: null + MemberRole: + type: object + required: + - role_id + - member_id + properties: + id: + type: integer + format: int64 + member_id: + type: integer + format: int64 + role_id: + type: integer + format: int64 + entry_date: + type: string + format: date-time + created_at: + type: string + format: date-time + updated_at: + type: string + format: date-time + deleted_at: + type: string + format: date-time + User: + type: object + required: + - id + - email + properties: + id: + type: integer + format: int64 + name: + type: string + example: Larissa Andrade + member_id: + type: integer + format: int64 + admin: + type: boolean + created_at: + type: string + format: date-time + updated_at: + type: string + format: date-time \ No newline at end of file