File: TicketUpdateWithArticleSend.t

package info (click to toggle)
znuny 6.5.18-1
  • links: PTS
  • area: non-free
  • in suites: forky, sid
  • size: 205,344 kB
  • sloc: perl: 1,038,694; xml: 74,551; javascript: 65,276; sql: 23,574; sh: 417; makefile: 63
file content (180 lines) | stat: -rw-r--r-- 5,585 bytes parent folder | download | duplicates (5)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# --
# Copyright (C) 2021 Znuny GmbH, https://znuny.org/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --

use strict;
use warnings;
use utf8;

use vars (qw($Self));

use Kernel::System::VariableCheck qw(:all);

$Kernel::OM->ObjectParamAdd(
    'Kernel::System::UnitTest::Helper' => {
        RestoreDatabase => 1,
    },
);

my $HelperObject             = $Kernel::OM->Get('Kernel::System::UnitTest::Helper');
my $UnitTestWebserviceObject = $Kernel::OM->Get('Kernel::System::UnitTest::Webservice');
my $ConfigObject             = $Kernel::OM->Get('Kernel::Config');
my $ZnunyHelperObject        = $Kernel::OM->Get('Kernel::System::ZnunyHelper');
my $UnitTestEmailObject      = $Kernel::OM->Get('Kernel::System::UnitTest::Email');
my $QueueObject              = $Kernel::OM->Get('Kernel::System::Queue');

$UnitTestEmailObject->MailCleanup();

my %Queue = $QueueObject->QueueGet(
    Name => 'Misc',
);
my $Signature = $QueueObject->GetSignature(
    QueueID => $Queue{QueueID}
);

if ( $Signature =~ m{Your Ticket-Team}m ) {
    $Self->True(
        $Signature,
        "Signature of Queue Misc: $Signature",
    );
}

my %UserData = $HelperObject->TestUserDataGet(
    Groups   => [ 'admin', 'users' ],
    Language => 'de'
);

my $Home = $ConfigObject->Get('Home');

$ZnunyHelperObject->_WebserviceCreate(
    Webservices => {
        TicketCreateAndUpdateWithArticleSend => $Home
            . '/scripts/test/sample/Webservice/TicketCreateAndUpdateWithArticleSend.yml',
    },
);

my $TicketID = $HelperObject->TicketCreate(
    Queue => 'Misc',
);

my $Response = $UnitTestWebserviceObject->Process(
    UnitTestObject => $Self,
    Webservice     => 'TicketCreateAndUpdateWithArticleSend',
    Operation      => 'TicketUpdate',
    Payload        => {
        TicketID => $TicketID,
        Ticket   => {
            Title => 'Asdf',
        },
        Article => {
            Subject              => 'Article subject äöüßÄÖÜ€ис',
            Body                 => 'Article body !"§$%&/()=?Ã<U+009C>*Ã<U+0084>Ã<U+0096>L:L@,.-',
            AutoResponseType     => 'auto reply',
            IsVisibleForCustomer => 1,
            CommunicationChannel => 'Email',
            SenderType           => 'agent',
            From                 => 'hello@znuny.org',
            Charset              => 'utf8',
            MimeType             => 'text/plain',
            HistoryType          => 'NewTicket',
            HistoryComment       => '% % ',
            ArticleSend          => 1,
            To                   => 'rs+TicketCreateAndUpdateWithArticleSend@znuny.org',
            Cc                   => 'jp+TicketCreateAndUpdateWithArticleSend@znuny.org',
            Bcc                  => 'jp2+TicketCreateAndUpdateWithArticleSend@znuny.org',
        },
        Attachment => [
            {
                Content     => 'Ymx1YiBibHViIGJsdWIg',
                ContentType => 'text/html',
                Filename    => 'test.txt',
            },
        ],
        UserLogin => $UserData{UserLogin},
        Password  => $UserData{UserLogin},
    },
);

$Self->True(
    $Response->{Success},
    'ticket updated successfully',
);
$Self->True(
    $Response->{Data}->{TicketID},
    'ticket update result contains ticket id',
);

my @Emails = $UnitTestEmailObject->EmailGet();

my $CcFound;
EMAIL:
for my $Email (@Emails) {
    next EMAIL if !$Email->{Header};
    next EMAIL if $Email->{Header} !~ m{^CC:\s*jp\+TicketCreateAndUpdateWithArticleSend\@znuny\.org$}sm;

    $CcFound = 1;
    last EMAIL;
}

$Self->True(
    $CcFound,
    'Sent email must contain expected Cc address.',
);

$UnitTestEmailObject->EmailValidate(
    UnitTestObject => $Self,
    Message        => 'ticket update triggered ArticleSend functionality.',
    Email          => \@Emails,
    ToArray        => [
        'rs+TicketCreateAndUpdateWithArticleSend@znuny.org',     # To
        'jp+TicketCreateAndUpdateWithArticleSend@znuny.org',     # Cc
        'jp2+TicketCreateAndUpdateWithArticleSend@znuny.org',    # Bcc (not testable like Cc above)
    ],
    Body => qr{Your Ticket-Team}m,
);

# test with no To-email
$UnitTestEmailObject->MailCleanup();

$Response = $UnitTestWebserviceObject->Process(
    UnitTestObject => $Self,
    Webservice     => 'TicketCreateAndUpdateWithArticleSend',
    Operation      => 'TicketUpdate',
    Payload        => {
        TicketID => $TicketID,
        Article  => {
            Subject              => 'Article subject äöüßÄÖÜ€ис',
            Body                 => 'Article body !"§$%&/()=?Ã<U+009C>*Ã<U+0084>Ã<U+0096>L:L@,.-',
            AutoResponseType     => 'auto reply',
            IsVisibleForCustomer => 1,
            CommunicationChannel => 'Email',
            SenderType           => 'agent',
            From                 => 'hello@znuny.org',
            Charset              => 'utf8',
            MimeType             => 'text/plain',
            HistoryType          => 'NewTicket',
            HistoryComment       => '% % ',
            ArticleSend          => 1,
        },
        UserLogin => $UserData{UserLogin},
        Password  => $UserData{UserLogin},
    },
);

$Self->Is(
    $Response->{Data}->{Error}->{ErrorCode},
    'TicketCreate.InvalidParameter',
    'ticket creation failed',
);

@Emails = $UnitTestEmailObject->EmailGet();
$Self->False(
    @Emails ? 1 : 0,
    'No emails sent out',
);

1;