Skip to content

Commit fdaa3ad

Browse files
author
Vitaliy Boyko
committed
graphQl-167: removed redundant fixture, optimised tests
1 parent c3845db commit fdaa3ad

File tree

2 files changed

+67
-390
lines changed

2 files changed

+67
-390
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/SendFriend/SendFriendTest.php

Lines changed: 67 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Magento\GraphQl\SendFriend;
99

10-
use Magento\Framework\DataObjectFactory;
1110
use Magento\SendFriend\Model\SendFriend;
1211
use Magento\SendFriend\Model\SendFriendFactory;
1312
use Magento\TestFramework\Helper\Bootstrap;
@@ -27,7 +26,7 @@ protected function setUp()
2726
}
2827

2928
/**
30-
* @magentoApiDataFixture Magento/SendFriend/_files/product_simple.php
29+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
3130
*/
3231
public function testSendFriend()
3332
{
@@ -122,7 +121,7 @@ public function testSendWithoutExistProduct()
122121
}
123122

124123
/**
125-
* @magentoApiDataFixture Magento/SendFriend/_files/product_simple.php
124+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
126125
*/
127126
public function testMaxSendEmailToFriend()
128127
{
@@ -186,31 +185,19 @@ public function testMaxSendEmailToFriend()
186185
}
187186

