mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Basic test, no value.
This commit is contained in:
@@ -46,8 +46,6 @@ class UserControllerTest extends TestCase
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
self::markTestIncomplete('Incomplete for refactor.');
|
||||
return;
|
||||
parent::setUp();
|
||||
Passport::actingAs($this->user());
|
||||
$this->mockDefaultConfiguration();
|
||||
@@ -63,190 +61,7 @@ class UserControllerTest extends TestCase
|
||||
*/
|
||||
public function testStoreBasic(): void
|
||||
{
|
||||
$data = [
|
||||
'email' => 'some_new@user' . $this->randomInt() . '.com',
|
||||
];
|
||||
|
||||
// mock
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(UserTransformer::class);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->twice()->andReturn(true);
|
||||
$userRepos->shouldReceive('store')->once()->andReturn($this->user());
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// test API
|
||||
$response = $this->post(route('api.v1.users.store'), $data, ['Content-Type' => 'application/x-www-form-urlencoded']);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store new user using JSON.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\UserController
|
||||
* @covers \FireflyIII\Api\V1\Requests\UserStoreRequest
|
||||
*/
|
||||
public function testStoreBasicJson(): void
|
||||
{
|
||||
$data = [
|
||||
'email' => 'some_new@user' . $this->randomInt() . '.com',
|
||||
'blocked' => true,
|
||||
'blocked_code' => 'email_changed',
|
||||
];
|
||||
|
||||
// mock
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(UserTransformer::class);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->twice()->andReturn(true);
|
||||
$userRepos->shouldReceive('store')->once()->andReturn($this->user());
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// test API
|
||||
$response = $this->postJson('/api/v1/users', $data, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store user with info already used.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\UserController
|
||||
* @covers \FireflyIII\Api\V1\Requests\UserStoreRequest
|
||||
*/
|
||||
public function testStoreNotUnique(): void
|
||||
{
|
||||
$data = [
|
||||
'email' => $this->user()->email,
|
||||
'blocked' => 0,
|
||||
];
|
||||
|
||||
// mock
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->twice()->andReturn(true);
|
||||
// test API
|
||||
$response = $this->post(route('api.v1.users.store'), $data, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(422);
|
||||
$response->assertExactJson(
|
||||
[
|
||||
'message' => 'The given data was invalid.',
|
||||
'errors' => [
|
||||
'email' => [
|
||||
'The email address has already been taken.',
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store user with info already used.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\UserController
|
||||
* @covers \FireflyIII\Api\V1\Requests\UserStoreRequest
|
||||
*/
|
||||
public function testStoreNotUniqueJson(): void
|
||||
{
|
||||
$data = [
|
||||
'email' => $this->user()->email,
|
||||
'blocked' => 0,
|
||||
];
|
||||
|
||||
// mock
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->twice()->andReturn(true);
|
||||
// test API
|
||||
$response = $this->postJson('/api/v1/users', $data, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(422);
|
||||
$response->assertExactJson(
|
||||
[
|
||||
'message' => 'The given data was invalid.',
|
||||
'errors' => [
|
||||
'email' => [
|
||||
'The email address has already been taken.',
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\UserController
|
||||
* @covers \FireflyIII\Api\V1\Requests\UserStoreRequest
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
// create a user first:
|
||||
$user = User::create(['email' => 'some@newu' . $this->randomInt() . 'ser.nl', 'password' => 'hello', 'blocked' => 0]);
|
||||
|
||||
// data:
|
||||
$data = [
|
||||
'email' => 'some-new@email' . $this->randomInt() . '.com',
|
||||
'blocked' => 0,
|
||||
];
|
||||
|
||||
// mock
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(UserTransformer::class);
|
||||
$userRepos->shouldReceive('update')->once()->andReturn($user);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->twice()->andReturn(true);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// call API
|
||||
$response = $this->put(route('api.v1.users.update', $user->id), $data, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\UserController
|
||||
* @covers \FireflyIII\Api\V1\Requests\UserStoreRequest
|
||||
*/
|
||||
public function testUpdateJson(): void
|
||||
{
|
||||
// create a user first:
|
||||
$user = User::create(['email' => 'some@newu' . $this->randomInt() . 'ser.nl', 'password' => 'hello', 'blocked' => 0]);
|
||||
|
||||
// data:
|
||||
$data = [
|
||||
'email' => 'some-new@email' . $this->randomInt() . '.com',
|
||||
'blocked' => 0,
|
||||
];
|
||||
|
||||
// mock
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(UserTransformer::class);
|
||||
$userRepos->shouldReceive('update')->once()->andReturn($user);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->twice()->andReturn(true);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// call API
|
||||
$response = $this->putJson('/api/v1/users/' . $user->id, $data, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(200);
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user