TwoFAccountImportRequestTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace Tests\Api\v1\Requests;
  3. use App\Api\v1\Requests\TwoFAccountImportRequest;
  4. use Illuminate\Foundation\Testing\WithoutMiddleware;
  5. use Illuminate\Support\Facades\Auth;
  6. use Illuminate\Support\Facades\Validator;
  7. use Tests\TestCase;
  8. /**
  9. * @covers \App\Api\v1\Requests\TwoFAccountImportRequest
  10. */
  11. class TwoFAccountImportRequestTest extends TestCase
  12. {
  13. use WithoutMiddleware;
  14. /**
  15. * @test
  16. */
  17. public function test_user_is_authorized()
  18. {
  19. Auth::shouldReceive('check')
  20. ->once()
  21. ->andReturn(true);
  22. $request = new TwoFAccountImportRequest();
  23. $this->assertTrue($request->authorize());
  24. }
  25. /**
  26. * @dataProvider provideValidData
  27. */
  28. public function test_valid_data(array $data): void
  29. {
  30. $request = new TwoFAccountImportRequest();
  31. $validator = Validator::make($data, $request->rules());
  32. $this->assertFalse($validator->fails());
  33. }
  34. /**
  35. * Provide Valid data for validation test
  36. */
  37. public function provideValidData(): array
  38. {
  39. return [
  40. [[
  41. 'payload' => 'otpauth-migration://offline?data=AEoATACEAEYASAA',
  42. ]],
  43. ];
  44. }
  45. /**
  46. * @dataProvider provideInvalidData
  47. */
  48. public function test_invalid_data(array $data): void
  49. {
  50. $request = new TwoFAccountImportRequest();
  51. $validator = Validator::make($data, $request->rules());
  52. $this->assertTrue($validator->fails());
  53. }
  54. /**
  55. * Provide invalid data for validation test
  56. */
  57. public function provideInvalidData(): array
  58. {
  59. return [
  60. [[
  61. 'payload' => null, // required
  62. ]],
  63. [[
  64. 'payload' => '', // required
  65. ]],
  66. [[
  67. 'payload' => true, // string
  68. ]],
  69. [[
  70. 'payload' => 8, // string
  71. ]],
  72. ];
  73. }
  74. }