188187
/**
189-
* @magentoApiDataFixture Magento/SendFriend/_files/product_simple.php
188+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
189+
* @dataProvider sendFriendsErrorsDataProvider
190+
* @param string $input
191+
* @param string $errorMessage
190192
*/
191-
public function testSendWithoutRecipientName()
193+
public function testErrors(string $input, string $errorMessage)
192194
{
193195
$query =
194196
<<<QUERY
195197
mutation {
196198
sendEmailToFriend(
197199
input: {
198-
product_id: 1
199-
sender: {
200-
name: "Name"
201-
email: "e@mail.com"
202-
message: "Lorem Ipsum"
203-
}
204-
recipients: [
205-
{
206-
name: ""
207-
email:"recipient1@mail.com"
208-
},
209-
{
210-
name: ""
211-
email:"recipient2@mail.com"
212-
}
213-
]
200+
$input
214201
}
215202
) {
216203
sender {
@@ -226,37 +213,44 @@ public function testSendWithoutRecipientName()
226213
}
227214
QUERY;
228215
$this->expectException(\Exception::class);
229-
$this->expectExceptionMessage('Please provide Name for all of recipients.');
216+
$this->expectExceptionMessage($errorMessage);
230217
$this->graphQlQuery($query);
231218
}
232219

233220
/**
234-
* @magentoApiDataFixture Magento/SendFriend/_files/product_simple.php
221+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
222+
* TODO: use magentoApiConfigFixture (to be merged https://github.com/magento/graphql-ce/pull/351)
223+
* @magentoApiDataFixture Magento/SendFriend/Fixtures/sendfriend_configuration.php
235224
*/
236-
public function testSendWithoutRecipientEmail()
225+
public function testLimitMessagesPerHour()
237226
{
227+
228+
/** @var SendFriend $sendFriend */
229+
$sendFriend = $this->sendFriendFactory->create();
230+
238231
$query =
239232
<<<QUERY
240233
mutation {
241234
sendEmailToFriend(
242235
input: {
243-
product_id: 1
236+
product_id: 1
244237
sender: {
245238
name: "Name"
246239
email: "e@mail.com"
247240
message: "Lorem Ipsum"
248-
}
241+
}
249242
recipients: [
250-
{
243+
{
251244
name: "Recipient Name 1"
252-
email:""
245+
email:"recipient1@mail.com"
253246
},
254-
{
247+
{
255248
name: "Recipient Name 2"
256-
email:""
257-
}
249+
email:"recipient2@mail.com"
250+
}
251+
258252
]
259-
}
253+
}
260254
) {
261255
sender {
262256
name
@@ -271,115 +265,63 @@ public function testSendWithoutRecipientEmail()
271265
}
272266
QUERY;
273267
$this->expectException(\Exception::class);
274-
$this->expectExceptionMessage('Please provide Email for all of recipients.');
275-
$this->graphQlQuery($query);
268+
$this->expectExceptionMessage(
269+
"You can't send messages more than {$sendFriend->getMaxSendsToFriend()} times an hour."
270+
);
271+
272+
for ($i = 0; $i <= $sendFriend->getMaxSendsToFriend() + 1; $i++) {
273+
$this->graphQlQuery($query);
274+
}
276275
}
277276

278277
/**
279-
* @magentoApiDataFixture Magento/SendFriend/_files/product_simple.php
278+
* @return array
280279
*/
281-
public function testSendWithoutSenderName()
280+
public function sendFriendsErrorsDataProvider()
282281
{
283-
$query =
284-
<<<QUERY
285-
mutation {
286-
sendEmailToFriend(
287-
input: {
288-
product_id: 1
289-
sender: {
290-
name: ""
282+
return [
283+
[
284+
'product_id: 1
285+
sender: {
286+
name: "Name"
291287
email: "e@mail.com"
292288
message: "Lorem Ipsum"
293289
}
294290
recipients: [
295291
{
296-
name: "Recipient Name 1"
292+
name: ""
297293
email:"recipient1@mail.com"
298294
},
299295
{
300-
name: "Recipient Name 2"
296+
name: ""
301297
email:"recipient2@mail.com"
302298
}
303-
]
304-
}
305-
) {
306-
sender {
307-
name
308-
email
309-
message
310-
}
311-
recipients {
312-
name
313-
email
314-
}
315-
}
316-
}
317-
QUERY;
318-
$this->expectException(\Exception::class);
319-
$this->expectExceptionMessage('Please provide Name of sender.');
320-
$this->graphQlQuery($query);
321-
}
322-
323-
/**
324-
* @magentoApiDataFixture Magento/SendFriend/_files/product_simple.php
325-
*/
326-
public function testSendWithoutSenderEmail()
327-
{
328-
$query =
329-
<<<QUERY
330-
mutation {
331-
sendEmailToFriend(
332-
input: {
333-
product_id: 1
299+
]', 'Please provide Name for all of recipients.'
300+
],
301+
[
302+
'product_id: 1
334303
sender: {
335304
name: "Name"
336-
email: ""
305+
email: "e@mail.com"
337306
message: "Lorem Ipsum"
338307
}
339308
recipients: [
340309
{
341310
name: "Recipient Name 1"
342-
email:"recipient1@mail.com"
311+
email:""
343312
},
344313
{
345314
name: "Recipient Name 2"
346-
email:"recipient2@mail.com"
315+
email:""
347316
}
348-
]
349-
}
350-
) {
351-
sender {
352-
name
353-
email
354-
message
355-
}
356-
recipients {
357-
name
358-
email
359-
}
360-
}
361-
}
362-
QUERY;
363-
$this->expectException(\Exception::class);
364-
$this->expectExceptionMessage('Please provide Email of sender.');
365-
$this->graphQlQuery($query);
366-
}
367-
368-
/**
369-
* @magentoApiDataFixture Magento/SendFriend/_files/product_simple.php
370-
*/
371-
public function testSendWithoutSenderMessage()
372-
{
373-
$query =
374-
<<<QUERY
375-
mutation {
376-
sendEmailToFriend(
377-
input: {
378-
product_id: 1
317+
]', 'Please provide Email for all of recipients.'
318+
],
319+
[
320+
'product_id: 1
379321
sender: {
380-
name: "Name"
322+
name: ""
381323
email: "e@mail.com"
382-
message: ""
324+
message: "Lorem Ipsum"
383325
}
384326
recipients: [
385327
{
@@ -390,79 +332,26 @@ public function testSendWithoutSenderMessage()
390332
name: "Recipient Name 2"
391333
email:"recipient2@mail.com"
392334
}
393-
]
394-
}
395-
) {
396-
sender {
397-
name
398-
email
399-
message
400-
}
401-
recipients {
402-
name
403-
email
404-
}
405-
}
406-
}
407-
QUERY;
408-
$this->expectException(\Exception::class);
409-
$this->expectExceptionMessage('Please provide Message.');
410-
$this->graphQlQuery($query);
411-
}
412-
413-
/**
414-
* @magentoApiDataFixture Magento/SendFriend/_files/product_simple.php
415-
* @magentoApiDataFixture Magento/SendFriend/Fixtures/sendfriend_configuration.php
416-
*/
417-
public function testLimitMessagesPerHour()
418-
{
419-
420-
/** @var SendFriend $sendFriend */
421-
$sendFriend = $this->sendFriendFactory->create();
422-
423-
$query =
424-
<<<QUERY
425-
mutation {
426-
sendEmailToFriend(
427-
input: {
428-
product_id: 1
335+
]', 'Please provide Name of sender.'
336+
],
337+
[
338+
'product_id: 1
429339
sender: {
430340
name: "Name"
431341
email: "e@mail.com"
432-
message: "Lorem Ipsum"
433-
}
342+
message: ""
343+
}
434344
recipients: [
435-
{
345+
{
436346
name: "Recipient Name 1"
437347
email:"recipient1@mail.com"
438348
},
439-
{
349+
{
440350
name: "Recipient Name 2"
441351
email:"recipient2@mail.com"
442-
}
443-
444-
]
445-
}
446-
) {
447-
sender {
448-
name
449-
email
450-
message
451-
}
452-
recipients {
453-
name
454-
email
455-
}
456-
}
457-
}
458-
QUERY;
459-
$this->expectException(\Exception::class);
460-
$this->expectExceptionMessage(
461-
"You can't send messages more than {$sendFriend->getMaxSendsToFriend()} times an hour."
462-
);
463-
464-
for ($i = 0; $i <= $sendFriend->getMaxSendsToFriend() + 1; $i++) {
465-
$this->graphQlQuery($query);
466-
}
352+
}
353+
]', 'Please provide Message.'
354+
]
355+
];
467356
}
468357
}

0 commit comments

Comments
 (0)