Skip to content

Commit

Permalink
Add spec for superadmin editing subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
sssggr committed Feb 10, 2018
1 parent 6ca6076 commit 70e1322
Show file tree
Hide file tree
Showing 14 changed files with 440 additions and 0 deletions.
12 changes: 12 additions & 0 deletions spec/factories/lists.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FactoryBot.define do
factory :list do
email "list@example.org"

trait :with_one_subscription do
after(:build) do |list|
create(:subscription)
end
end
factory :list_with_one_subscription, traits: [:with_one_subscription]
end
end
9 changes: 9 additions & 0 deletions spec/factories/subscriptions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FactoryBot.define do
factory :subscription do
sequence(:email) {|n| "user#{n}@example.org" }
fingerprint "129A74AD5317457F9E502844A39C61B32003A8D8"
admin false
delivery_enabled true
list_id 1
end
end
57 changes: 57 additions & 0 deletions spec/features/subscriptions/superadmin_edits_subscription_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
require "rails_helper"

feature "Super admin edits a subscription" do
scenario "gets a form populated with with the subscription data" do
super_admin = create(:account, email: "root@localhost")

stub_request(:post, "https://localhost:4443/subscriptions.json").
with(body: "{\"email\":\"user1@example.org\",\"fingerprint\":\"129A74AD5317457F9E502844A39C61B32003A8D8\",\"admin\":true,\"delivery_enabled\":true,\"list_id\":1}").
to_return(status: 200, body: File.read(fixture_path + "/admin_subscription.json"))
subscription = create(:subscription, admin: true)

stub_request(:post, "https://localhost:4443/lists.json").
with(body: "{\"email\":\"list1@example.org\",\"subscriptions\":[{\"email\":\"subscription5@example.org\",\"fingerprint\":\"129A74AD5317457F129A74AD5317457F\",\"admin\":true,\"delivery_enabled\":true,\"list_id\":11,\"id\":8,\"created_at\":\"2018-01-13T16:31:19.406Z\",\"updated_at\":\"2018-01-13T16:31:19.427Z\"}]}").
to_return(status: 200, body: File.read(fixture_path + "/list1.json"))
_list = create(:list, email: "list1@example.org", subscriptions: [subscription])

stub_request(:get, "https://localhost:4443/lists.json").
to_return(status: 200, body: File.read(fixture_path + "/lists.json"))
stub_request(:get, "https://localhost:4443/subscriptions.json?email=root@localhost").
to_return(body: File.read(fixture_path + "/subscriptions.json"))
stub_request(:get, "https://localhost:4443/lists/1.json").
to_return(status: 200, body: File.read(fixture_path + "/list1.json"))
stub_request(:get, "https://localhost:4443/lists/2.json").
to_return(status: 200, body: File.read(fixture_path + "/list2.json"))
stub_request(:get, "https://localhost:4443/subscriptions.json?list_id=1").
to_return(status: 200, body: File.read(fixture_path + "/subscriptions.json"))
stub_request(:get, "https://localhost:4443/keys/129A74AD5317457F9E502844A39C61B32003A8D8.json?list_id=1").
to_return(status: 200, body: File.read(fixture_path + "/key.json"))
stub_request(:get, "https://localhost:4443/keys/129A74AD5317457F9E502844A39C61B32003A8D8.json?list_id=2").
to_return(status: 200, body: File.read(fixture_path + "/key.json"))

stub_request(:get, "https://localhost:4443/keys/59C71FB38AEE22E091C78259D06350440F759BD3.json?list_id=1").
to_return(status: 200, body: File.read(fixture_path + "/key.json"))

sign_in(super_admin)

