ContactUsTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace Webkul\BagistoApi\Tests\Feature\GraphQL;
  3. use Webkul\BagistoApi\Tests\GraphQLTestCase;
  4. class ContactUsTest extends GraphQLTestCase
  5. {
  6. /**
  7. * Create Contact Us - Basic
  8. *
  9. * This mutation does not require authentication - it is available to all visitors
  10. */
  11. public function test_create_contact_us_basic(): void
  12. {
  13. $query = <<<'GQL'
  14. mutation createContactUs($input: createContactUsInput!) {
  15. createContactUs(input: $input) {
  16. contactUs {
  17. success
  18. message
  19. }
  20. }
  21. }
  22. GQL;
  23. $variables = [
  24. 'input' => [
  25. 'name' => 'John Doe',
  26. 'email' => 'john@example.com',
  27. 'contact' => '+1234567890',
  28. 'message' => 'I have a question about your products'
  29. ]
  30. ];
  31. $response = $this->graphQL($query, $variables);
  32. $response->assertSuccessful();
  33. $this->assertArrayHasKey('data', $response->json());
  34. $this->assertArrayHasKey('createContactUs', $response->json('data'));
  35. $this->assertArrayHasKey('contactUs', $response->json('data.createContactUs'));
  36. $contactUs = $response->json('data.createContactUs.contactUs');
  37. $this->assertTrue($contactUs['success'], 'Contact Us submission should be successful');
  38. $this->assertEquals(
  39. 'Your message has been submitted successfully. We will get back to you shortly.',
  40. $contactUs['message']
  41. );
  42. }
  43. /**
  44. * Create Contact Us - With Client Mutation ID
  45. *
  46. * This mutation does not require authentication - it is available to all visitors
  47. */
  48. public function test_create_contact_us_with_client_mutation_id(): void
  49. {
  50. $query = <<<'GQL'
  51. mutation createContactUs($input: createContactUsInput!) {
  52. createContactUs(input: $input) {
  53. contactUs {
  54. success
  55. message
  56. }
  57. clientMutationId
  58. }
  59. }
  60. GQL;
  61. $variables = [
  62. 'input' => [
  63. 'name' => 'Jane Smith',
  64. 'email' => 'jane.smith@example.com',
  65. 'contact' => '+0987654321',
  66. 'message' => 'I would like to inquire about bulk order discounts for your clothing range.',
  67. 'clientMutationId' => 'contact-form-001'
  68. ]
  69. ];
  70. $response = $this->graphQL($query, $variables);
  71. $response->assertSuccessful();
  72. $this->assertArrayHasKey('data', $response->json());
  73. $this->assertArrayHasKey('createContactUs', $response->json('data'));
  74. $this->assertArrayHasKey('contactUs', $response->json('data.createContactUs'));
  75. $this->assertArrayHasKey('clientMutationId', $response->json('data.createContactUs'));
  76. $contactUs = $response->json('data.createContactUs.contactUs');
  77. $this->assertTrue($contactUs['success'], 'Contact Us submission should be successful');
  78. $this->assertEquals(
  79. 'Your message has been submitted successfully. We will get back to you shortly.',
  80. $contactUs['message']
  81. );
  82. // Verify clientMutationId is returned correctly
  83. $this->assertEquals(
  84. 'contact-form-001',
  85. $response->json('data.createContactUs.clientMutationId')
  86. );
  87. }
  88. }