Page MenuHomePhorge

CompanionAppsTest.php
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

CompanionAppsTest.php

<?php
namespace Tests\Feature\Controller;
use App\User;
use App\CompanionApp;
use Tests\TestCase;
class CompanionAppsTest extends TestCase
{
/**
* {@inheritDoc}
*/
public function setUp(): void
{
parent::setUp();
$this->deleteTestUser('UsersControllerTest1@userscontroller.com');
$this->deleteTestDomain('userscontroller.com');
}
/**
* {@inheritDoc}
*/
public function tearDown(): void
{
$this->deleteTestUser('UsersControllerTest1@userscontroller.com');
$this->deleteTestDomain('userscontroller.com');
parent::tearDown();
}
/**
* Test registering the app
*/
public function testRegister(): void
{
$user = $this->getTestUser('CompanionAppsTest1@userscontroller.com');
$notificationToken = "notificationToken";
$deviceId = "deviceId";
$response = $this->actingAs($user)->post(
"api/v4/companion/register",
['notificationToken' => $notificationToken, 'deviceId' => $deviceId]
);
$response->assertStatus(200);
$companionApp = \App\CompanionApp::where('device_id', $deviceId)->first();
$this->assertTrue($companionApp != null);
$this->assertEquals($deviceId, $companionApp->device_id);
$this->assertEquals($notificationToken, $companionApp->notification_token);
// Test a token update
$notificationToken = "notificationToken2";
$response = $this->actingAs($user)->post(
"api/v4/companion/register",
['notificationToken' => $notificationToken, 'deviceId' => $deviceId]
);
$response->assertStatus(200);
$companionApp->refresh();
$this->assertEquals($notificationToken, $companionApp->notification_token);
// Failing input valdiation
$response = $this->actingAs($user)->post(
"api/v4/companion/register",
[]
);
$response->assertStatus(422);
// Other users device
$user2 = $this->getTestUser('CompanionAppsTest2@userscontroller.com');
$response = $this->actingAs($user2)->post(
"api/v4/companion/register",
['notificationToken' => $notificationToken, 'deviceId' => $deviceId]
);
$response->assertStatus(403);
}
}

File Metadata

Mime Type
text/x-php
Expires
Fri, Apr 24, 1:16 PM (3 d, 10 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
12/da/0705aafe22eef2aedc033eb6267b
Default Alt Text
CompanionAppsTest.php (2 KB)

Event Timeline