stub_request(:get, "https://localhost:4443/subscriptions/8.json").
to_return(status: 200, body: File.read(fixture_path + "/subscription.json"))
stub_request(:get, "https://localhost:4443/lists/1.json").
with(headers: {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Basic c2NobGV1ZGVyOmlpMTIzNDU2Nzg5aWk=', 'User-Agent'=>'Ruby'}).
to_return(status: 200, body: File.read(fixture_path + "/list1.json"))
stub_request(:get, "https://localhost:4443/keys.json?list_id=1").
to_return(status: 200, body: File.read(fixture_path + "/keys.json"))

visit(edit_subscription_path(subscription.id))
expect(page).to have_field('Email', with: subscription.email, disabled: true)

WebMock.reset!
end

def sign_in(user)
visit new_login_path
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Login"
end
end
10 changes: 10 additions & 0 deletions spec/fixtures/admin_subscription.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": 8,
"list_id": 11,
"email": "subscription5@example.org",
"fingerprint": "129A74AD5317457F129A74AD5317457F",
"admin": true,
"delivery_enabled": true,
"created_at": "2018-01-13T16:31:19.406Z",
"updated_at": "2018-01-13T16:31:19.427Z"
}
22 changes: 22 additions & 0 deletions spec/fixtures/admin_subscriptions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"id": 1,
"list_id": 3,
"email": "subscription3@example.org",
"fingerprint": "129A74AD5317457F9E502844A39C61B32003A8D8",
"admin": true,
"delivery_enabled": true,
"created_at": "2017-12-30T19:13:17.273Z",
"updated_at": "2017-12-30T19:13:17.321Z"
},
{
"id": 4,
"list_id": 4,
"email": "subscription4@example.org",
"fingerprint": "129A74AD5317457F9E502844A39C61B32003A8D8",
"admin": true,
"delivery_enabled": true,
"created_at": "2017-12-30T19:13:17.295Z",
"updated_at": "2017-12-30T19:13:17.317Z"
}
]
9 changes: 9 additions & 0 deletions spec/fixtures/key.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"fingerprint": "59C71FB38AEE22E091C78259D06350440F759BD3",
"email": "schleuder@example.org",
"expiry": null,
"generated_at": "2016-12-06 14:38:05 +0100",
"primary_uid": "Schleuder TestUser <schleuder@example.org>",
"oneline": "0x59C71FB38AEE22E091C78259D06350440F759BD3 schleuder@example.org 2016-12-06",
"trust_issues": null
}
11 changes: 11 additions & 0 deletions spec/fixtures/keys.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"fingerprint": "59C71FB38AEE22E091C78259D06350440F759BD3",
"email": "schleuder@example.org",
"expiry": null,
"generated_at": "2016-12-06 14:38:05 +0100",
"primary_uid": "Schleuder TestUser <schleuder@example.org>",
"oneline": "0x59C71FB38AEE22E091C78259D06350440F759BD3 schleuder@example.org 2016-12-06",
"trust_issues": null
}
]
46 changes: 46 additions & 0 deletions spec/fixtures/list1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"id": 1,
"created_at": "2017-12-30T19:50:15.600Z",
"updated_at": "2017-12-30T19:50:15.600Z",
"email": "list1@example.org",
"fingerprint": "59C71FB38AEE22E091C78259D06350440F759BD3",
"log_level": "warn",
"subject_prefix": null,
"subject_prefix_in": null,
"subject_prefix_out": null,
"openpgp_header_preference": "signencrypt",
"public_footer": null,
"headers_to_meta": [
"from",
"to",
"cc",
"date"
],
"bounces_drop_on_headers": {
"x-spam-flag": true
},
"keywords_admin_only": [
"subscribe",
"unsubscribe",
"delete-key"
],
"keywords_admin_notify": [
"add-key"
],
"send_encrypted_only": true,
"receive_encrypted_only": false,
"receive_signed_only": false,
"receive_authenticated_only": false,
"receive_from_subscribed_emailaddresses_only": false,
"receive_admin_only": false,
"keep_msgid": true,
"bounces_drop_all": false,
"bounces_notify_admins": true,
"include_list_headers": true,
"include_openpgp_header": true,
"max_message_size_kb": 10240,
"language": "en",
"forward_all_incoming_to_admins": false,
"logfiles_to_keep": 2,
"internal_footer": null
}
46 changes: 46 additions & 0 deletions spec/fixtures/list2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"id": 2,
"created_at": "2017-12-30T19:50:15.600Z",
"updated_at": "2017-12-30T19:50:15.600Z",
"email": "list2@example.org",
"fingerprint": "59C71FB38AEE22E091C78259D06350440F759BD3",
"log_level": "warn",
"subject_prefix": null,
"subject_prefix_in": null,
"subject_prefix_out": null,
"openpgp_header_preference": "signencrypt",
"public_footer": null,
"headers_to_meta": [
"from",
"to",
"cc",
"date"
],
"bounces_drop_on_headers": {
"x-spam-flag": true
},
"keywords_admin_only": [
"subscribe",
"unsubscribe",
"delete-key"
],
"keywords_admin_notify": [
"add-key"
],
"send_encrypted_only": true,
"receive_encrypted_only": false,
"receive_signed_only": false,
"receive_authenticated_only": false,
"receive_from_subscribed_emailaddresses_only": false,
"receive_admin_only": false,
"keep_msgid": true,
"bounces_drop_all": false,
"bounces_notify_admins": true,
"include_list_headers": true,
"include_openpgp_header": true,
"max_message_size_kb": 10240,
"language": "en",
"forward_all_incoming_to_admins": false,
"logfiles_to_keep": 2,
"internal_footer": null
}
46 changes: 46 additions & 0 deletions spec/fixtures/list3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"id": 3,
"created_at": "2017-12-30T19:50:15.600Z",
"updated_at": "2017-12-30T19:50:15.600Z",
"email": "list3@example.org",
"fingerprint": "59C71FB38AEE22E091C78259D06350440F759BD3",
"log_level": "warn",
"subject_prefix": null,
"subject_prefix_in": null,
"subject_prefix_out": null,
"openpgp_header_preference": "signencrypt",
"public_footer": null,
"headers_to_meta": [
"from",
"to",
"cc",
"date"
],
"bounces_drop_on_headers": {
"x-spam-flag": true
},
"keywords_admin_only": [
"subscribe",
"unsubscribe",
"delete-key"
],
"keywords_admin_notify": [
"add-key"
],
"send_encrypted_only": true,
"receive_encrypted_only": false,
"receive_signed_only": false,
"receive_authenticated_only": false,
"receive_from_subscribed_emailaddresses_only": false,
"receive_admin_only": false,
"keep_msgid": true,
"bounces_drop_all": false,
"bounces_notify_admins": true,
"include_list_headers": true,
"include_openpgp_header": true,
"max_message_size_kb": 10240,
"language": "en",
"forward_all_incoming_to_admins": false,
"logfiles_to_keep": 2,
"internal_footer": null
}
46 changes: 46 additions & 0 deletions spec/fixtures/list4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"id": 4,
"created_at": "2017-12-30T19:50:15.600Z",
"updated_at": "2017-12-30T19:50:15.600Z",
"email": "list4@example.org",
"fingerprint": "59C71FB38AEE22E091C78259D06350440F759BD3",
"log_level": "warn",
"subject_prefix": null,
"subject_prefix_in": null,
"subject_prefix_out": null,
"openpgp_header_preference": "signencrypt",
"public_footer": null,
"headers_to_meta": [
"from",
"to",
"cc",
"date"
],
"bounces_drop_on_headers": {
"x-spam-flag": true
},
"keywords_admin_only": [
"subscribe",
"unsubscribe",
"delete-key"
],
"keywords_admin_notify": [
"add-key"
],
"send_encrypted_only": true,
"receive_encrypted_only": false,
"receive_signed_only": false,
"receive_authenticated_only": false,
"receive_from_subscribed_emailaddresses_only": false,
"receive_admin_only": false,
"keep_msgid": true,
"bounces_drop_all": false,
"bounces_notify_admins": true,
"include_list_headers": true,
"include_openpgp_header": true,
"max_message_size_kb": 10240,
"language": "en",
"forward_all_incoming_to_admins": false,
"logfiles_to_keep": 2,
"internal_footer": null
}
Loading

0 comments on commit 70e1322

Please sign in to comment.