Skip to content

Commit

Permalink
fix: flow translation post processing (#487)
Browse files Browse the repository at this point in the history
* fix: use config parameter instead of work

* test: add more precise assertions
  • Loading branch information
scolladon authored Feb 26, 2023
1 parent 0855dcc commit 225c435
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
48 changes: 48 additions & 0 deletions __tests__/unit/lib/post-processor/flowTranslationProcessor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const FlowTranslationProcessor = require('../../../../src/post-processor/flowTra
const { mockParse } = require('fast-xml-parser')
const {
FLOW_DIRECTORY_NAME,
METAFILE_SUFFIX,
TRANSLATION_EXTENSION,
TRANSLATION_TYPE,
} = require('../../../../src/utils/metadataConstants')
const {
Expand All @@ -19,6 +21,7 @@ jest.mock('../../../../src/utils/ignoreHelper')
const FR = 'fr'
const EN = 'en'
const flowFullName = 'test-flow'
const EXTENSION = `${TRANSLATION_EXTENSION}${METAFILE_SUFFIX}`

const trueAfter = (attempt = 0) => {
let count = 0
Expand Down Expand Up @@ -62,6 +65,11 @@ describe('FlowTranslationProcessor', () => {
// Assert
expect(work.diffs.package.has(TRANSLATION_TYPE)).toBeFalsy()
expect(scanExtension).toHaveBeenCalledTimes(1)
expect(scanExtension).toHaveBeenCalledWith(
work.config.source,
EXTENSION,
work.config
)
expect(mockParse).not.toHaveBeenCalled()
expect(copyFiles).not.toHaveBeenCalled()
})
Expand All @@ -79,6 +87,11 @@ describe('FlowTranslationProcessor', () => {
// Assert
expect(work.diffs.package.has(TRANSLATION_TYPE)).toBeFalsy()
expect(scanExtension).toHaveBeenCalledTimes(1)
expect(scanExtension).toHaveBeenCalledWith(
work.config.source,
EXTENSION,
work.config
)
expect(mockParse).toHaveBeenCalledTimes(1)
expect(copyFiles).not.toHaveBeenCalled()
})
Expand All @@ -101,6 +114,11 @@ describe('FlowTranslationProcessor', () => {
// Assert
expect(work.diffs.package.has(TRANSLATION_TYPE)).toBeTruthy()
expect(scanExtension).toHaveBeenCalledTimes(1)
expect(scanExtension).toHaveBeenCalledWith(
work.config.source,
EXTENSION,
work.config
)
expect(mockParse).toHaveBeenCalledTimes(1)
expect(copyFiles).toHaveBeenCalled()
})
Expand Down Expand Up @@ -138,6 +156,11 @@ describe('FlowTranslationProcessor', () => {

// Assert
expect(scanExtension).toHaveBeenCalledTimes(1)
expect(scanExtension).toHaveBeenCalledWith(
work.config.source,
EXTENSION,
work.config
)
expect(mockParse).not.toHaveBeenCalled()
expect(copyFiles).not.toHaveBeenCalled()
})
Expand Down Expand Up @@ -174,6 +197,11 @@ describe('FlowTranslationProcessor', () => {
// Assert
expect(work.diffs.package.has(TRANSLATION_TYPE)).toBeFalsy()
expect(scanExtension).toHaveBeenCalledTimes(1)
expect(scanExtension).toHaveBeenCalledWith(
work.config.source,
EXTENSION,
work.config
)
expect(mockParse).toHaveBeenCalledTimes(2)
expect(copyFiles).not.toHaveBeenCalled()
})
Expand Down Expand Up @@ -201,6 +229,11 @@ describe('FlowTranslationProcessor', () => {
// Assert
expect(work.diffs.package.has(TRANSLATION_TYPE)).toBeTruthy()
expect(scanExtension).toHaveBeenCalledTimes(1)
expect(scanExtension).toHaveBeenCalledWith(
work.config.source,
EXTENSION,
work.config
)
expect(mockParse).toHaveBeenCalledTimes(2)
if (generateDelta) expect(copyFiles).toHaveBeenCalledTimes(2)
else expect(copyFiles).not.toHaveBeenCalled()
Expand All @@ -223,6 +256,11 @@ describe('FlowTranslationProcessor', () => {
// Assert
expect(work.diffs.package.has(TRANSLATION_TYPE)).toBeFalsy()
expect(scanExtension).toHaveBeenCalledTimes(1)
expect(scanExtension).toHaveBeenCalledWith(
work.config.source,
EXTENSION,
work.config
)
expect(forPath).toHaveBeenCalledTimes(1)
expect(mockParse).not.toHaveBeenCalled()
expect(copyFiles).not.toHaveBeenCalled()
Expand All @@ -245,6 +283,11 @@ describe('FlowTranslationProcessor', () => {
// Assert
expect(work.diffs.package.has(TRANSLATION_TYPE)).toBeTruthy()
expect(scanExtension).toHaveBeenCalledTimes(1)
expect(scanExtension).toHaveBeenCalledWith(
work.config.source,
EXTENSION,
work.config
)
expect(forPath).toHaveBeenCalledTimes(1)
expect(mockParse).toHaveBeenCalledTimes(1)
expect(copyFiles).toHaveBeenCalledTimes(1)
Expand Down Expand Up @@ -274,6 +317,11 @@ describe('FlowTranslationProcessor', () => {
// Assert
expect(work.diffs.package.has(TRANSLATION_TYPE)).toBeFalsy()
expect(scanExtension).toHaveBeenCalledTimes(1)
expect(scanExtension).toHaveBeenCalledWith(
work.config.source,
EXTENSION,
work.config
)
expect(mockParse).not.toHaveBeenCalled()
expect(copyFiles).not.toHaveBeenCalled()
})
Expand Down
2 changes: 1 addition & 1 deletion src/post-processor/flowTranslationProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class FlowTranslationProcessor extends BaseProcessor {
const translationsIterator = scanExtension(
this.config.source,
EXTENSION,
this.work
this.work.config
)

const ign = await this._getIgnoreInstance()
Expand Down

0 comments on commit 225c435

Please sign in to comment.