mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-11-22 08:13:11 +01:00
Fix phpunit tests
This commit is contained in:
parent
893f29849e
commit
0374bc4994
@ -99,23 +99,6 @@ protected static function boot()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
@ -176,64 +176,31 @@ public function testMoveAccountsToGroup()
|
||||
$response = $this->actingAs($this->user, 'api')
|
||||
->json('GET', '/api/twofaccounts/1')
|
||||
->assertJsonFragment([
|
||||
'group_id' => (string) $this->group->id
|
||||
'group_id' => $this->group->id
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($this->user, 'api')
|
||||
->json('GET', '/api/twofaccounts/2')
|
||||
->assertJsonFragment([
|
||||
'group_id' => (string) $this->group->id
|
||||
'group_id' => $this->group->id
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($this->user, 'api')
|
||||
->json('GET', '/api/twofaccounts/3')
|
||||
->assertJsonFragment([
|
||||
'group_id' => (string) $this->group->id
|
||||
'group_id' => $this->group->id
|
||||
]);
|
||||
|
||||
// test the accounts count of the user group
|
||||
$response = $this->actingAs($this->user, 'api')
|
||||
->json('GET', '/api/groups')
|
||||
->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
|
||||
*
|
||||
@ -284,8 +251,8 @@ public function testMoveAccountsToPseudoGroup()
|
||||
$response = $this->actingAs($this->user, 'api')
|
||||
->json('GET', '/api/groups')
|
||||
->assertJsonFragment([
|
||||
'twofaccounts_count' => '3', // the 3 accounts for 'all'
|
||||
'twofaccounts_count' => '2' // the 2 accounts that remain in the user group
|
||||
'twofaccounts_count' => 3, // the 3 accounts for 'all'
|
||||
'twofaccounts_count' => 2 // the 2 accounts that remain in the user group
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -32,7 +32,7 @@ public function testExistingUserCount()
|
||||
$response = $this->json('POST', '/api/checkuser')
|
||||
->assertStatus(200)
|
||||
->assertJson([
|
||||
'userCount' => '1',
|
||||
'username' => $this->user->name,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ public function testUserCreationWithAnExistingUser()
|
||||
'password_confirmation' => 'test',
|
||||
]);
|
||||
|
||||
$response->assertStatus(400);
|
||||
$response->assertStatus(422);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user