# frozen_string_literal: true require 'spec_helper' describe USPSFlags::Grades do describe 'invalid insignia' do it 'should raise USPSFlags::Errors::InvalidInsignia if an invalid grade is specified' do @insignia = USPSFlags::Grades.new do |b| b.grade = :not_a_grade b.outfile = '' end expect { @insignia.svg }.to raise_error( USPSFlags::Errors::InvalidInsignia, 'Unknown grade: not_a_grade' ) end it 'should raise USPSFlags::Errors::InvalidInsignia if an invalid edpro is specified' do @insignia = USPSFlags::Grades.new do |b| b.edpro = nil b.outfile = '' end expect { @insignia.svg }.to raise_error( USPSFlags::Errors::InvalidInsignia, 'EdPro must be boolean' ) end it 'should raise USPSFlags::Errors::InvalidInsignia if an invalid membership is specified' do @insignia = USPSFlags::Grades.new do |b| b.membership = :normal b.outfile = '' end expect { @insignia.svg }.to raise_error( USPSFlags::Errors::InvalidInsignia, 'Unknown membership level: normal' ) end end context 'S' do before(:each) do @insignia = USPSFlags::Grades.new do |g| g.grade = :s g.outfile = '' end end it 'should have the S insignia' do expect(@insignia.svg).to include( <<~SVG SVG ) end end context 'P' do before(:each) do @insignia = USPSFlags::Grades.new do |g| g.grade = :p g.outfile = '' end end it 'should have the P insignia' do expect(@insignia.svg).to include( <<~SVG SVG ) end end context 'AP - EdPro' do before(:each) do @insignia = USPSFlags::Grades.new do |g| g.grade = :ap g.edpro = true g.outfile = '' end end it 'should have the AP insignia' do expect(@insignia.svg).to include( <<~SVG SVG ) end it 'should have the AP EdPro bar' do expect(@insignia.svg).to include( <<~SVG SVG ) end end context 'JN - 5MM' do before(:each) do @insignia = USPSFlags::Grades.new do |g| g.grade = :jn g.merit_marks = 5 g.edpro = true g.outfile = '' end end it 'should have the JN insignia' do expect(@insignia.svg).to include( <<~SVG SVG ) end it 'should have a 5th position merit mark' do expect(@insignia.svg).to include('') end it 'should not have a 6th position merit mark' do expect(@insignia.svg).to_not include('') end it 'should have the JN EdPro bar' do expect(@insignia.svg).to include( <<~SVG SVG ) end end context 'N - Life Member' do before(:each) do @insignia = USPSFlags::Grades.new do |g| g.grade = :n g.membership = :life g.outfile = '' end end it 'should have the N insignia' do expect(@insignia.svg).to include( <<~SVG SVG ) end it 'should have a life member arrow' do expect(@insignia.svg).to include( 'm 107.6,178.2 c -0.2,0.7 -1.2,4.7 -2.1,8.8 -0.9,4.1 -2.2,9.7 -3,12.5 -7.9,29.7 -8.9,51.9 -2.9,67.7 4.5,' \ '12.2 7,16.7 8.9,16.7 2.4,0.1 12.2,-15.8 16.2,-26.4 6.4,-16.5 6.7,-18 6.7,-33.6 0.1,-15.7 -0.1,-16.4 -6.7,' \ '-29.7 -2,-3.9 -5.4,-8.5 -8.9,-11.8 -5.7,-5.5 -7.6,-6.4 -8.2,-4.2 z' ) end end context 'SN - Senior Member - 20 MM' do before(:each) do @insignia = USPSFlags::Grades.new do |g| g.grade = :sn g.membership = :senior g.merit_marks = 20 g.outfile = '' end end it 'should have the SN insignia box' do expect(@insignia.svg).to include(' SVG ) end it 'should have a 20th position merit mark' do expect(@insignia.svg).to include('') end end it 'should generate all without error' do expect(USPSFlags::Grades.all).to eql(USPSFlags::Grades::ALL_CONFIGS) end it 'should raise the correct error with an invalid edpro request' do expect { USPSFlags::Grades::EdPro.get(:s) }.to raise_error( USPSFlags::Errors::InvalidInsignia, 'EdPro is only valid for grades AP, JN, N' ) end end