Skip to content
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
4 changes: 4 additions & 0 deletions app/Core/Models/Concerns/HasArtifactIdentifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ trait HasArtifactIdentifier
{
public static function bootHasArtifactIdentifier(): void
{
static::deleting(function (self $model) {
$model->artifact()->delete();
});

static::created(function (self $model) {
DB::transaction(function () use ($model) {
$projectId = $model->getProjectIdForArtifact();
Expand Down
27 changes: 25 additions & 2 deletions tests/Feature/EdgeCases/SpecificationEdgeCasesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,31 @@ public function mcpTools(): array
$this->assertDatabaseMissing('stories', ['id' => $story->id]);
});

it('cleans up the artifact record when a story is deleted')
->skip('HasArtifactIdentifier does not register a deleting hook — artifact cascade not yet implemented in core.');
it('cleans up the artifact record when a story is deleted', function (): void {
$auth = createAuth();
$project = setupProject($auth, ['code' => 'CL9B']);
app(TenantManager::class)->setTenant($auth['tenant']);

$epic = Epic::factory()->create(['project_id' => $project->id]);
$story = Story::factory()->create(['epic_id' => $epic->id]);
$storyId = $story->fresh()->identifier;

$this->assertDatabaseHas('artifacts', [
'artifactable_id' => $story->id,
'artifactable_type' => $story->getMorphClass(),
]);

$this->deleteJson(
"/api/v1/projects/CL9B/stories/{$storyId}",
[],
authHeader($auth['token'])
)->assertStatus(204);

$this->assertDatabaseMissing('artifacts', [
'artifactable_id' => $story->id,
'artifactable_type' => $story->getMorphClass(),
]);
});

});

Expand Down
Loading