Skip to content

Commit

Permalink
fix: ensure settled action result before fetching it [PHX-2608]
Browse files Browse the repository at this point in the history
  • Loading branch information
marcolink committed May 10, 2023
1 parent 3d5894a commit 0029a06
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
9 changes: 3 additions & 6 deletions lib/cmds/merge_cmds/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Listr from 'listr'
import path from 'path'
import type { Argv } from 'yargs'
import {
callCreateChangeset,
callCreateChangesetWithResponse,
getExportMigration
} from '../../utils/app-actions'
import { getAppActionId, type Host } from '../../utils/app-actions-config'
Expand Down Expand Up @@ -89,7 +89,7 @@ export const callExportAppAction = async ({
// use wrapTask
task: async (ctx: Context, task) => {
task.output = chalk`calculating differences`
const actionResponse = await callCreateChangeset({
const actionResponse = await callCreateChangesetWithResponse({
api: ctx.api,
appDefinitionId: ctx.appDefinitionId,
appActionId: ctx.createChangesetActionId,
Expand All @@ -107,11 +107,8 @@ export const callExportAppAction = async ({
})

task.output = chalk`fetching differences`
// wait for changeset to be settled
await new Promise(resolve => setTimeout(resolve, 1000 * 8))
// eslint-disable-next-line require-atomic-updates
ctx.changesetRef = actionResponse
// ctx.changesetRef = actionResponse.sys.id
ctx.changesetRef = actionResponse.sys.id
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"contentful-collection": "^0.0.4",
"contentful-export": "^7.19.0",
"contentful-import": "^8.5.35",
"contentful-management": "^10.33.0",
"contentful-management": "^10.35.3",
"contentful-migration": "^4.12.5",
"emojic": "^1.1.11",
"execa": "^5.0.0",
Expand Down
17 changes: 14 additions & 3 deletions test/unit/cmds/merge_cmds/export.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const mockedClient = {
},
environmentAlias: {
getMany: jest.fn().mockResolvedValue({ items: [] })
},
}
} as unknown as PlainClientAPI

describe('merge export command', () => {
Expand Down Expand Up @@ -90,7 +90,15 @@ describe('merge export command', () => {
body: '{"message": {"migration":"console.log(\'hello world\')"}}'
}
}),
createWithResponse: jest.fn()
createWithResponse: jest.fn().mockResolvedValue({
statusCode: 200,
sys: {
id: 'action-id-export-migration'
},
response: {
body: '{"message": {"migration":"console.log(\'hello world\')"}}'
}
})
}

await exportCmd.callExportAppAction({
Expand All @@ -103,7 +111,10 @@ describe('merge export command', () => {
spaceId: 'space'
})

expect(mockedClient.appActionCall.create).toHaveBeenCalledTimes(2)
expect(mockedClient.appActionCall.create).toHaveBeenCalledTimes(1)
expect(mockedClient.appActionCall.createWithResponse).toHaveBeenCalledTimes(
1
)
})

it('catches the error and shows a pretty output', async () => {
Expand Down

0 comments on commit 0029a06

Please sign in to comment.