Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/CompanionAppsTest.php
Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | public function testRegister(): void | ||||
// Other users device | // Other users device | ||||
$user2 = $this->getTestUser('CompanionAppsTest2@userscontroller.com'); | $user2 = $this->getTestUser('CompanionAppsTest2@userscontroller.com'); | ||||
$response = $this->actingAs($user2)->post( | $response = $this->actingAs($user2)->post( | ||||
"api/v4/companion/register", | "api/v4/companion/register", | ||||
['notificationToken' => $notificationToken, 'deviceId' => $deviceId] | ['notificationToken' => $notificationToken, 'deviceId' => $deviceId] | ||||
); | ); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
} | } | ||||
public function testIndex(): void | |||||
{ | |||||
$response = $this->get("api/v4/companion"); | |||||
$response->assertStatus(401); | |||||
$user = $this->getTestUser('CompanionAppsTest1@userscontroller.com'); | |||||
machniak: This user should be deleted in setUp() and tearDown(). | |||||
$response = $this->actingAs($user)->get("api/v4/companion"); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertSame(1, $json['count']); | |||||
$this->assertCount(1, $json['list']); | |||||
$this->assertSame($user->id, $json['list'][0]['user_id']); | |||||
$this->assertSame('deviceId', $json['list'][0]['device_id']); | |||||
$this->assertSame('notificationToken2', $json['list'][0]['notification_token']); | |||||
$this->assertSame(1, $json['list'][0]['mfa_enabled']); | |||||
$user2 = $this->getTestUser('CompanionAppsTest2@userscontroller.com'); | |||||
machniakUnsubmitted Done Inline ActionsThis user should be deleted in setUp() and tearDown(). machniak: This user should be deleted in setUp() and tearDown(). | |||||
$response = $this->actingAs($user2)->get( | |||||
"api/v4/companion" | |||||
); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertSame(0, $json['count']); | |||||
$this->assertCount(0, $json['list']); | |||||
} | |||||
public function testShow(): void | |||||
{ | |||||
$companionApp = \App\CompanionApp::where('device_id', 'deviceId')->first(); | |||||
$response = $this->get("api/v4/companion/{$companionApp->id}"); | |||||
$response->assertStatus(401); | |||||
$user = $this->getTestUser('CompanionAppsTest1@userscontroller.com'); | |||||
$response = $this->actingAs($user)->get("api/v4/companion/aaa"); | |||||
machniakUnsubmitted Done Inline ActionsI miss a test for 403 case. machniak: I miss a test for 403 case. | |||||
$response->assertStatus(404); | |||||
$response = $this->actingAs($user)->get("api/v4/companion/{$companionApp->id}"); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertSame($companionApp->id, $json['id']); | |||||
} | |||||
public function testPairingInfo(): void | |||||
machniakUnsubmitted Done Inline ActionsJust testPairing. machniak: Just `testPairing`. | |||||
{ | |||||
$response = $this->get("api/v4/companion/pairing"); | |||||
$response->assertStatus(401); | |||||
$user = $this->getTestUser('CompanionAppsTest1@userscontroller.com'); | |||||
$response = $this->actingAs($user)->get("api/v4/companion/pairing"); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertArrayHasKey('qrcode', $json); | |||||
machniakUnsubmitted Done Inline ActionsWe should test that it is a data: URI. Maybe even also that it is a valid image content. machniak: We should test that it is a `data:` URI. Maybe even also that it is a valid image content. | |||||
} | |||||
} | } |
This user should be deleted in setUp() and tearDown().