Clean up spec outputs (#450)
* Improve BadgeAchievementSpec * Create specs for PushNotificationSubscription * Clean-up specs for VideoStatesController * Refactor spec
This commit is contained in:
parent
74266db0d9
commit
ec264bf802
5 changed files with 48 additions and 39 deletions
|
|
@ -1,23 +1,21 @@
|
|||
class VideoStatesController < ApplicationController
|
||||
skip_before_action :verify_authenticity_token
|
||||
|
||||
def create
|
||||
unless valid_user
|
||||
render json: { message: "invalid_user" }, :status => 422
|
||||
render json: { message: "invalid_user" }, status: 422
|
||||
return
|
||||
end
|
||||
begin
|
||||
logger.info "VIDEO STATES: #{params}"
|
||||
request_json = JSON.parse(request.raw_post, {symbolize_names: true})
|
||||
request_json = JSON.parse(request.raw_post, symbolize_names: true)
|
||||
logger.info "VIDEO STATES: #{request_json}"
|
||||
rescue
|
||||
rescue StandardError
|
||||
end
|
||||
request_json = JSON.parse(request.raw_post, {symbolize_names: true})
|
||||
puts request_json
|
||||
message_json = JSON.parse(request_json[:Message], {symbolize_names: true})
|
||||
puts message_json
|
||||
puts "***"
|
||||
request_json = JSON.parse(request.raw_post, symbolize_names: true)
|
||||
message_json = JSON.parse(request_json[:Message], symbolize_names: true)
|
||||
@article = Article.find_by_video_code(message_json[:input][:key])
|
||||
@article.update(video_state: "COMPLETED") #Only is called on completion
|
||||
@article.update(video_state: "COMPLETED") # Only is called on completion
|
||||
NotifyMailer.video_upload_complete_email(@article).deliver
|
||||
render json: { message: "Video state updated" }
|
||||
end
|
||||
|
|
@ -27,5 +25,4 @@ class VideoStatesController < ApplicationController
|
|||
user = nil if !user.has_role?(:super_admin)
|
||||
user
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
8
spec/factories/badge_achievements.rb
Normal file
8
spec/factories/badge_achievements.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
FactoryBot.define do
|
||||
factory :badge_achievement do
|
||||
user
|
||||
badge
|
||||
rewarder { user }
|
||||
rewarding_context_message_markdown { "Hello [Yoho](/hey)" }
|
||||
end
|
||||
end
|
||||
|
|
@ -1,29 +1,17 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe BadgeAchievement, type: :model do
|
||||
let(:user) { create(:user) }
|
||||
let(:badge) { create(:badge) }
|
||||
|
||||
describe "validations" do
|
||||
subject { BadgeAchievement.create(user_id: user.id, badge_id: badge.id) }
|
||||
subject { create(:badge_achievement) }
|
||||
|
||||
it { is_expected.to belong_to(:user) }
|
||||
it { is_expected.to belong_to(:badge) }
|
||||
it { is_expected.to belong_to(:rewarder).class_name("User") }
|
||||
end
|
||||
|
||||
it "disallow duplicate badges" do
|
||||
BadgeAchievement.create(user_id: user.id, badge_id: badge.id, rewarder_id: create(:user).id)
|
||||
expect do
|
||||
BadgeAchievement.create!(user_id: user.id, badge_id: badge.id, rewarder_id: create(:user).id)
|
||||
end.to raise_error
|
||||
it { is_expected.to validate_uniqueness_of(:badge_id).scoped_to(:user_id) }
|
||||
end
|
||||
|
||||
it "turns rewarding_context_message_markdown into rewarding_context_message HTML" do
|
||||
achievement = BadgeAchievement.create(user_id: user.id,
|
||||
badge_id: badge.id,
|
||||
rewarder_id: create(:user).id,
|
||||
rewarding_context_message_markdown: "Hello [Yoho](/hey)")
|
||||
expect(achievement.rewarding_context_message.include?("</a>"))
|
||||
achievement = create(:badge_achievement)
|
||||
expect(achievement.rewarding_context_message).to include("</a>")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,21 @@
|
|||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe PushNotificationSubscription, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
describe "validation" do
|
||||
subject do
|
||||
PushNotificationSubscription.create(user: create(:user),
|
||||
auth_key: "asdf123",
|
||||
endpoint: "asdf123")
|
||||
end
|
||||
|
||||
it { is_expected.to validate_presence_of(:endpoint) }
|
||||
it { is_expected.to validate_presence_of(:user_id) }
|
||||
it { is_expected.to validate_presence_of(:p256dh_key) }
|
||||
it { is_expected.to validate_presence_of(:auth_key) }
|
||||
it { is_expected.to validate_presence_of(:notification_type) }
|
||||
it { is_expected.to validate_uniqueness_of(:endpoint) }
|
||||
it { is_expected.to validate_uniqueness_of(:p256dh_key) }
|
||||
it { is_expected.to validate_uniqueness_of(:auth_key) }
|
||||
it { is_expected.to belong_to(:user) }
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,21 +2,21 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe "VideoStatesUpdate", type: :request do
|
||||
before do
|
||||
@user = FactoryBot.create(:user)
|
||||
@user.update(secret:"TEST_SECRET")
|
||||
@user.add_role(:super_admin)
|
||||
@article = FactoryBot.create(:article, video_code: "DUMMY_VID_CODE")
|
||||
end
|
||||
let(:authorized_user) { create(:user, :super_admin, secret: "TEST_SECRET") }
|
||||
let(:regular_user) { create(:user, secret: "TEST_SECRET") }
|
||||
let(:article) { create(:article, video_code: "DUMMY_VID_CODE") }
|
||||
|
||||
describe "POST /video_states" do
|
||||
it "updates video state" do
|
||||
post "/video_states?key=#{@user.secret}", params: {
|
||||
Message: "{\"input\":{\"key\":\"DUMMY_VID_CODE\"}}"}.to_json
|
||||
input = JSON.unparse(input: { key: article.video_code })
|
||||
post "/video_states?key=#{authorized_user.secret}",
|
||||
params: { Message: input }.to_json
|
||||
expect(Article.last.video_state).to eq("COMPLETED")
|
||||
end
|
||||
|
||||
it "rejects non-authorized users" do
|
||||
@user.remove_role(:super_admin)
|
||||
post "/video_states?key=#{@user.secret}", params: {input: {key: Article.last.video_code}}
|
||||
post "/video_states?key=#{regular_user.secret}",
|
||||
params: { input: { key: article.video_code } }
|
||||
expect(response).to have_http_status(422)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue