Skip to content

Instantly share code, notes, and snippets.

@tiggreen
Created March 24, 2018 13:29
Show Gist options
  • Save tiggreen/637f6bf824f4b7d939ea21078ced01b6 to your computer and use it in GitHub Desktop.
Save tiggreen/637f6bf824f4b7d939ea21078ced01b6 to your computer and use it in GitHub Desktop.
<?php
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
class SettingsTest extends TestCase
{
use DatabaseTransactions;
public function setUp()
{
parent::setUp();
$this->user = factory(App\User::class)->create([
'enrolled_weekly_report' => false,
]);
$this->user2 = factory(App\User::class)->create();
}
public function test_users_can_update_their_settings()
{
$this->actingAs($this->user, 'api');
$response = $this->json('PUT', '/api/settings/user', [
'name' => 'Changed User Test',
'email' => 'changedtester@gmail.com'
]);
$response->assertStatus(200);
$response->assertJsonFragment([
'name' => 'Changed User Test',
'email' => 'changedtester@gmail.com',
]);
$this->assertDatabaseHas('users', [
'name' => 'Changed User Test',
'email' => 'changedtester@gmail.com',
]);
}
public function test_settings_update_email_always_required()
{
$this->actingAs($this->user, 'api');
$response = $this->json('PUT', '/api/settings/user', [
'name' => 'Changed User Test',
'email' => ''
]);
$response->assertStatus(422);
}
public function test_email_should_always_be_unique()
{
$this->actingAs($this->user, 'api');
$response = $this->json('PUT', '/api/settings/user', [
'name' => 'Changed User Test',
'email' => $this->user2->email
]);
$response->assertJsonFragment([
'message' => 'The given data was invalid.',
]);
$response->assertStatus(422);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment