Skip to content

test(api): add API tests for importers - #1219

Open
matejnesuta wants to merge 1 commit into
guacsec:mainfrom
matejnesuta:importer-api-tests
Open

test(api): add API tests for importers#1219
matejnesuta wants to merge 1 commit into
guacsec:mainfrom
matejnesuta:importer-api-tests

Conversation

@matejnesuta

@matejnesuta matejnesuta commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Simple CRUD tests for the Importer feature, as these paths are not covered (and currently cannot be covered) by our UI suite.

Summary by Sourcery

Tests:

  • Add end-to-end API coverage for importer creation, retrieval, PATCH and PUT updates, and deletion.

@codecov

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.19%. Comparing base (00adb72) to head (b40f252).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1219   +/-   ##
=======================================
  Coverage   54.19%   54.19%           
=======================================
  Files         255      255           
  Lines        5715     5715           
  Branches     1774     1774           
=======================================
  Hits         3097     3097           
  Misses       2355     2355           
  Partials      263      263           
Flag Coverage Δ
e2e 70.36% <ø> (ø)
unit 8.65% <ø> (ø)

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.

Comment thread e2e/tests/api/features/importer.ts
@sourcery-ai

sourcery-ai Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds isolated Playwright/Axios API tests covering importer creation, retrieval, PATCH and PUT updates with revision headers, and deletion, including response-status and persistence assertions.

File-Level Changes

Change Details Files
Add end-to-end API coverage for the Importer resource’s CRUD lifecycle.
  • Create an importer and verify its persisted name and configuration.
  • Exercise merge-patch updates with revision-based optimistic concurrency and confirm unchanged fields are preserved.
  • Exercise full PUT replacement with revision-based concurrency and verify updated configuration.
  • Delete an importer and assert subsequent retrieval returns 404.
  • Use deterministic importer names, pre-test cleanup, and finally-block cleanup to isolate tests.
e2e/tests/api/features/importer.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 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="e2e/tests/api/features/importer.ts" line_range="68" />
<code_context>
+          },
+        },
+      );
+      expect(patchResponse.status).toBe(204);
+
+      const verifyResponse = await axios.get(
</code_context>
<issue_to_address>
**issue (bug_risk):** These tests require PATCH, PUT, and DELETE to return 204, but the checked-in OpenAPI contract declares 201 for all three importer operations, so the tests fail against an implementation that follows the documented API even when the mutation succeeds.

**Suggested fix:** Align the assertions with the actual API contract, or update the API/OpenAPI contract if 204 is the intended response.
</issue_to_address>

### Comment 2
<location path="e2e/tests/api/features/importer.ts" line_range="137" />
<code_context>
+        validateStatus: () => true,
+      })
+      .catch(() => undefined);
+    await axios.post(`/api/v3/importer/${importerName}`, BASE_IMPORTER_CONFIG);
+
+    try {
</code_context>
<issue_to_address>
**issue (bug_risk):** The delete test has no `try`/`finally` cleanup, so any failure after creation leaves `api-test-delete-importer` persisted in the environment; the next run's pre-delete hides the leftover state, but a failed run pollutes shared test data and can affect other consumers.

**Triggers:** When the creation or any assertion in the delete test fails before the explicit delete completes.

**Suggested fix:** Put the create/read/delete assertions in a `try` block and delete the importer in `finally`, as the create, PATCH, and PUT tests do.
</issue_to_address>

### Comment 3
<location path="e2e/tests/api/features/importer.ts" line_range="17-21" />
<code_context>
+  test("Create importer and verify it exists", async ({ axios }) => {
+    const importerName = "api-test-create-importer";
+
+    await axios
+      .delete(`/api/v3/importer/${importerName}`, {
+        validateStatus: () => true,
+      })
+      .catch(() => undefined);
+
+    try {
</code_context>
<issue_to_address>
**issue (bug_risk):** The initial cleanup deletes a fixed importer name and suppresses every failure, then creation proceeds; if deletion is rejected by authorization, unavailable due to a transient server error, or otherwise does not remove an existing importer, the subsequent POST fails with a conflict rather than establishing the test's clean fixture.

**Triggers:** When a stale importer with the fixed name exists and the cleanup DELETE does not actually succeed.

**Suggested fix:** Use unique names per run, or verify the cleanup response and fail explicitly when an existing fixture cannot be removed.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 3 findings to address first, and the change only adds API tests, so it does not alter production behavior directly. During execution the tests persist importer records and delete them afterward; if a test or cleanup fails, a bounded leftover importer may remain, but it can be removed or the test rerun and reverting the PR prevents further creation.

Blocking findings: e2e/tests/api/features/importer.ts:68, e2e/tests/api/features/importer.ts:137, e2e/tests/api/features/importer.ts:21


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.

},
},
);
expect(patchResponse.status).toBe(204);

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 (bug_risk): These tests require PATCH, PUT, and DELETE to return 204, but the checked-in OpenAPI contract declares 201 for all three importer operations, so the tests fail against an implementation that follows the documented API even when the mutation succeeds.

Suggested fix: Align the assertions with the actual API contract, or update the API/OpenAPI contract if 204 is the intended response.

validateStatus: () => true,
})
.catch(() => undefined);
await axios.post(`/api/v3/importer/${importerName}`, BASE_IMPORTER_CONFIG);

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 (bug_risk): The delete test has no try/finally cleanup, so any failure after creation leaves api-test-delete-importer persisted in the environment; the next run's pre-delete hides the leftover state, but a failed run pollutes shared test data and can affect other consumers.

Triggers: When the creation or any assertion in the delete test fails before the explicit delete completes.

Suggested fix: Put the create/read/delete assertions in a try block and delete the importer in finally, as the create, PATCH, and PUT tests do.

Comment on lines +17 to +21
await axios
.delete(`/api/v3/importer/${importerName}`, {
validateStatus: () => true,
})
.catch(() => undefined);

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 (bug_risk): The initial cleanup deletes a fixed importer name and suppresses every failure, then creation proceeds; if deletion is rejected by authorization, unavailable due to a transient server error, or otherwise does not remove an existing importer, the subsequent POST fails with a conflict rather than establishing the test's clean fixture.

Triggers: When a stale importer with the fixed name exists and the cleanup DELETE does not actually succeed.

Suggested fix: Use unique names per run, or verify the cleanup response and fail explicitly when an existing fixture cannot be removed.

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.

2 participants