Skip to content

Conversation

@asnewman
Copy link
Contributor

@asnewman asnewman commented Aug 8, 2025

Summary

Adds support for fetching and outputting rich text (HTML) content from the Ditto API.

Usage

Add richText: html to your configuration:

projects: [],
variants: [],
richText: html
outputs:
  - format: json,
    framework: i18next

It can be overridden with false

outputs:
  - format: json
    framework: i18next
    richText: false

When enabled, the CLI will output HTML-formatted text values in JSON files.

Testing checklist

  • Verify the base level richText: html works
  • Verify the overriding output config richText: false works
  • Verify the overriding output config richText: html works

First, run local Ditto and the public api - in ditto-app run your normal local start command + yarn start:api
Then, to run the CLI locally, run yarn start pull and paste in your API key if needed
You'll need to update ditto/config.yml to test the changes.
Check the json files to verify rich text output.

@asnewman asnewman marked this pull request as ready for review August 12, 2025 23:18
@asnewman asnewman requested a review from marla-hoggard August 13, 2025 23:49
Copy link
Contributor

@marla-hoggard marla-hoggard left a comment

Choose a reason for hiding this comment

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

I'm going to push up a few commits to fix the filter issue, as well as update a prompt message that i noticed was out of date.

@marla-hoggard marla-hoggard self-requested a review August 14, 2025 18:16
@asnewman
Copy link
Contributor Author

@marla-hoggard for tomorrow, I added some tests for the pull function, should be good to rereview!

const mockHttpClient = httpClient as jest.Mocked<typeof httpClient>;

// Test data factories
const createMockTextItem = (overrides: any = {}) => ({
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Do we have these types defined in the CLI that we could use instead of any? Missing proper typing in tests makes them much less likely to be updated on changes/harder to write without making silly errors.


// Create a temporary directory for tests
let testDir: string;
let outputDir: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these variables and the beforeEach/afterEach live inside the outer-most describe?


const assertFilesCreated = (outputDir: string, expectedFiles: string[]) => {
const actualFiles = fs.readdirSync(outputDir).sort();
expect(actualFiles).toEqual(expectedFiles.sort());
Copy link
Contributor

Choose a reason for hiding this comment

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

Use the newer, non-mutating toSorted() instead of sort() for both of these to avoid directly mutating the arrays, potentially causing side effects in what else might be asserted after this line in the test.


// Mock should only return project-1 items when filtered
// The API only returns items for the requested projects
setupMocks([textItem1], []);
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, these tests aren't actually testing the config filters at all. The only determining factor in what gets returned is what we pass into setupMocks. The filters are all used for determining the query params that we pass to the API endpoint. But here we're totally mocking the endpoint and manually providing response data. If I change the config values, the tests continue to pass.

These tests are doing a great job of validating the part of the flow from API response to CLI output, which works for the richText tests since that's where that logic gets applied, but the filters get applied in the config -> API request pathway, which is being 100% mocked right now.

To test the filters, we would want to inspect the request params that we send to the mocked API endpoint and confirm that we properly converted the config to the right params. That might be easier via directly testing the generateQueryParams method rather than doing it inside the pull command tests, but should hopefully also be accomplishable by inspecting what is sent to mockHttpClient if we want to keep it all in here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I do think it's worth writing good filter tests, but I would be good if we removed them from this PR so we could get the richText functionality in and then opened a follow-up PR with the test updates. As long as we actually do it soon while the context is all in our head.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah good catch. I added a toHaveBeenCalledWith for the get call, that should test things properly, right? If not I'll just remove the test

Updates createMockTextItem function to use Partial<TextItemsResponse[0]>
instead of any, providing better type safety for test mock overrides.
Improves test organization by moving testDir, outputDir variables
and beforeEach/afterEach hooks inside the main describe block for
better scoping and isolation.
Replaces mutating sort() calls with non-mutating toSorted()
to avoid potential side effects in test assertions.
These tests mock HTTP calls and set appContext directly, so the YAML
config files were never actually read. Removed the duplication between
YAML strings and setProjectConfig() calls - now tests only create what
they need and use a single source of truth for configuration.

This eliminates the risk of YAML/object mismatch bugs and makes the
tests clearer about what they're actually testing.
Adds toHaveBeenCalledWith assertions to filter tests to verify that
config filters are correctly converted to API query parameters.
Tests now catch bugs in the config->API params conversion logic
instead of just testing the mocked response->file output flow.

This addresses the concern that filter tests weren't actually
testing the filtering functionality due to complete API mocking.
@asnewman asnewman requested a review from marla-hoggard August 15, 2025 22:22
Copy link
Contributor

@marla-hoggard marla-hoggard left a comment

Choose a reason for hiding this comment

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

@asnewman I pushed some tweaks to the tests, adding a few more filter cases and splitting up the filter tests and the output file test, to more explicitly tie the tests to the parts of the flow that aren't mocked. Everything else looks good from my end!

@asnewman asnewman merged commit 566a878 into v5-beta Aug 18, 2025
1 check passed
@asnewman asnewman deleted the ash/dit-11112-rich-text-for-cli branch August 18, 2025 21:55
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.

3 participants