summaryrefslogtreecommitdiff
path: root/qa/qa/specs/features/browser_ui/2_plan/email/trigger_email_notification_spec.rb
blob: 0a577aa07f8bfc1104d7509c4b20764065248d29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# frozen_string_literal: true

module QA
  context 'Plan', :orchestrated, :smtp do
    describe 'Email Notification' do
      include Support::Api

      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 |project|
          project.name = 'email-notification-test'
        end
      end

      before do
        Flow::Login.sign_in
      end

      it 'is received by a user for project invitation' do
        Flow::Project.add_member(project: project, username: user.username)

        expect(page).to have_content(/@#{user.username}(\n| )?Given access/)

        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

      private

      def mailhog_json
        Support::Retrier.retry_until(sleep_interval: 1) do
          Runtime::Logger.debug(%Q[retrieving "#{QA::Runtime::MailHog.api_messages_url}"])

          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
      end
    end
  end
end