Skip to content

test(e2e): delete single and multiple SBOMs - #1182

Open
vobratil wants to merge 1 commit into
guacsec:mainfrom
vobratil:api-delete-tests
Open

test(e2e): delete single and multiple SBOMs#1182
vobratil wants to merge 1 commit into
guacsec:mainfrom
vobratil:api-delete-tests

Conversation

@vobratil

@vobratil vobratil commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

This is a set of simple delete tests that test the deletion of single, multiple existent and non-existent SBOMs.

This should probably not be merged before this issue is fixed:
https://redhat.atlassian.net/browse/TC-5382

Summary by Sourcery

Add end-to-end API coverage for deleting SBOMs under various scenarios.

Tests:

  • Add e2e test for deleting a single existing SBOM and verifying it is no longer retrievable.
  • Add e2e test for deleting multiple existing SBOMs and verifying they are all removed.
  • Add e2e test for attempting to delete a single non-existent SBOM and asserting a not-found response.
  • Add e2e test for deleting multiple non-existent SBOMs and asserting a successful no-op response.

@sourcery-ai

sourcery-ai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds new Playwright-based E2E API tests for SBOM deletion, covering single vs multiple and existing vs non-existent SBOM IDs, with shared upload/cleanup helpers and logging for non-expected statuses.

File-Level Changes

Change Details Files
Introduce serial E2E test suite that verifies deletion behavior for single and multiple existing SBOMs via REST API and asserts their subsequent 404 responses.
  • Create SBOM / Delete describe block configured to run serially
  • Upload fixture SBOMs using shared helpers and track their IDs for cleanup
  • Issue DELETE requests against /api/v3/sbom/:id and /api/v3/sbom endpoints for uploaded SBOM IDs
  • Assert HTTP 204 on successful delete operations and 404 on subsequent GETs for deleted SBOMs
e2e/tests/api/features/sbom-delete.ts
Add negative E2E tests for deleting non-existent SBOM IDs, asserting correct REST responses for single and bulk delete calls.
  • Generate random SBOM-like IDs that are extremely unlikely to exist
  • DELETE single non-existent SBOM by ID and assert a 404 status
  • DELETE multiple non-existent SBOMs in bulk and assert a 204 status
  • Log responses when statuses deviate from expectations for easier debugging
e2e/tests/api/features/sbom-delete.ts
Introduce shared state and cleanup for all SBOM deletion tests to avoid leaking uploaded SBOMs across runs.
  • Maintain a shared array of SBOM IDs to delete after all tests run
  • Implement an afterAll hook that deletes any accumulated SBOM IDs via helper
  • Ensure uploads from each test append to the shared cleanup list
e2e/tests/api/features/sbom-delete.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues, and left some high level feedback:

  • Remove test.describe.only from the suite to avoid unintentionally skipping other e2e tests when this file is run as part of the full test suite.
  • Consider extracting the random SBOM ID generation logic into a shared helper to avoid duplication between the single and multiple non-existent SBOM tests and keep the test code easier to maintain.
  • Since sbomIdsDelete is used for cleanup but those SBOMs are already deleted in the tests, it may be clearer either to skip adding already-deleted IDs to this array or to document that deleteSboms tolerates missing resources to avoid confusion for future readers.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Remove `test.describe.only` from the suite to avoid unintentionally skipping other e2e tests when this file is run as part of the full test suite.
- Consider extracting the random SBOM ID generation logic into a shared helper to avoid duplication between the single and multiple non-existent SBOM tests and keep the test code easier to maintain.
- Since `sbomIdsDelete` is used for cleanup but those SBOMs are already deleted in the tests, it may be clearer either to skip adding already-deleted IDs to this array or to document that `deleteSboms` tolerates missing resources to avoid confusion for future readers.

## Individual Comments

### Comment 1
<location path="e2e/tests/api/features/sbom-delete.ts" line_range="24" />
<code_context>
+  "cnv-4.17-binary-2-latest.json.bz2",
+];
+
+test.describe.only("SBOM / Delete", () => {
+  test.describe.configure({ mode: "serial" });
+
</code_context>
<issue_to_address>
**issue (testing):** Avoid using `describe.only` in committed e2e tests

`test.describe.only` limits the run to this suite and will skip other e2e suites, potentially hiding regressions. Please remove `.only` (or wrap it in a local-only helper) so the full e2e suite runs in CI.
</issue_to_address>

### Comment 2
<location path="e2e/tests/api/features/sbom-delete.ts" line_range="84-100" />
<code_context>
+    }
+  });
+
+  test("Single non-existent SBOM", async ({ axios }) => {
+    const nonExistentId = Array.from({ length: 45 }, () =>
+      "abcdefghijklmnopqrstuvwxyz0123456789"[Math.floor(Math.random() * 36)],
+    ).join("");
+
+    const response = await axios.delete(
+      `/api/v3/sbom/${encodeURIComponent(nonExistentId)}`,
+      { validateStatus: null },
+    );
+    if (response.status !== 404) {
+      logger.error(
+        `Delete single non-existent SBOM failed with status ${response.status}:`,
+        response.data,
+      );
+    }
+    expect(response.status).toBe(404);
+  });
+
</code_context>
<issue_to_address>
**suggestion (testing):** Avoid randomness for non-existent IDs to keep tests deterministic and reproducible

