Tests for users

This commit is contained in:
David Bomba 2023-08-12 16:21:06 +10:00
parent a847bdb0ed
commit 0f931fe1a8
2 changed files with 48 additions and 15 deletions

View File

@ -127,8 +127,7 @@ class UserFilters extends QueryFilters
$user_array = $this->transformKeys(explode(',', $user_id));
return $this->builder->where(function ($query) use ($user_array) {
$query->whereNotIn('id', $user_array)
->where('account_id', auth()->user()->account_id);
$query->whereNotIn('id', $user_array);
});
}
}

View File

@ -142,29 +142,63 @@ class UserTest extends TestCase
'X-API-PASSWORD' => 'ALongAndBriliantPassword',
])->get('/api/v1/users', $data);
$response->assertStatus(200);
$arr = $response->json();
$this->assertCount(2, $arr['data']);
//archive the user we just created:
//archive the user we just created:
$data = [
'action' => 'archive',
'ids' => [$user_id],
];
$data = [
'action' => 'archive',
'ids' => [$user_id],
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $company_token->token,
'X-API-PASSWORD' => 'ALongAndBriliantPassword',
])->postJson('/api/v1/users/bulk', $data);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $company_token->token,
'X-API-PASSWORD' => 'ALongAndBriliantPassword',
])->postJson('/api/v1/users/bulk', $data);
$response->assertStatus(200);
$response->assertStatus(200);
$this->assertCount(1, $response->json()['data']);
$this->assertCount(1, $response->json()['data']);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $company_token->token,
'X-API-PASSWORD' => 'ALongAndBriliantPassword',
])->get("/api/v1/users?without={$company_token->user->hashed_id}");
$response->assertStatus(200);
$this->assertCount(1, $response->json()['data']);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $company_token->token,
'X-API-PASSWORD' => 'ALongAndBriliantPassword',
])->get("/api/v1/users?without={$company_token->user->hashed_id}&status=active");
$response->assertStatus(200);
$this->assertCount(0, $response->json()['data']);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $company_token->token,
'X-API-PASSWORD' => 'ALongAndBriliantPassword',
])->get("/api/v1/users?without={$company_token->user->hashed_id}&status=archived");
$response->assertStatus(200);
$this->assertCount(1, $response->json()['data']);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $company_token->token,
'X-API-PASSWORD' => 'ALongAndBriliantPassword',
])->get("/api/v1/users?without={$company_token->user->hashed_id}&status=deleted");
$response->assertStatus(200);
$this->assertCount(0, $response->json()['data']);
}