Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
682da3dea8 |
@@ -37,7 +37,7 @@ class PredefinedMutationController extends Controller
|
|||||||
$request->validate([
|
$request->validate([
|
||||||
'name' => ['required', 'string', 'max:255'],
|
'name' => ['required', 'string', 'max:255'],
|
||||||
'description' => ['nullable', 'string'],
|
'description' => ['nullable', 'string'],
|
||||||
'amount' => ['required', 'integer', 'not_in:0', 'min:-1000', 'max:1000'],
|
'amount' => ['required', 'integer'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$ledger->predefinedMutations()->create($request->all());
|
$ledger->predefinedMutations()->create($request->all());
|
||||||
@@ -69,7 +69,7 @@ class PredefinedMutationController extends Controller
|
|||||||
$request->validate([
|
$request->validate([
|
||||||
'name' => ['required', 'string', 'max:255'],
|
'name' => ['required', 'string', 'max:255'],
|
||||||
'description' => ['nullable', 'string'],
|
'description' => ['nullable', 'string'],
|
||||||
'amount' => ['required', 'integer', 'not_in:0', 'min:-1000', 'max:1000'],
|
'amount' => ['required', 'integer'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$predefinedMutation->update($request->all());
|
$predefinedMutation->update($request->all());
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class StoreMutationRequest extends FormRequest
|
|||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'amount' => ['required', 'integer', 'not_in:0', 'min:-1000', 'max:1000'],
|
'amount' => ['required', 'integer'],
|
||||||
'description' => ['required', 'string'],
|
'description' => ['required', 'string'],
|
||||||
'type' => ['nullable', 'string'],
|
'type' => ['nullable', 'string'],
|
||||||
'status' => ['nullable', 'string'],
|
'status' => ['nullable', 'string'],
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use Carbon\CarbonImmutable;
|
use Carbon\CarbonImmutable;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||||
use Illuminate\Http\Resources\Json\JsonResource;
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
use Illuminate\Support\Facades\Date;
|
use Illuminate\Support\Facades\Date;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
@@ -26,6 +27,13 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
{
|
{
|
||||||
JsonResource::withoutWrapping();
|
JsonResource::withoutWrapping();
|
||||||
$this->configureDefaults();
|
$this->configureDefaults();
|
||||||
|
|
||||||
|
Relation::morphMap([
|
||||||
|
'user' => \App\Models\User::class,
|
||||||
|
'dynamic' => \App\Models\Dynamic::class,
|
||||||
|
'ledger' => \App\Models\Ledger::class,
|
||||||
|
'mutation' => \App\Models\Mutation::class,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('messages', function (Blueprint $table) {
|
||||||
|
DB::table('messages')->where('subject_type', 'App\\Models\\User')->update(['subject_type' => 'user']);
|
||||||
|
DB::table('messages')->where('subject_type', 'App\\Models\\Mutation')->update(['subject_type' => 'mutation']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('messages', function (Blueprint $table) {
|
||||||
|
DB::table('messages')->where('subject_type', 'user')->update(['subject_type' => 'App\\Models\\User']);
|
||||||
|
DB::table('messages')->where('subject_type', 'mutation')->update(['subject_type' => 'App\\Models\\Mutation']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -202,16 +202,16 @@ function parseMessageContent(message: {
|
|||||||
// 2. Link subjects if found in the text
|
// 2. Link subjects if found in the text
|
||||||
if (message.subject_id && message.subject_type) {
|
if (message.subject_id && message.subject_type) {
|
||||||
if (
|
if (
|
||||||
message.subject_type === 'App\\Models\\Mutation' ||
|
message.subject_type === 'mutation' ||
|
||||||
message.subject_type === 'App\\Models\\Ledger'
|
message.subject_type === 'ledger'
|
||||||
) {
|
) {
|
||||||
const ledgerId =
|
const ledgerId =
|
||||||
message.subject_type === 'App\\Models\\Mutation'
|
message.subject_type === 'mutation'
|
||||||
? message.subject?.ledger_id
|
? message.subject?.ledger_id
|
||||||
: message.subject?.id;
|
: message.subject?.id;
|
||||||
|
|
||||||
const ledgerName =
|
const ledgerName =
|
||||||
message.subject_type === 'App\\Models\\Mutation'
|
message.subject_type === 'mutation'
|
||||||
? message.subject?.ledger?.name
|
? message.subject?.ledger?.name
|
||||||
: message.subject?.name;
|
: message.subject?.name;
|
||||||
|
|
||||||
|
|||||||
@@ -121,54 +121,3 @@ test('owner can approve a pending suggestion and it is updated and logged', func
|
|||||||
expect($dynamicChatMessages->last()->user_id)->toBeNull();
|
expect($dynamicChatMessages->last()->user_id)->toBeNull();
|
||||||
expect($dynamicChatMessages->last()->content)->toBe("<user:{$owner->id}> APPROVED the suggestion \"Polished dungeon floors\" for +20 points on \"{$ledger->name}\" ledger.");
|
expect($dynamicChatMessages->last()->content)->toBe("<user:{$owner->id}> APPROVED the suggestion \"Polished dungeon floors\" for +20 points on \"{$ledger->name}\" ledger.");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('creating a mutation with 0 points fails validation', function () {
|
|
||||||
$owner = User::factory()->create();
|
|
||||||
$dynamic = Dynamic::factory()->create();
|
|
||||||
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
|
||||||
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
|
||||||
|
|
||||||
$this->actingAs($owner);
|
|
||||||
|
|
||||||
$response = $this->post(route('dynamics.ledgers.mutations.store', [$dynamic, $ledger]), [
|
|
||||||
'amount' => 0,
|
|
||||||
'description' => 'Zero point spam',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response->assertSessionHasErrors(['amount']);
|
|
||||||
expect(Mutation::where('description', 'Zero point spam')->exists())->toBeFalse();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('creating a mutation with more than 1000 points fails validation', function () {
|
|
||||||
$owner = User::factory()->create();
|
|
||||||
$dynamic = Dynamic::factory()->create();
|
|
||||||
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
|
||||||
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
|
||||||
|
|
||||||
$this->actingAs($owner);
|
|
||||||
|
|
||||||
$response = $this->post(route('dynamics.ledgers.mutations.store', [$dynamic, $ledger]), [
|
|
||||||
'amount' => 1001,
|
|
||||||
'description' => 'Abusive positive point reward',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response->assertSessionHasErrors(['amount']);
|
|
||||||
expect(Mutation::where('description', 'Abusive positive point reward')->exists())->toBeFalse();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('creating a mutation with less than -1000 points fails validation', function () {
|
|
||||||
$owner = User::factory()->create();
|
|
||||||
$dynamic = Dynamic::factory()->create();
|
|
||||||
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
|
||||||
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
|
||||||
|
|
||||||
$this->actingAs($owner);
|
|
||||||
|
|
||||||
$response = $this->post(route('dynamics.ledgers.mutations.store', [$dynamic, $ledger]), [
|
|
||||||
'amount' => -1001,
|
|
||||||
'description' => 'Abusive negative point demerit',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response->assertSessionHasErrors(['amount']);
|
|
||||||
expect(Mutation::where('description', 'Abusive negative point demerit')->exists())->toBeFalse();
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -164,54 +164,3 @@ test('owner can delete predefined mutation', function () {
|
|||||||
'id' => $predefined->id,
|
'id' => $predefined->id,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('creating a predefined mutation with 0 points fails validation', function () {
|
|
||||||
$owner = User::factory()->create();
|
|
||||||
$dynamic = Dynamic::factory()->create();
|
|
||||||
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
|
||||||
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
|
||||||
|
|
||||||
$this->actingAs($owner);
|
|
||||||
|
|
||||||
$response = $this->post(route('dynamics.ledgers.predefined-mutations.store', [$dynamic->uuid, $ledger->uuid]), [
|
|
||||||
'name' => 'Zero point predefined',
|
|
||||||
'amount' => 0,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response->assertSessionHasErrors(['amount']);
|
|
||||||
expect(PredefinedMutation::where('name', 'Zero point predefined')->exists())->toBeFalse();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('creating a predefined mutation with more than 1000 points fails validation', function () {
|
|
||||||
$owner = User::factory()->create();
|
|
||||||
$dynamic = Dynamic::factory()->create();
|
|
||||||
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
|
||||||
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
|
||||||
|
|
||||||
$this->actingAs($owner);
|
|
||||||
|
|
||||||
$response = $this->post(route('dynamics.ledgers.predefined-mutations.store', [$dynamic->uuid, $ledger->uuid]), [
|
|
||||||
'name' => 'Abusive positive predefined',
|
|
||||||
'amount' => 1001,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response->assertSessionHasErrors(['amount']);
|
|
||||||
expect(PredefinedMutation::where('name', 'Abusive positive predefined')->exists())->toBeFalse();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('creating a predefined mutation with less than -1000 points fails validation', function () {
|
|
||||||
$owner = User::factory()->create();
|
|
||||||
$dynamic = Dynamic::factory()->create();
|
|
||||||
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
|
||||||
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
|
||||||
|
|
||||||
$this->actingAs($owner);
|
|
||||||
|
|
||||||
$response = $this->post(route('dynamics.ledgers.predefined-mutations.store', [$dynamic->uuid, $ledger->uuid]), [
|
|
||||||
'name' => 'Abusive negative predefined',
|
|
||||||
'amount' => -1001,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response->assertSessionHasErrors(['amount']);
|
|
||||||
expect(PredefinedMutation::where('name', 'Abusive negative predefined')->exists())->toBeFalse();
|
|
||||||
});
|
|
||||||
|
|||||||
Reference in New Issue
Block a user