Skip to content
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

fix: ensure settled action result before fetching it [PHX-2608] #2049

Merged
merged 1 commit into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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