diff --git a/spec/classes/comptoir_spec.rb b/spec/classes/comptoir_spec.rb index 2d0a1b0d448853b3cf764d41ce98b876ccd9ef74..57815e617d171972a92c740d9e2091d4d3304b82 100644 --- a/spec/classes/comptoir_spec.rb +++ b/spec/classes/comptoir_spec.rb @@ -9,19 +9,77 @@ describe 'comptoir' do it { is_expected.to compile } it { is_expected.to contain_archive('comptoir.tgz') } - it do - is_expected.to contain_file('/etc/comptoir/env.prod.local') \ - .with_content(sensitive(%r{^WEBAPP_I18N_DEFAULT_LOCALE='en'})) - end - context 'without smtp auth' do + context '/etc/comptoir/env.prod.local with default values' do it do + is_expected.to contain_file('/etc/comptoir/env.prod.local') \ + .with_content(sensitive(%r{^APP_ENV=prod$})) + # is_expected.to contain_file('/etc/comptoir/env.prod.local') \ + # .with_content(%r{^DATABASE_URL="postgresql://dbcomptoir:changeit@127.0.0.1:5432/comptoir\?serverVersion=14&charset=utf8"$}) + + is_expected.to contain_file('/etc/comptoir/env.prod.local') \ + .with_content(sensitive(%r{^APP_SECRET=ThisTokenIsNotSoSecretChangeIt$})) is_expected.to contain_file('/etc/comptoir/env.prod.local') \ .with_content(sensitive(%r{^MAILER_DSN=smtp://127.0.0.1:25$})) + + is_expected.to contain_file('/etc/comptoir/env.prod.local') \ + .with_content(sensitive(%r{^WEBAPP_NAME='Comptoir-du-Libre'$})) + is_expected.to contain_file('/etc/comptoir/env.prod.local') \ + .with_content(sensitive(%r{^WEBAPP_SHORTNAME='Comptoir'$})) + is_expected.to contain_file('/etc/comptoir/env.prod.local') \ + .with_content(sensitive(%r{^WEBAPP_I18N_DEFAULT_LOCALE='en'$})) + is_expected.to contain_file('/etc/comptoir/env.prod.local') \ + .with_content(sensitive(%r{^WEBAPP_TIMEZONE='Europe/Paris'$})) + end + end + + context '/etc/comptoir/env.prod.local with custom database settings' do + let(:params) do + { + db_host: 'db.example.org', + db_version: '16', + db_user: 'database_user', + db_password: 'database_password', + db_name: 'database_name', + } + end + + it do + is_expected.to contain_file('/etc/comptoir/env.prod.local') \ + .with_content(%r{^DATABASE_URL="postgresql://database_user:database_password@db.example.org:5432/database_name\?serverVersion=16&charset=utf8"$}) + + # is_expected.to contain_file('/etc/comptoir/env.prod.local') \ + # .with_content(sensitive(%r{^DATABASE_URL="postgresql://database_user:database_password@db.example.org:5432/database_name\?serverVersion=16&charset=utf8"$})) + end + end + + context '/etc/comptoir/env.prod.local with custom app_secret' do + let(:params) do + { + app_secret: 'ThisCustomTokenIsNotSoSecret', + } + end + + it do + is_expected.to contain_file('/etc/comptoir/env.prod.local') \ + .with_content(sensitive(%r{^APP_SECRET=ThisCustomTokenIsNotSoSecret$})) + end + end + + context '/etc/comptoir/env.prod.local with custom SMTP host and without SMTP auth' do + let(:params) do + { + smtp_host: 'smtp.example.com', + } + end + + it do + is_expected.to contain_file('/etc/comptoir/env.prod.local') \ + .with_content(sensitive(%r{^MAILER_DSN=smtp://smtp.example.com:25$})) end end - context 'with smtp auth' do + context '/etc/comptoir/env.prod.local with SMTP auth and custom SMTP host and port' do let(:params) do { smtp_host: 'smtp.example.org', @@ -37,20 +95,39 @@ describe 'comptoir' do end end - context 'with trusted_hosts' do + context '/etc/comptoir/env.prod.local with custom emails (mail from, mail alerting to)' do let(:params) do { - trusted_hosts: '^example.org$', + smtp_mailfrom: 'custormer-contact@example.org', + smtp_mailalertingto: 'webapp-alerting@example.org', } end it do is_expected.to contain_file('/etc/comptoir/env.prod.local') \ - .with_content(sensitive(%r{^WEBAPP_TRUSTED_HOSTS='\^example\.org\$'$})) + .with_content(sensitive(%r{^WEBAPP_EMAIL_FROM='custormer-contact@example.org'$})) + is_expected.to contain_file('/etc/comptoir/env.prod.local') \ + .with_content(sensitive(%r{^WEBAPP_EMAIL_ALERTING_TO='webapp-alerting@example.org'$})) end end - context 'with locale fr' do + context '/etc/comptoir/env.prod.local with custom webapp name' do + let(:params) do + { + app_name: 'The New Comptoir', + app_shortname: 'New-Comptoir', + } + end + + it do + is_expected.to contain_file('/etc/comptoir/env.prod.local') \ + .with_content(sensitive(%r{^WEBAPP_NAME='The New Comptoir'$})) + is_expected.to contain_file('/etc/comptoir/env.prod.local') \ + .with_content(sensitive(%r{^WEBAPP_SHORTNAME='New-Comptoir'$})) + end + end + + context '/etc/comptoir/env.prod.local with locale fr' do let(:params) do { i18ndefaultlocale: 'fr', @@ -62,6 +139,32 @@ describe 'comptoir' do .with_content(sensitive(%r{^WEBAPP_I18N_DEFAULT_LOCALE='fr'})) end end + + context '/etc/comptoir/env.prod.local with custom timezone: Pacific/Tahiti' do + let(:params) do + { + timezone: 'Pacific/Tahiti', + } + end + + it do + is_expected.to contain_file('/etc/comptoir/env.prod.local') \ + .with_content(sensitive(%r{^WEBAPP_TIMEZONE='Pacific/Tahiti'$})) + end + end + + context '/etc/comptoir/env.prod.local with trusted_hosts' do + let(:params) do + { + trusted_hosts: '^example.org$', + } + end + + it do + is_expected.to contain_file('/etc/comptoir/env.prod.local') \ + .with_content(sensitive(%r{^WEBAPP_TRUSTED_HOSTS='\^example\.org\$'$})) + end + end end end end