Commit ef4f6a96 authored by Diego Louzán's avatar Diego Louzán Committed by Sanad Liaquat

feat: add e2e email delivery tests

Depends on a new scenario defined in gitlab-qa that launches a docker
image for mailhog and makes sure that email delivery via smtp is
performed correctly
parent ba8c55ee
---
title: Add e2e qa test for email delivery
merge_request: 20675
author: Diego Louzán
type: other
......@@ -15,6 +15,7 @@ module QA
#
module Flow
autoload :Login, 'qa/flow/login'
autoload :Project, 'qa/flow/project'
end
##
......@@ -33,6 +34,7 @@ module QA
autoload :Fixtures, 'qa/runtime/fixtures'
autoload :Logger, 'qa/runtime/logger'
autoload :GPG, 'qa/runtime/gpg'
autoload :MailHog, 'qa/runtime/mail_hog'
module API
autoload :Client, 'qa/runtime/api/client'
......@@ -130,6 +132,7 @@ module QA
autoload :Kubernetes, 'qa/scenario/test/integration/kubernetes'
autoload :Mattermost, 'qa/scenario/test/integration/mattermost'
autoload :ObjectStorage, 'qa/scenario/test/integration/object_storage'
autoload :SMTP, 'qa/scenario/test/integration/smtp'
end
module Sanity
......@@ -422,6 +425,7 @@ module QA
autoload :Maven, 'qa/service/docker_run/maven'
autoload :NodeJs, 'qa/service/docker_run/node_js'
autoload :GitlabRunner, 'qa/service/docker_run/gitlab_runner'
autoload :MailHog, 'qa/service/docker_run/mail_hog'
end
end
......
# frozen_string_literal: true
module QA
module Flow
module Project
module_function
def add_member(project:, username:)
project.visit!
Page::Project::Menu.perform(&:go_to_members_settings)
Page::Project::Settings::Members.perform do |member_settings|
member_settings.add_member(username)
end
end
end
end
end
......@@ -281,6 +281,10 @@ module QA
ENV.fetch('GITLAB_QA_LOOP_RUNNER_MINUTES', 1).to_i
end
def mailhog_hostname
ENV['MAILHOG_HOSTNAME']
end
private
def remote_grid_credentials
......
# frozen_string_literal: true
module QA
module Runtime
module MailHog
def self.base_url
host = QA::Runtime::Env.mailhog_hostname || 'localhost'
"http://#{host}:8025"
end
def self.api_messages_url
"#{base_url}/api/v2/messages"
end
end
end
end
# frozen_string_literal: true
module QA
module Scenario
module Test
module Integration
class SMTP < Test::Instance::All
tags :smtp
end
end
end
end
end
# frozen_string_literal: true
module QA
context 'Manage', :orchestrated, :smtp do
describe 'mail notification' do
let(:user) do
Resource::User.fabricate_or_use(Runtime::Env.gitlab_qa_username_1, Runtime::Env.gitlab_qa_password_1)
end
let(:project) do
Resource::Project.fabricate_via_api! do |resource|
resource.name = 'email-notification-test'
end
end
before do
Flow::Login.sign_in
end
it 'user receives email for project invitation' do
Flow::Project.add_member(project: project, username: user.username)
expect(page).to have_content(/@#{user.username}(\n| )?Given access/)
# Wait for Action Mailer to deliver messages
mailhog_json = Support::Retrier.retry_until(sleep_interval: 1) do
Runtime::Logger.debug(%Q[retrieving "#{QA::Runtime::MailHog.api_messages_url}"]) if Runtime::Env.debug?
mailhog_response = get QA::Runtime::MailHog.api_messages_url
mailhog_data = JSON.parse(mailhog_response.body)
# Expect at least two invitation messages: group and project
mailhog_data if mailhog_data.dig('total') >= 2
end
# Check json result from mailhog
mailhog_items = mailhog_json.dig('items')
expect(mailhog_items).to include(an_object_satisfying { |o| /project was granted/ === o.dig('Content', 'Headers', 'Subject', 0) })
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment