mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-06-20 11:47:53 +02:00
Fix phpunit tests
This commit is contained in:
parent
893f29849e
commit
0374bc4994
@ -99,23 +99,6 @@ class TwoFAccount extends Model implements Sortable
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Scope a query to only include TwoFAccounts of a given group.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
|
||||||
* @param mixed $groupId
|
|
||||||
* @return \Illuminate\Database\Eloquent\Builder
|
|
||||||
*/
|
|
||||||
public function scopeOfGroup($query, $groupId)
|
|
||||||
{
|
|
||||||
if( $groupId ) {
|
|
||||||
return $query->where('group_id', $groupId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $query;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sortable settings
|
* Sortable settings
|
||||||
*
|
*
|
||||||
|
@ -176,64 +176,31 @@ class AccountsGroupTest extends TestCase
|
|||||||
$response = $this->actingAs($this->user, 'api')
|
$response = $this->actingAs($this->user, 'api')
|
||||||
->json('GET', '/api/twofaccounts/1')
|
->json('GET', '/api/twofaccounts/1')
|
||||||
->assertJsonFragment([
|
->assertJsonFragment([
|
||||||
'group_id' => (string) $this->group->id
|
'group_id' => $this->group->id
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response = $this->actingAs($this->user, 'api')
|
$response = $this->actingAs($this->user, 'api')
|
||||||
->json('GET', '/api/twofaccounts/2')
|
->json('GET', '/api/twofaccounts/2')
|
||||||
->assertJsonFragment([
|
->assertJsonFragment([
|
||||||
'group_id' => (string) $this->group->id
|
'group_id' => $this->group->id
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response = $this->actingAs($this->user, 'api')
|
$response = $this->actingAs($this->user, 'api')
|
||||||
->json('GET', '/api/twofaccounts/3')
|
->json('GET', '/api/twofaccounts/3')
|
||||||
->assertJsonFragment([
|
->assertJsonFragment([
|
||||||
'group_id' => (string) $this->group->id
|
'group_id' => $this->group->id
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// test the accounts count of the user group
|
// test the accounts count of the user group
|
||||||
$response = $this->actingAs($this->user, 'api')
|
$response = $this->actingAs($this->user, 'api')
|
||||||
->json('GET', '/api/groups')
|
->json('GET', '/api/groups')
|
||||||
->assertJsonFragment([
|
->assertJsonFragment([
|
||||||
'twofaccounts_count' => '3'
|
'twofaccounts_count' => 3
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* test 2FAccounts are scoped when an active group is set via API
|
|
||||||
*
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function testScopedAccounts()
|
|
||||||
{
|
|
||||||
// Set the default group to the existing one
|
|
||||||
$response = $this->actingAs($this->user, 'api')
|
|
||||||
->json('POST', '/api/settings/options', [
|
|
||||||
'activeGroup' => $this->group->id,
|
|
||||||
])
|
|
||||||
->assertStatus(200);
|
|
||||||
|
|
||||||
// We associate 2 accounts to the group
|
|
||||||
$response = $this->actingAs($this->user, 'api')
|
|
||||||
->json('PATCH', '/api/group/accounts/', [
|
|
||||||
'groupId' => $this->group->id,
|
|
||||||
'accountsIds' => [1,2]
|
|
||||||
])
|
|
||||||
->assertStatus(200);
|
|
||||||
|
|
||||||
// Test accounts index is scoped with active group
|
|
||||||
$response = $this->actingAs($this->user, 'api')
|
|
||||||
->json('GET', '/api/twofaccounts')
|
|
||||||
->assertJsonCount(2)
|
|
||||||
->assertJsonFragment([
|
|
||||||
'id' => 1,
|
|
||||||
'id' => 2
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test 2FAccounts association with a missing group via API
|
* test 2FAccounts association with a missing group via API
|
||||||
*
|
*
|
||||||
@ -284,8 +251,8 @@ class AccountsGroupTest extends TestCase
|
|||||||
$response = $this->actingAs($this->user, 'api')
|
$response = $this->actingAs($this->user, 'api')
|
||||||
->json('GET', '/api/groups')
|
->json('GET', '/api/groups')
|
||||||
->assertJsonFragment([
|
->assertJsonFragment([
|
||||||
'twofaccounts_count' => '3', // the 3 accounts for 'all'
|
'twofaccounts_count' => 3, // the 3 accounts for 'all'
|
||||||
'twofaccounts_count' => '2' // the 2 accounts that remain in the user group
|
'twofaccounts_count' => 2 // the 2 accounts that remain in the user group
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ class RegisterTest extends TestCase
|
|||||||
$response = $this->json('POST', '/api/checkuser')
|
$response = $this->json('POST', '/api/checkuser')
|
||||||
->assertStatus(200)
|
->assertStatus(200)
|
||||||
->assertJson([
|
->assertJson([
|
||||||
'userCount' => '1',
|
'username' => $this->user->name,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ class RegisterTest extends TestCase
|
|||||||
'password_confirmation' => 'test',
|
'password_confirmation' => 'test',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response->assertStatus(400);
|
$response->assertStatus(422);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user