| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| namespace :message_notifications do | ||
| task backfill_conversations: :environment do | ||
| Notification.where(type: "NewMessageNotification").find_each do |notification| | ||
| instance = notification.to_notification | ||
| notification.update!( | ||
| recipient: notification.recipient.user, | ||
| params: { | ||
| message: instance.message, | ||
| conversation: instance.message.conversation | ||
| } | ||
| ) | ||
|
|
||
| # The associated developers with these notifications where deleted. | ||
| Notification.where(id: [1, 98]).destroy_all | ||
| end | ||
| end | ||
|
|
||
| task mark_as_read: :environment do | ||
| Notification.mark_as_read! | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| require "test_helper" | ||
|
|
||
| class NotificationsTest < ActionDispatch::IntegrationTest | ||
| test "you must be signed in" do | ||
| get notifications_path | ||
| assert_redirected_to new_user_registration_path | ||
| end | ||
|
|
||
| test "you can view the new notifications page even if none exist" do | ||
| sign_in users(:with_business) | ||
|
|
||
| get notifications_path | ||
| assert_select "h3", "No new notifications" | ||
| end | ||
|
|
||
| test "you can view your new notifications if you have new (unread) notifications" do | ||
| user = users(:with_business) | ||
| developer = developers(:available) | ||
| sign_in user | ||
| create_message!(developer: developer, business: user.business) | ||
|
|
||
| get notifications_path | ||
| assert_select "h1", "New notifications" | ||
| end | ||
|
|
||
| test "viewing a notification marks it as read and redirects" do | ||
| user = users(:with_business) | ||
| developer = developers(:available) | ||
| sign_in user | ||
| message = create_message!(developer: developer, business: user.business) | ||
| notification = Notification.last | ||
|
|
||
| refute notification.reload.read? | ||
| get notification_path(notification) | ||
|
|
||
| assert_redirected_to conversation_path(message.conversation) | ||
| assert notification.reload.read? | ||
| end | ||
|
|
||
| test "redirects to your notifications if the notification doesn't have a URL" do | ||
| user = users(:admin) | ||
| sign_in user | ||
| Conversation.create!(developer: developers(:available), business: businesses(:one)) | ||
| notification = Notification.last | ||
|
|
||
| get notification_path(notification) | ||
|
|
||
| assert_redirected_to notifications_path | ||
| end | ||
|
|
||
| def create_message!(developer:, business:) | ||
| Message.create!(developer: developer, business: business, sender: developer, body: "Hello!") | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| require "test_helper" | ||
|
|
||
| class ReadNotificationsTest < ActionDispatch::IntegrationTest | ||
| test "you must be signed in" do | ||
| get read_notifications_path | ||
| assert_redirected_to new_user_registration_path | ||
| end | ||
|
|
||
| test "you can view the history page even if no read notifications exist" do | ||
| sign_in users(:with_business) | ||
|
|
||
| get read_notifications_path | ||
| assert_select "h3", "No read notifications" | ||
| end | ||
|
|
||
| test "you can view your past notifications if you have past (read) notifications" do | ||
| user = users(:with_business) | ||
| developer = developers(:available) | ||
| sign_in user | ||
| Message.create!(developer: developer, business: user.business, sender: developer, body: "Hello!") | ||
| Notification.last.mark_as_read! | ||
|
|
||
| get read_notifications_path | ||
|
|
||
| assert_select "h1", "Read notifications" | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,16 @@ | ||
| class AdminMailerPreview < ActionMailer::Preview | ||
| def new_developer_profile | ||
| notification = Notification.where(type: NewDeveloperProfileNotification.to_s).first | ||
| AdminMailer.with(record: notification, recipient: User.first).new_developer_profile | ||
| end | ||
|
|
||
| def new_business | ||
| notification = Notification.where(type: NewBusinessNotification.to_s).first | ||
| AdminMailer.with(record: notification, recipient: User.first).new_business | ||
| end | ||
|
|
||
| def new_conversation | ||
| notification = Notification.where(type: NewConversationNotification.to_s).first | ||
| AdminMailer.with(record: notification, recipient: User.first).new_conversation | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| class MessageMailerPreview < ActionMailer::Preview | ||
| def new_message | ||
| notification = Notification.where(type: NewMessageNotification.to_s).first | ||
| MessageMailer.with(record: notification, recipient: notification.recipient).new_message | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| require "test_helper" | ||
|
|
||
| class NotificationTest < ActiveSupport::TestCase | ||
| test "conversation resolves correctly" do | ||
| developer = developers(:available) | ||
| business = businesses(:one) | ||
| message = Message.create!(developer: developer, business: business, sender: developer, body: "Hello!") | ||
|
|
||
| assert Notification.last.to_notification.conversation == message.conversation | ||
| end | ||
|
|
||
| test "message resolves correctly" do | ||
| developer = developers(:available) | ||
| business = businesses(:one) | ||
| message = Message.create!(developer: developer, business: business, sender: developer, body: "Hello!") | ||
|
|
||
| assert Notification.last.to_notification.message == message | ||
| end | ||
| end |