| # encoding: utf-8 |
| # frozen_string_literal: true |
| require 'spec_helper' |
| require 'whimsy/asf' |
| |
| describe ASF::Mail do |
| |
| describe "ASF::Mail.to_canonical" do |
| it "should return address unaltered for invalid emails" do |
| email = 'textwithnoATsign' |
| expect(ASF::Mail.to_canonical(email)).to eq(email) |
| email = 'textwithtrailing@' |
| expect(ASF::Mail.to_canonical(email)).to eq(email) |
| email = '@textwithleadingAT' |
| expect(ASF::Mail.to_canonical(email)).to eq(email) |
| end |
| it "should return address with downcased domain for valid emails" do |
| expect(ASF::Mail.to_canonical('ABC@DEF')).to eq('ABC@def') |
| end |
| it "should return address with downcased domain and canonicalised name for GMail emails" do |
| expect(ASF::Mail.to_canonical('A.B.C+123@GMail.com')).to eq('abc@gmail.com') |
| end |
| it "should return address with downcased domain and canonicalised name for Googlemail emails" do |
| expect(ASF::Mail.to_canonical('A.B.C+123@Googlemail.com')).to eq('abc@gmail.com') |
| end |
| end |
| |
| describe '.cansub(member, pmc_chair, ldap_pmcs)' do |
| committers = ['infra-users', 'jobs', 'site-dev', 'committers-cvs', 'site-cvs', 'party'] |
| board = ['board', 'board-commits', 'board-chat'] |
| members = ['members','press'] # partial list |
| notallowed = ['notallowed'] |
| lists = ASF::Mail.cansub(false, false, nil) |
| it 'should return public lists only' do |
| if TEST_DATA |
| expect(lists.length).to be >= 7 |
| else |
| expect(lists.length).to be >= 1000 |
| end |
| expect(lists).not_to include('private') |
| expect(lists).not_to include('security') |
| expect(lists).to include(*committers) |
| expect(lists).not_to include(*board) |
| expect(lists).not_to include(*members) |
| expect(lists).not_to include(*notallowed) |
| end |
| it 'should return the same lists' do |
| mylists = ASF::Mail.cansub(false, false, []) - lists |
| expect(mylists.length).to be(0) |
| end |
| it 'should return private PMC lists' do |
| mylists = ASF::Mail.cansub(false, false, ['ant','whimsical']) - lists |
| expect(mylists.length).to be(2) |
| expect(mylists).to include('ant-private','whimsical-private') |
| expect(mylists).not_to include(*notallowed) |
| end |
| it 'should not return non-existent lists' do |
| mylists = ASF::Mail.cansub(false, false, ['xxxant','xxxwhimsical']) - lists |
| expect(mylists.length).to be(0) |
| end |
| it 'should return private PPMC lists' do |
| if TEST_DATA |
| podnames = ['pod1','pod2'] |
| else |
| podnames = ASF::Podling.current.map(&:name) |
| end |
| mylists = ASF::Mail.cansub(false, false, podnames) - lists |
| expect(mylists.length).to be_between(podnames.length-2, podnames.length).inclusive # mailing list may not be set up yet |
| expect(mylists).not_to include(*notallowed) |
| end |
| it 'should return chair lists only' do |
| mylists = ASF::Mail.cansub(false, true, nil) |
| if TEST_DATA |
| expect(mylists.length).to be >= 7 |
| else |
| expect(mylists.length).to be >= 1000 |
| end |
| expect(mylists).not_to include('private') |
| expect(mylists).not_to include('security') |
| expect(mylists).to include(*committers) |
| expect(mylists).to include(*board) |
| expect(mylists).not_to include(*members) |
| expect(mylists).not_to include(*notallowed) |
| end |
| it 'should return member lists only' do |
| mylists = ASF::Mail.cansub(true, false, nil) |
| if TEST_DATA |
| expect(mylists.length).to be >= 7 |
| else |
| expect(mylists.length).to be >= 1000 |
| end |
| expect(mylists).not_to include('private') |
| expect(mylists).not_to include('security') |
| expect(mylists).to include(*committers) |
| expect(mylists).to include(*board) |
| expect(mylists).to include(*members) |
| expect(mylists).not_to include(*notallowed) |
| end |
| end |
| |
| describe '.deprecated()' do |
| it 'should return some lists' do |
| depr = ASF::Mail.deprecated() |
| if TEST_DATA |
| expect(depr.length).to be(4) # locally fixed size |
| else |
| expect(depr.length).to be_between(0,10).inclusive # varies, but probably in that range |
| end |
| end |
| end |
| |
| end |