19
19
activate_encrypt ( user_preferences_page , current_user )
20
20
end
21
21
22
- def select_self_as_recipient
22
+ def select_recipient ( username )
23
23
find ( "#private-message-users" ) . click
24
- find ( "#private-message-users-filter input[name='filter-input-search']" ) . send_keys (
25
- current_user . username ,
26
- )
24
+ find ( "#private-message-users-filter input[name='filter-input-search']" ) . send_keys ( username )
27
25
find ( ".email-group-user-chooser-row" ) . click
28
26
find ( "#private-message-users" ) . click
29
27
end
30
28
31
29
it "can permanently decrypt the topic" do
30
+ Jobs . run_immediately!
31
+
32
32
topic_page . open_new_message
33
33
expect ( page ) . to have_css ( ".encrypt-controls .d-icon-lock" )
34
34
35
- select_self_as_recipient
35
+ enable_encrypt_for_user_in_session ( other_user , user_preferences_page )
36
+ select_recipient ( other_user . username )
36
37
37
38
# Create encrypted PM
38
39
topic_page . fill_in_composer_title ( topic_title )
39
40
topic_page . fill_in_composer ( "This is an initial post in the encrypted PM" )
40
41
topic_page . send_reply
41
42
42
- # Check it worked, and post a reply
43
+ # Check it worked
43
44
expect ( find ( ".fancy-title" ) ) . to have_content ( topic_title )
44
45
expect ( page ) . to have_css ( ".topic-status .d-icon-user-secret" )
45
46
expect ( find ( "#post_1" ) ) . to have_content ( "This is an initial post in the encrypted PM" )
47
+
48
+ # Reply from other user
49
+ using_session ( "user_#{ other_user . username } _enable_encrypt" ) do
50
+ visit "/t/#{ Topic . last . id } "
51
+ topic_page . click_reply_button
52
+ topic_page . fill_in_composer ( "Reply from other user" )
53
+ topic_page . send_reply
54
+ expect ( find ( "#post_2" ) ) . to have_content ( "Reply from other user" )
55
+ end
56
+
57
+ # Final reply from initial user, with uploads
46
58
topic_page . click_reply_button
47
59
topic_page . fill_in_composer ( "This is a reply to the encrypted PM" )
48
60
attach_file ( file_from_fixtures ( "logo.png" , "images" ) . path ) do
@@ -51,7 +63,7 @@ def select_self_as_recipient
51
63
expect ( page ) . to have_no_css ( "#file-uploading" )
52
64
topic_page . send_reply
53
65
54
- expect ( find ( "#post_2 " ) ) . to have_content ( "This is a reply to the encrypted PM" )
66
+ expect ( find ( "#post_3 " ) ) . to have_content ( "This is a reply to the encrypted PM" )
55
67
56
68
try_until_success do
57
69
upload = Topic . last . posts . last . uploads . first
@@ -60,6 +72,7 @@ def select_self_as_recipient
60
72
end
61
73
62
74
initial_bump_date = Topic . last . bumped_at
75
+ initial_notification_count = Notification . count
63
76
64
77
# Permanently decrypt the topic
65
78
find ( ".decrypt-topic-button" ) . click
@@ -72,21 +85,23 @@ def select_self_as_recipient
72
85
expect ( page ) . not_to have_css ( "body.encrypted-topic-page" )
73
86
expect ( page ) . to have_css ( ".private-message-glyph" )
74
87
expect ( find ( "#post_1" ) ) . to have_content ( "This is an initial post in the encrypted PM" )
75
- expect ( find ( "#post_2" ) ) . to have_content ( "This is a reply to the encrypted PM" )
88
+ expect ( find ( "#post_2" ) ) . to have_content ( "Reply from other user" )
89
+ expect ( find ( "#post_3" ) ) . to have_content ( "This is a reply to the encrypted PM" )
76
90
77
91
# Check database state is good
78
92
expect ( Topic . last . is_encrypted? ) . to eq ( false )
79
93
upload = Topic . last . posts . last . uploads . first
80
94
expect ( upload ) . to be_present
81
95
expect ( upload . url ) . not_to end_with ( ".encrypted" )
82
96
expect ( Topic . last . bumped_at ) . to eq ( initial_bump_date ) # rubocop:disable Discourse/TimeEqMatcher because it should be precisely the same
97
+ expect ( Notification . count ) . to eq ( initial_notification_count )
83
98
end
84
99
85
100
it "can permanently decrypt multiple topics" do
86
101
3 . times do |i |
87
102
topic_page . open_new_message
88
103
expect ( page ) . to have_css ( ".encrypt-controls .d-icon-lock" )
89
- select_self_as_recipient
104
+ select_recipient ( current_user . username )
90
105
91
106
# Create encrypted PM
92
107
topic_page . fill_in_composer_title ( topic_title )
0 commit comments