Using `Math.random` here makes failures hard to reproduce and, in rare cases, could even generate a valid ID. In e2e tests it’s preferable to use a fixed clearly invalid ID pattern (e.g. `"nonexistent-sbom-id-..."`) or a seeded deterministic generator so runs remain predictable while still exercising the "non-existent" path.

```suggestion
  test("Single non-existent SBOM", async ({ axios }) => {
    // Use a fixed clearly invalid ID to keep the test deterministic and reproducible
    const nonExistentId = "nonexistent-sbom-id-should-return-404";

    const response = await axios.delete(
      `/api/v3/sbom/${encodeURIComponent(nonExistentId)}`,
      { validateStatus: null },
    );
    if (response.status !== 404) {
      logger.error(
        `Delete single non-existent SBOM failed with status ${response.status}:`,
        response.data,
      );
    }
    expect(response.status).toBe(404);
  });
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread e2e/tests/api/features/sbom-delete.ts Outdated
"cnv-4.17-binary-2-latest.json.bz2",
];

test.describe.only("SBOM / Delete", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (testing): Avoid using describe.only in committed e2e tests

test.describe.only limits the run to this suite and will skip other e2e suites, potentially hiding regressions. Please remove .only (or wrap it in a local-only helper) so the full e2e suite runs in CI.

Comment on lines +84 to +100
test("Single non-existent SBOM", async ({ axios }) => {
const nonExistentId = Array.from({ length: 45 }, () =>
"abcdefghijklmnopqrstuvwxyz0123456789"[Math.floor(Math.random() * 36)],
).join("");

const response = await axios.delete(
`/api/v3/sbom/${encodeURIComponent(nonExistentId)}`,
{ validateStatus: null },
);
if (response.status !== 404) {
logger.error(
`Delete single non-existent SBOM failed with status ${response.status}:`,
response.data,
);
}
expect(response.status).toBe(404);
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Avoid randomness for non-existent IDs to keep tests deterministic and reproducible

Using Math.random here makes failures hard to reproduce and, in rare cases, could even generate a valid ID. In e2e tests it’s preferable to use a fixed clearly invalid ID pattern (e.g. "nonexistent-sbom-id-...") or a seeded deterministic generator so runs remain predictable while still exercising the "non-existent" path.

Suggested change
test("Single non-existent SBOM", async ({ axios }) => {
const nonExistentId = Array.from({ length: 45 }, () =>
"abcdefghijklmnopqrstuvwxyz0123456789"[Math.floor(Math.random() * 36)],
).join("");
const response = await axios.delete(
`/api/v3/sbom/${encodeURIComponent(nonExistentId)}`,
{ validateStatus: null },
);
if (response.status !== 404) {
logger.error(
`Delete single non-existent SBOM failed with status ${response.status}:`,
response.data,
);
}
expect(response.status).toBe(404);
});
test("Single non-existent SBOM", async ({ axios }) => {
// Use a fixed clearly invalid ID to keep the test deterministic and reproducible
const nonExistentId = "nonexistent-sbom-id-should-return-404";
const response = await axios.delete(
`/api/v3/sbom/${encodeURIComponent(nonExistentId)}`,
{ validateStatus: null },
);
if (response.status !== 404) {
logger.error(
`Delete single non-existent SBOM failed with status ${response.status}:`,
response.data,
);
}
expect(response.status).toBe(404);
});

@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.03%. Comparing base (ed87429) to head (7d36f08).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1182   +/-   ##
=======================================
  Coverage   54.03%   54.03%           
=======================================
  Files         269      269           
  Lines        5904     5904           
  Branches     1849     1849           
=======================================
  Hits         3190     3190           
  Misses       2419     2419           
  Partials      295      295           
Flag Coverage Δ
unit 6.82% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Signed-off-by: Vilem Obratil <vobratil@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant