mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-21 15:54:22 +01:00
Merge branch 'tests' of git.sleede.com:projets/fab-manager into tests
This commit is contained in:
commit
23884bc2c5
@ -5,6 +5,8 @@ class Abuse < ActiveRecord::Base
|
|||||||
|
|
||||||
after_create :notify_admins_abuse_reported
|
after_create :notify_admins_abuse_reported
|
||||||
|
|
||||||
|
validates :first_name, :last_name, :email, :message, :presence => true
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
def notify_admins_abuse_reported
|
def notify_admins_abuse_reported
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
json.admin do
|
json.reporting do
|
||||||
json.extract! @abuse, :id, :signaled_id, :signaled_type
|
json.extract! @abuse, :id, :signaled_id, :signaled_type
|
||||||
end
|
end
|
||||||
|
78
test/integration/abuses_test.rb
Normal file
78
test/integration/abuses_test.rb
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
class AbusesTest < ActionDispatch::IntegrationTest
|
||||||
|
|
||||||
|
# Called before every test method runs. Can be used
|
||||||
|
# to set up fixture information.
|
||||||
|
def setup
|
||||||
|
# Do nothing
|
||||||
|
end
|
||||||
|
|
||||||
|
# Called after every test method runs. Can be used to tear
|
||||||
|
# down fixture information.
|
||||||
|
|
||||||
|
def teardown
|
||||||
|
# Do nothing
|
||||||
|
end
|
||||||
|
|
||||||
|
# Abuse report
|
||||||
|
test 'visitor report an abuse' do
|
||||||
|
project = Project.first
|
||||||
|
|
||||||
|
post '/api/abuses',
|
||||||
|
{
|
||||||
|
abuse: {
|
||||||
|
signaled_type: 'Project',
|
||||||
|
signaled_id: project.id,
|
||||||
|
first_name: 'William',
|
||||||
|
last_name: 'Prindle',
|
||||||
|
email: 'wprindle@iastate.edu',
|
||||||
|
message: 'This project is in infringement with the patent US5014921 A.'
|
||||||
|
}
|
||||||
|
}.to_json,
|
||||||
|
{
|
||||||
|
'Accept' => Mime::JSON,
|
||||||
|
'Content-Type' => Mime::JSON.to_s
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check response format & status
|
||||||
|
assert_equal 201, response.status, response.body
|
||||||
|
assert_equal Mime::JSON, response.content_type
|
||||||
|
|
||||||
|
# Check the correct object was signaled
|
||||||
|
abuse = json_response(response.body)
|
||||||
|
assert_equal project.id, abuse[:reporting][:signaled_id], 'project ID mismatch'
|
||||||
|
assert_equal 'Project', abuse[:reporting][:signaled_type], 'signaled object type mismatch'
|
||||||
|
|
||||||
|
# Check notifications were sent for every admins
|
||||||
|
notifications = Notification.where(notification_type_id: NotificationType.find_by_name('notify_admin_abuse_reported'), attached_object_type: 'Abuse', attached_object_id: abuse[:reporting][:id])
|
||||||
|
assert_not_empty notifications, 'no notifications were created'
|
||||||
|
notified_users_ids = notifications.map {|n| n.receiver_id }
|
||||||
|
User.admins.each do |adm|
|
||||||
|
assert_includes notified_users_ids, adm.id, "Admin #{adm.id} was not notified"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Incomplete abuse report
|
||||||
|
test 'visitor send an invalid report' do
|
||||||
|
project = Project.first
|
||||||
|
|
||||||
|
post '/api/abuses',
|
||||||
|
{
|
||||||
|
abuse: {
|
||||||
|
signaled_type: 'Project',
|
||||||
|
signaled_id: project.id,
|
||||||
|
first_name: 'John',
|
||||||
|
last_name: 'Wrong',
|
||||||
|
email: '',
|
||||||
|
message: ''
|
||||||
|
}
|
||||||
|
}.to_json,
|
||||||
|
{
|
||||||
|
'Accept' => Mime::JSON,
|
||||||
|
'Content-Type' => Mime::JSON.to_s
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_equal 422, response.status, response.body
|
||||||
|
assert_match /can't be blank/, response.body
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
34
test/integration/subscriptions_test.rb
Normal file
34
test/integration/subscriptions_test.rb
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
class SubscriptionsTest < ActionDispatch::IntegrationTest
|
||||||
|
|
||||||
|
|
||||||
|
setup do
|
||||||
|
@user = User.find_by_username('jdupont')
|
||||||
|
login_as(@user, scope: :user)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "user take a subscription" do
|
||||||
|
skip
|
||||||
|
plan = Plan.where(group_id: @user.group.id, type: 'Plan').first
|
||||||
|
|
||||||
|
post '/api/subscriptions',
|
||||||
|
{
|
||||||
|
subscription: {
|
||||||
|
plan_id: plan.id,
|
||||||
|
user_id: @user.id,
|
||||||
|
card_token: stripe_card_token
|
||||||
|
}
|
||||||
|
}.to_json,
|
||||||
|
{
|
||||||
|
'Accept' => Mime::JSON,
|
||||||
|
'Content-Type' => Mime::JSON.to_s
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_equal 201, response.status, response.body
|
||||||
|
assert_equal Mime::JSON, response.content_type
|
||||||
|
|
||||||
|
subscription = json_response(response.body)
|
||||||
|
assert_equal plan.id, subscription[:plan_id]
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -13,6 +13,8 @@ end
|
|||||||
Sidekiq::Testing.inline!
|
Sidekiq::Testing.inline!
|
||||||
Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new({ color: true })]
|
Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new({ color: true })]
|
||||||
|
|
||||||
|
require "stripe"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ActiveSupport::TestCase
|
class ActiveSupport::TestCase
|
||||||
@ -23,6 +25,17 @@ class ActiveSupport::TestCase
|
|||||||
def json_response(body)
|
def json_response(body)
|
||||||
JSON.parse(body, symbolize_names: true)
|
JSON.parse(body, symbolize_names: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def stripe_card_token
|
||||||
|
Stripe::Token.create(
|
||||||
|
:card => {
|
||||||
|
:number => "4242424242424242",
|
||||||
|
:exp_month => 4,
|
||||||
|
:exp_year => DateTime.now.next_year.year,
|
||||||
|
:cvc => "314"
|
||||||
|
},
|
||||||
|
).id
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ActionDispatch::IntegrationTest
|
class ActionDispatch::IntegrationTest
|
||||||
|
Loading…
x
Reference in New Issue
Block a user