jam-cloud/web/spec/controllers/api_retailer_invitations_co...

56 lines
1.7 KiB
Ruby

require 'spec_helper'
describe ApiRetailerInvitationsController, type: :controller do
before { skip "Lessons/Teachers/Students/Schools are unsupported" }
render_views
let (:owner) {FactoryBot.create(:user)}
let (:retailer) {FactoryBot.create(:retailer, user: owner)}
let (:retailer_invitation_teacher) {FactoryBot.create(:retailer_invitation, retailer: retailer)}
before(:each) do
controller.current_user = owner
end
describe "index" do
it "works" do
get :index, params: { id: retailer.id }
response.should be_successful
JSON.parse(response.body)['total_entries'].should eql 0
retailer_invitation_teacher.touch
get :index, params: { id: retailer.id }
response.should be_successful
JSON.parse(response.body)['total_entries'].should eql 1
end
end
describe "create" do
it "works" do
UserMailer.deliveries.clear
post :create, params: { id: retailer.id, first_name: "Seth", last_name: "Call", email: "seth@jamkazam.com", :format => 'json' }
response.should be_successful
UserMailer.deliveries.length.should eql 1
JSON.parse(response.body)['id'].should eql RetailerInvitation.find_by_email("seth@jamkazam.com").id
end
end
describe "resend" do
it "works" do
UserMailer.deliveries.clear
post :resend, params: { id: retailer.id, invitation_id: retailer_invitation_teacher.id, :format => 'json' }
UserMailer.deliveries.length.should eql 1
response.should be_successful
end
end
describe "delete" do
it "works" do
delete :delete, params: { id: retailer.id, invitation_id: retailer_invitation_teacher.id, :format => 'json' }
response.should be_successful
end
end
end