-
Notifications
You must be signed in to change notification settings - Fork 6
Add rich text support for CLI #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
marla-hoggard
left a comment
There was a problem hiding this 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.
…ds/cli into ash/dit-11112-rich-text-for-cli
|
@marla-hoggard for tomorrow, I added some tests for the pull function, should be good to rereview! |
lib/src/commands/pull.test.ts
Outdated
| const mockHttpClient = httpClient as jest.Mocked<typeof httpClient>; | ||
|
|
||
| // Test data factories | ||
| const createMockTextItem = (overrides: any = {}) => ({ |
There was a problem hiding this comment.
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.
lib/src/commands/pull.test.ts
Outdated
|
|
||
| // Create a temporary directory for tests | ||
| let testDir: string; | ||
| let outputDir: string; |
There was a problem hiding this comment.
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?
lib/src/commands/pull.test.ts
Outdated
|
|
||
| const assertFilesCreated = (outputDir: string, expectedFiles: string[]) => { | ||
| const actualFiles = fs.readdirSync(outputDir).sort(); | ||
| expect(actualFiles).toEqual(expectedFiles.sort()); |
There was a problem hiding this comment.
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.
lib/src/commands/pull.test.ts
Outdated
|
|
||
| // Mock should only return project-1 items when filtered | ||
| // The API only returns items for the requested projects | ||
| setupMocks([textItem1], []); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
marla-hoggard
left a comment
There was a problem hiding this 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!
Summary
Adds support for fetching and outputting rich text (HTML) content from the Ditto API.
Usage
Add
richText: htmlto your configuration:It can be overridden with
falseWhen enabled, the CLI will output HTML-formatted text values in JSON files.
Testing checklist
richText: htmlworksrichText: falseworksrichText: htmlworksFirst, run local Ditto and the public api - in
ditto-apprun your normal local start command +yarn start:apiThen, to run the CLI locally, run
yarn start pulland paste in your API key if neededYou'll need to update
ditto/config.ymlto test the changes.Check the json files to verify rich text output.