Skip to content

test(e2e): add API client tests#192

Open
duyhungtnn wants to merge 7 commits intochore/remove-proto-requestfrom
chore/e2e-api-client
Open

test(e2e): add API client tests#192
duyhungtnn wants to merge 7 commits intochore/remove-proto-requestfrom
chore/e2e-api-client

Conversation

@duyhungtnn
Copy link
Copy Markdown
Collaborator

@duyhungtnn duyhungtnn commented Apr 9, 2026

close #86

This pull request adds comprehensive end-to-end (E2E) test suites for the Bucketeer API client, focusing on:

  • Functional testing
  • Deep schema validation of API responses without using any 3rd lib.

The new tests ensure that API endpoints return the expected fields and data types, and that any breaking changes in the backend are caught early. The most important changes are grouped below:

refs: https://github.com/bucketeer-io/go-server-sdk/blob/master/test/e2e/api_test.go

E2e tests passed https://github.com/bucketeer-io/node-server-sdk/actions/runs/24231732798/job/70744660423

@duyhungtnn duyhungtnn changed the base branch from master to chore/remove-proto-request April 9, 2026 04:35
Populate ava-e2e.config.mjs env vars with dev API endpoint, scheme, and example client/server keys, and add new end-to-end tests and plan:

- e2e/api_client.ts: behavioral E2E tests for APIClient (getFeatureFlags, getSegmentUsers, getEvaluation).
- e2e/api_client_schema.ts: schema validation tests with composable assert helpers that verify presence and types of nested response fields (features, rules, strategies, segment users, evaluations, etc.).
- plan-addFieldPresenceAssertionsSchema.prompt.md: plan describing the bottom-up approach for adding field presence assertions and verification steps.

These changes add stricter schema checks to catch silent backend field removals and separate behavioral tests from schema validation.
@duyhungtnn duyhungtnn force-pushed the chore/e2e-api-client branch from 941ab91 to 45b546d Compare April 9, 2026 04:39
Add a header comment to e2e/api_client_schema.ts describing the test suite's purpose and approach. The comment explains that the tests perform deep, bottom-up schema validation of Bucketeer API responses—verifying presence and types of fields including nested objects and arrays—to catch breaking changes or field removals at the SDK level and prevent silent production failures. No functional code changes.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds new AVA-based E2E tests that exercise the low-level APIClient directly and validate response payload structure, intended to catch backend breaking changes earlier at the SDK boundary.

Changes:

  • Added functional E2E tests for getFeatureFlags, getSegmentUsers, and getEvaluation.
  • Added a “deep schema validation” E2E suite with bottom-up assertions for nested response objects.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
e2e/api_client.ts Functional E2E tests for core APIClient endpoints.
e2e/api_client_schema.ts Deep schema assertions for APIClient responses (features, segment users, evaluation).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread e2e/api_client_schema.ts Outdated
Comment thread e2e/api_client_schema.ts Outdated
Comment thread e2e/api_client_schema.ts Outdated
Comment thread e2e/api_client.ts
Comment thread e2e/api_client_schema.ts
Comment thread e2e/api_client.ts
Use empty arrays instead of [''] in getSegmentUsers test calls, and adjust schema assertions to handle optional fields: cast allowed strings, only validate name/description when present, and make reason validation conditional. Also update Variation type to require id and name (make them non-optional) in src/objects/feature.ts. These changes fix false-positive test assumptions and align TypeScript types with expected runtime data.
@duyhungtnn duyhungtnn requested a review from Copilot April 9, 2026 09:07
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/objects/feature.ts
Comment thread e2e/api_client_schema.ts
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread e2e/api_client.ts
Comment thread e2e/api_client.ts
Comment thread e2e/api_client.ts
Comment thread e2e/api_client.ts
Comment thread e2e/api_client_schema.ts
Expand the header comment in e2e/api_client_schema.ts to explain why runtime schema tests are necessary: JSON.parse yields unknown/any at runtime and TypeScript types are erased at compile time, so a runtime test suite acts as the contract to catch backend field removals or type changes that could otherwise silently break production.
Add assertions and clarifying comments to e2e/api_client.ts: ensure response.forceUpdate is true on initial getFeatureFlags and getSegmentUsers calls (so clients fetch latest data), and assert first.segmentUsers.length > 0 in the segment users test to guarantee a non-empty initial result. Minor formatting tweak.
@duyhungtnn duyhungtnn requested a review from Copilot April 10, 2026 04:40
@duyhungtnn duyhungtnn changed the title chore: e2e api client test(e2e): add API client tests Apr 10, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread e2e/api_client.ts
Comment thread e2e/api_client_schema.ts
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread e2e/api_client.ts Outdated
Replace a loose inequality check with explicit assertions: verify featureFlagsId is a string and has length > 0. This makes the test more precise and ensures the response field is both the correct type and non-empty.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@duyhungtnn duyhungtnn marked this pull request as ready for review April 10, 2026 08:05
@duyhungtnn duyhungtnn requested a review from cre8ivejp as a code owner April 10, 2026 08:05
@duyhungtnn
Copy link
Copy Markdown
Collaborator Author

@cre8ivejp please help me to take a look

Note:
It should be merged only after this PR is merged:
#186

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants