3 # Système de gestion des adhésions de Nos oignons
4 # Copyright © 2013-2014 Nos oignons <contact@nos-oignons.net>
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as
8 # published by the Free Software Foundation, either version 3 of the
9 # License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 stub_request(:any, /mailman.example.org/).
26 with(basic_auth: ['mailman_rest_user', 'mailman_rest_pass'])
27 stub_request(:get, 'https://mailman.example.org/3.0/lists/ag@nos-oignons.net/roster/member').
28 with(basic_auth: ['mailman_rest_user', 'mailman_rest_pass']).
29 to_return { |request| {body: roster_member_payload } }
32 def member_id_for_email(email)
33 Digest::SHA1.hexdigest(email)
36 def roster_member_payload
37 # This is an approximation of the actual payload from Mailman, but good enough for our needs
39 "total_size": @ag_emails.count,
41 "entries": @ag_emails.map { |email| { "email": email, "member_id": member_id_for_email(email) } },
46 Given /^une liste ag@ avec comme emails inscrits:$/ do |subscriber_list|
47 @ag_emails = subscriber_list.strip.split
50 Then 'la liste ag@ doit avoir reçu l’inscription de {string}' do |email|
52 a_request(:post, "https://mailman.example.org/3.0/members").
53 with(headers: {'Content-Type': 'application/json'},
55 {"list_id": "ag.nos-oignons.net",
58 "pre_confirmed": true,
65 Then 'la liste ag@ ne doit pas avoir reçu d’inscription' do
67 a_request(:post, "https://mailman.example.org/3.0/members")
68 ).not_to have_been_made
71 Then 'la liste ag@ doit avoir reçu la désinscription de {string}' do |email|
73 a_request(:delete, "https://mailman.example.org/3.0/members/#{member_id_for_email(email)}")