Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-26 #27

Merged
merged 4 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
echo "TIMESTAMP_START=$(date +'%s')" >> $GITHUB_OUTPUT
- name: "Slack notification: IN PROGRESS"
id: slack
uses: slackapi/slack-github-action@v1.24.0
uses: slackapi/slack-github-action@v1.25.0
with:
channel-id: 'C068A06PV43'
payload: |
Expand Down Expand Up @@ -131,7 +131,7 @@ jobs:
echo "DATE_END=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_OUTPUT
echo "DURATION_PHRASE=$(($(date +'%s')-$TIMESTAMP_START)) seconds" >> $GITHUB_OUTPUT
- name: "Slack notification: Done"
uses: slackapi/slack-github-action@v1.24.0
uses: slackapi/slack-github-action@v1.25.0
with:
channel-id: 'C068A06PV43'
update-ts: ${{ steps.slack.outputs.ts }}
Expand Down Expand Up @@ -192,7 +192,7 @@ jobs:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
- name: "Send a notification for failures"
if: ${{ failure() }}
uses: slackapi/slack-github-action@v1.24.0
uses: slackapi/slack-github-action@v1.25.0
with:
channel-id: 'C068A06PV43'
update-ts: ${{ steps.slack.outputs.ts }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
*/
trait CreateJsonTrait
{
protected int $status_code_json_guest_create = 403;

protected string $create_info_parameter = 'owned_by_id';

protected string $create_info_invalid_value = '[duck]';

/**
* @return class-string<Model>
*/
Expand Down Expand Up @@ -39,7 +45,7 @@ public function test_json_guest_cannot_get_create_info()
$response = $this->getJson($url);
// $response->dump();

$response->assertStatus(403);
$response->assertStatus($this->status_code_json_guest_create);
}

public function test_json_admin_can_get_create_info()
Expand Down Expand Up @@ -73,9 +79,12 @@ public function test_json_get_create_info_as_admin_with_invalid_parameter_and_fa
$packageInfo['model_route']
));

$response = $this->actingAs($user)
->from($url)
->getJson($url.'?owned_by_id=[duck]');
$response = $this->actingAs($user)->from($url)->getJson(sprintf(
'%1$s?%2$s=%3$s',
$url,
$this->create_info_parameter,
$this->create_info_invalid_value
));

$this->assertAuthenticated();

Expand All @@ -85,6 +94,6 @@ public function test_json_get_create_info_as_admin_with_invalid_parameter_and_fa
'errors',
]);

$response->assertJsonValidationErrorFor('owned_by_id');
$response->assertJsonValidationErrorFor($this->create_info_parameter);
}
}
20 changes: 15 additions & 5 deletions src/Feature/Http/Controllers/Resource/Playground/CreateTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
*/
trait CreateTrait
{
protected int $status_code_guest_create = 403;

protected string $create_form_parameter = 'owned_by_id';

protected string $create_form_invalid_value = '[duck]';

/**
* @return class-string<Model>
*/
Expand All @@ -32,7 +38,8 @@ public function test_guest_cannot_render_create_view()
));

$response = $this->get($url);
$response->assertStatus(403);

$response->assertStatus($this->status_code_guest_create);
}

public function test_admin_can_render_create_view()
Expand Down Expand Up @@ -91,9 +98,12 @@ public function test_create_view_as_admin_with_invalid_parameter_and_fail_valida
$packageInfo['model_route']
));

$response = $this->actingAs($user)
->from($url)
->get($url.'?owned_by_id=[duck]');
$response = $this->actingAs($user)->from($url)->get(sprintf(
'%1$s?%2$s=%3$s',
$url,
$this->create_form_parameter,
$this->create_form_invalid_value
));

// $response->dump();
// $response->dumpHeaders();
Expand All @@ -102,7 +112,7 @@ public function test_create_view_as_admin_with_invalid_parameter_and_fail_valida

// // The owned by id field must be a valid UUID.
$response->assertSessionHasErrors([
'owned_by_id',
$this->create_form_parameter,
]);

$this->assertAuthenticated();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
*/
trait DestroyJsonTrait
{
protected int $status_code_json_guest_destroy = 403;

protected int $status_code_json_user_destroy = 401;

/**
* @return class-string<Model>
*/
Expand All @@ -32,7 +36,6 @@ public function test_json_guest_cannot_destroy()

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => null,
'deleted_at' => null,
]);

Expand All @@ -45,11 +48,10 @@ public function test_json_guest_cannot_destroy()

$response = $this->deleteJson($url);

$response->assertStatus(403);
$response->assertStatus($this->status_code_json_guest_destroy);

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => null,
'deleted_at' => null,
]);
}
Expand All @@ -62,13 +64,10 @@ public function test_json_destroy_as_admin_and_succeed()

$user = User::factory()->admin()->create();

$model = $fqdn::factory()->create([
'owned_by_id' => $user->id,
]);
$model = $fqdn::factory()->create();

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
'deleted_at' => null,
]);

Expand All @@ -88,11 +87,9 @@ public function test_json_destroy_as_admin_and_succeed()

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
]);
$this->assertDatabaseMissing($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
'deleted_at' => null,
]);
$response->assertNoContent();
Expand All @@ -106,13 +103,10 @@ public function test_json_destroy_as_admin_and_succeed_with_force_delete()

$user = User::factory()->admin()->create();

$model = $fqdn::factory()->create([
'owned_by_id' => $user->id,
]);
$model = $fqdn::factory()->create();

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
'deleted_at' => null,
]);

Expand Down Expand Up @@ -141,13 +135,10 @@ public function test_json_destroy_as_admin_and_succeed_with_no_content()

$user = User::factory()->admin()->create();

$model = $fqdn::factory()->create([
'owned_by_id' => $user->id,
]);
$model = $fqdn::factory()->create();

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
'deleted_at' => null,
]);

Expand All @@ -162,11 +153,9 @@ public function test_json_destroy_as_admin_and_succeed_with_no_content()

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
]);
$this->assertDatabaseMissing($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
'deleted_at' => null,
]);

Expand All @@ -181,13 +170,10 @@ public function test_json_destroy_as_admin_and_succeed_and_ignore_redirect()

$user = User::factory()->admin()->create();

$model = $fqdn::factory()->create([
'owned_by_id' => $user->id,
]);
$model = $fqdn::factory()->create();

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
'deleted_at' => null,
]);

Expand All @@ -209,11 +195,9 @@ public function test_json_destroy_as_admin_and_succeed_and_ignore_redirect()

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
]);
$this->assertDatabaseMissing($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
'deleted_at' => null,
]);

Expand All @@ -228,13 +212,10 @@ public function test_json_destroy_as_user_and_get_denied_and_no_force_delete_all

$user = User::factory()->create();

$model = $fqdn::factory()->create([
'owned_by_id' => $user->id,
]);
$model = $fqdn::factory()->create();

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
'deleted_at' => null,
]);

Expand All @@ -248,11 +229,10 @@ public function test_json_destroy_as_user_and_get_denied_and_no_force_delete_all

$response = $this->actingAs($user)->deleteJson($url);

$response->assertStatus(401);
$response->assertStatus($this->status_code_json_user_destroy);

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
'deleted_at' => null,
]);
}
Expand Down
Loading
Loading