Skip to content

Commit

Permalink
SALTO-7139 SALTO-6602: Elements Fixer should receive Elements with re…
Browse files Browse the repository at this point in the history
…solved types #7001
  • Loading branch information
tamtamirr authored Dec 26, 2024
1 parent 0e9be61 commit 90caa9b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/core/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
detailedCompare,
getDetailedChanges as getDetailedChangesFromChange,
inspectValue,
resolveTypeShallow,
} from '@salto-io/adapter-utils'
import { deployActions, ItemStatus } from './core/deploy'
import {
Expand Down Expand Up @@ -715,6 +716,9 @@ export const fixElements = async (
.filter(values.isDefined)
.toArray()

const elementsSource = await workspace.elements()
await awu(elements).forEach(element => resolveTypeShallow(element, elementsSource))

log.debug(
'about to fixElements: %o, found by selectors: %o',
elements.map(element => element.elemID.getFullName()),
Expand Down
19 changes: 18 additions & 1 deletion packages/core/test/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
ReferenceExpression,
SeverityLevel,
toChange,
TypeReference,
} from '@salto-io/adapter-api'
import * as workspace from '@salto-io/workspace'
import { collections } from '@salto-io/lowerdash'
Expand Down Expand Up @@ -1311,7 +1312,7 @@ describe('api.ts', () => {
type = new ObjectType({
elemID: new ElemID('test1', 'test'),
})
instance = new InstanceElement('test', type, { c: 4 })
instance = new InstanceElement('test', new TypeReference(type.elemID), { c: 4 })

ws = mockWorkspace({
accounts: ['test1'],
Expand Down Expand Up @@ -1534,6 +1535,22 @@ describe('api.ts', () => {
expect(res).toEqual({ changes: [], errors: [] })
expect(mockFixElements).toHaveBeenCalledTimes(0)
})
describe('Resolve instances types', () => {
let inputElements: Element[]
beforeEach(() => {
mockFixElements.mockImplementation(async elements => {
inputElements = elements
return { fixedElements: [], errors: [] }
})
})
it('should invoke fixElements with instances that have resolved type', async () => {
await api.fixElements(ws, [workspace.createElementSelector(instance.elemID.getFullName())])
expect(inputElements).toHaveLength(1)
const instanceElement = inputElements[0] as InstanceElement
expect(instanceElement).toBeInstanceOf(InstanceElement)
expect(instanceElement.refType.type).toBeDefined()
})
})
})

describe('cancelServiceAsyncTask', () => {
Expand Down

0 comments on commit 90caa9b

Please sign in to comment.