Big changes added events for decisions
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Segment;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
|
||||
uses(WithFaker::class);
|
||||
|
||||
it('creates a decision with add_segment event when config is valid', function () {
|
||||
$user = User::factory()->create([
|
||||
'email_verified_at' => now(),
|
||||
]);
|
||||
$this->actingAs($user);
|
||||
|
||||
$segment = Segment::factory()->create();
|
||||
|
||||
$addSegmentEventId = \DB::table('events')->insertGetId([
|
||||
'name' => 'Add Segment',
|
||||
'key' => 'add_segment',
|
||||
'description' => 'Attach a segment to contract',
|
||||
'active' => 1,
|
||||
'config' => json_encode([]),
|
||||
'options' => json_encode([]),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$payload = [
|
||||
'name' => fake()->unique()->words(2, true),
|
||||
'color_tag' => null,
|
||||
'auto_mail' => false,
|
||||
'email_template_id' => null,
|
||||
'actions' => [],
|
||||
'events' => [
|
||||
[
|
||||
'id' => $addSegmentEventId,
|
||||
'active' => true,
|
||||
'run_order' => 1,
|
||||
'config' => [
|
||||
'segment_id' => $segment->id,
|
||||
'deactivate_previous' => true,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$response = $this->post(route('settings.decisions.store'), $payload);
|
||||
|
||||
$response->assertSessionHasNoErrors();
|
||||
$response->assertRedirect(route('settings.workflow'));
|
||||
});
|
||||
|
||||
it('validates segment_id is required for add_segment event on create', function () {
|
||||
$user = User::factory()->create([
|
||||
'email_verified_at' => now(),
|
||||
]);
|
||||
$this->actingAs($user);
|
||||
|
||||
$addSegmentEventId = \DB::table('events')->insertGetId([
|
||||
'name' => 'Add Segment',
|
||||
'key' => 'add_segment',
|
||||
'description' => 'Attach a segment to contract',
|
||||
'active' => 1,
|
||||
'config' => json_encode([]),
|
||||
'options' => json_encode([]),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$payload = [
|
||||
'name' => fake()->unique()->words(2, true),
|
||||
'color_tag' => null,
|
||||
'auto_mail' => false,
|
||||
'email_template_id' => null,
|
||||
'events' => [
|
||||
[
|
||||
'id' => $addSegmentEventId,
|
||||
'active' => true,
|
||||
'run_order' => 1,
|
||||
'config' => [
|
||||
// missing segment_id
|
||||
'deactivate_previous' => true,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$response = $this->post(route('settings.decisions.store'), $payload);
|
||||
|
||||
$response->assertSessionHasErrors(['events.0.config.segment_id']);
|
||||
});
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Decision;
|
||||
use App\Models\Event;
|
||||
use App\Models\Segment;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
|
||||
uses(WithFaker::class);
|
||||
|
||||
it('validates segment_id is required for add_segment event', function () {
|
||||
$user = User::factory()->create([
|
||||
'email_verified_at' => now(),
|
||||
]);
|
||||
$this->actingAs($user);
|
||||
|
||||
$decision = Decision::factory()->create();
|
||||
|
||||
// Ensure event exists (legacy schema requires non-null options)
|
||||
$addSegmentId = \DB::table('events')->insertGetId([
|
||||
'name' => 'Add Segment',
|
||||
'key' => 'add_segment',
|
||||
'description' => 'Attach a segment to contract',
|
||||
'active' => 1,
|
||||
'config' => json_encode([]),
|
||||
'options' => json_encode([]),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$payload = [
|
||||
'name' => $decision->name,
|
||||
'color_tag' => $decision->color_tag,
|
||||
'auto_mail' => false,
|
||||
'email_template_id' => null,
|
||||
'events' => [
|
||||
[
|
||||
'id' => $addSegmentId,
|
||||
'active' => true,
|
||||
'run_order' => 1,
|
||||
'config' => [
|
||||
// 'segment_id' => missing on purpose
|
||||
'deactivate_previous' => true,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$response = $this->put(route('settings.decisions.update', ['id' => $decision->id]), $payload);
|
||||
|
||||
$response->assertSessionHasErrors(['events.0.config.segment_id']);
|
||||
});
|
||||
|
||||
it('validates archive_setting_id is required for archive_contract event', function () {
|
||||
$user = User::factory()->create([
|
||||
'email_verified_at' => now(),
|
||||
]);
|
||||
$this->actingAs($user);
|
||||
|
||||
$decision = Decision::factory()->create();
|
||||
|
||||
$archiveEventId = \DB::table('events')->insertGetId([
|
||||
'name' => 'Archive Contract',
|
||||
'key' => 'archive_contract',
|
||||
'description' => 'Archive a contract by archive setting',
|
||||
'active' => 1,
|
||||
'config' => json_encode([]),
|
||||
'options' => json_encode([]),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$payload = [
|
||||
'name' => $decision->name,
|
||||
'color_tag' => $decision->color_tag,
|
||||
'auto_mail' => false,
|
||||
'email_template_id' => null,
|
||||
'events' => [
|
||||
[
|
||||
'id' => $archiveEventId,
|
||||
'active' => true,
|
||||
'run_order' => 1,
|
||||
'config' => [
|
||||
// 'archive_setting_id' => missing on purpose
|
||||
'reactivate' => false,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$response = $this->put(route('settings.decisions.update', ['id' => $decision->id]), $payload);
|
||||
|
||||
$response->assertSessionHasErrors(['events.0.config.archive_setting_id']);
|
||||
});
|
||||
|
||||
it('accepts valid add_segment config and updates without validation errors', function () {
|
||||
$user = User::factory()->create([
|
||||
'email_verified_at' => now(),
|
||||
]);
|
||||
$this->actingAs($user);
|
||||
|
||||
$decision = Decision::factory()->create();
|
||||
|
||||
$addSegmentId = \DB::table('events')->insertGetId([
|
||||
'name' => 'Add Segment',
|
||||
'key' => 'add_segment',
|
||||
'description' => 'Attach a segment to contract',
|
||||
'active' => 1,
|
||||
'config' => json_encode([]),
|
||||
'options' => json_encode([]),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$segment = Segment::factory()->create();
|
||||
|
||||
$payload = [
|
||||
'name' => $decision->name,
|
||||
'color_tag' => $decision->color_tag,
|
||||
'auto_mail' => false,
|
||||
'email_template_id' => null,
|
||||
'events' => [
|
||||
[
|
||||
'id' => $addSegmentId,
|
||||
'active' => true,
|
||||
'run_order' => 1,
|
||||
'config' => [
|
||||
'segment_id' => $segment->id,
|
||||
'deactivate_previous' => true,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$response = $this->put(route('settings.decisions.update', ['id' => $decision->id]), $payload);
|
||||
|
||||
$response->assertSessionHasNoErrors();
|
||||
$response->assertRedirect(route('settings.workflow'));
|
||||
});
|
||||
Reference in New Issue
Block a user