thompsonsj / payload-crowdin-sync

Upload and sync localized fields from the default locale to Crowdin.
7 stars 6 forks source link

refactor(tests): api mocks #149

Closed thompsonsj closed 10 months ago

thompsonsj commented 10 months ago

Fix crowdin file creation logic

forEach was being used with async-await to create documents in the crowdin-files collection.

This led to inconsistent test results. Documents from the crowdin-files collection could be retrieved before they have been created.

We now wait for all of these files to be created. The hacky comments and dummy API calls used in tests to try and wait for these files have now been removed.

See https://gist.github.com/joeytwiddle/37d2085425c049629b80956d3c618971.

Remove the mock Crowdin client

Crowdin API calls were mocked using dependency injection in the filesApi and translationsApi classes.

This is removed and all tests now need to use nock to intercept all calls to the Crowdin API. Logic is retained from the mock client but refactored to provide fake Crowdin responses synchronously if needed.

This gives much greater control over tests and also provides effective documentation in that we can see exactly what Crowdin API calls are expected.

Remove custom Payload config files

By introducing another Payload dev installation under dev-alternative-config, we avoid the need to create different Payload config files under the same Payload installation.

This is preferable because: