Welcome to mirror list, hosted at ThFree Co, Russian Federation.

issues_spec.rb « emails « features « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c425dad88aa900de9214ee5f16a8195e376030b8 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# frozen_string_literal: true

require "spec_helper"

RSpec.describe "E-Mails > Issues", :js, feature_category: :team_planning do
  let_it_be(:project) { create(:project_empty_repo, :public, name: 'Long Earth') }
  let_it_be(:author) { create(:user, username: 'author', name: 'Sally Linsay') }
  let_it_be(:current_user) { create(:user, username: 'current_user', name: 'Shi-mi') }

  before do
    project.add_developer(current_user)
    sign_in(current_user)
  end

  describe 'assignees' do
    let_it_be(:assignee) { create(:user, username: 'assignee', name: 'Joshua Valienté') }
    let_it_be(:issue_without_assignee) { create(:issue, project: project, author: author, title: 'No milk today!') }

    let_it_be(:issue_with_assignee) do
      create(
        :issue, project: project, author: author, assignees: [assignee],
        title: 'All your base are belong to us')
    end

    it 'sends confirmation e-mail for assigning' do
      synchronous_notifications
      expect(Notify).to receive(:reassigned_issue_email)
        .with(author.id, issue_without_assignee.id, [], current_user.id, nil)
        .once
        .and_call_original
      expect(Notify).to receive(:reassigned_issue_email)
        .with(assignee.id, issue_without_assignee.id, [], current_user.id, NotificationReason::ASSIGNED)
        .once
        .and_call_original

      visit issue_path(issue_without_assignee)
      assign_to(assignee)

      expect(find('#notes-list')).to have_text("Shi-mi assigned to @assignee just now")
    end

    it 'sends confirmation e-mail for reassigning' do
      synchronous_notifications
      expect(Notify).to receive(:reassigned_issue_email)
        .with(author.id, issue_with_assignee.id, [assignee.id], current_user.id, NotificationReason::ASSIGNED)
        .once
        .and_call_original
      expect(Notify).to receive(:reassigned_issue_email)
        .with(assignee.id, issue_with_assignee.id, [assignee.id], current_user.id, nil)
        .once
        .and_call_original

      visit issue_path(issue_with_assignee)
      assign_to(author)

      expect(find('#notes-list')).to have_text("Shi-mi assigned to @author and unassigned @assignee just now")
    end

    it 'sends confirmation e-mail for unassigning' do
      synchronous_notifications
      expect(Notify).to receive(:reassigned_issue_email)
        .with(author.id, issue_with_assignee.id, [assignee.id], current_user.id, nil)
        .once
        .and_call_original
      expect(Notify).to receive(:reassigned_issue_email)
        .with(assignee.id, issue_with_assignee.id, [assignee.id], current_user.id, nil)
        .once
        .and_call_original

      visit issue_path(issue_with_assignee)
      quick_action('/unassign')

      expect(find('#notes-list')).to have_text("Shi-mi unassigned @assignee just now")
    end
  end

  describe 'closing' do
    let_it_be(:issue) { create(:issue, project: project, author: author, title: 'Public Holiday') }

    it 'sends confirmation e-mail for closing' do
      synchronous_notifications
      expect(Notify).to receive(:closed_issue_email)
        .with(author.id, issue.id, current_user.id, { closed_via: nil, reason: nil })
        .once
        .and_call_original

      visit issue_path(issue)
      quick_action("/close")

      expect(find('#notes-list')).to have_text("Shi-mi closed just now")
    end
  end

  private

  def assign_to(user)
    quick_action("/assign @#{user.username}")
  end

  def quick_action(command)
    fill_in 'note[note]', with: command
    click_button 'Comment'
  end

  def synchronous_notifications
    expect_next_instance_of(NotificationService) do |service|
      expect(service).to receive(:async).and_return(service)
    end
  end
end