Skip to content

Commit

Permalink
Revert "fix: xml header consideration for inFile metadata type handler (
Browse files Browse the repository at this point in the history
scolladon#811)"

This reverts commit 71b1217.
  • Loading branch information
a-ursu committed May 24, 2024
1 parent 66a2893 commit f374a3e
Show file tree
Hide file tree
Showing 6 changed files with 329 additions and 350 deletions.
2 changes: 1 addition & 1 deletion __tests__/functional/delta.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('sgd:source:delta NUTS', () => {
const destructiveChangesLineCount = await getFileLineNumber(
'e2e/expected/destructiveChanges/destructiveChanges.xml'
)
expect(packageLineCount).to.equal(221)
expect(packageLineCount).to.equal(220)
expect(destructiveChangesLineCount).to.equal(130)
expect(result).to.include('"error": null')
expect(result).to.include('"success": true')
Expand Down
233 changes: 110 additions & 123 deletions __tests__/unit/lib/utils/metadataDiff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,85 +28,11 @@ const workFlowAttributes = new Map([
['alerts', { xmlName: 'WorkflowAlert', key: 'fullName' }],
])

const xmlHeader = { '?xml': { '@_version': '1.0', '@_encoding': 'UTF-8' } }

const alert = {
Workflow: {
'@_xmlns': 'http://soap.sforce.com/2006/04/metadata',
alerts: [
{
fullName: 'TestEmailAlert',
description: 'awesome',
protected: 'false',
recipients: { field: 'OtherEmail', type: 'email' },
senderAddress: '[email protected]',
senderType: 'OrgWideEmailAddress',
template: 'None',
},
{
fullName: 'OtherTestEmailAlert',
description: 'awesome',
protected: 'false',
recipients: { field: 'OtherEmail', type: 'email' },
senderAddress: '[email protected]',
senderType: 'OrgWideEmailAddress',
template: 'None',
},
],
},
}

const alertOther = {
Workflow: {
'@_xmlns': 'http://soap.sforce.com/2006/04/metadata',
alerts: [
{
fullName: 'OtherTestEmailAlert',
description: 'awesome',
protected: 'false',
recipients: { field: 'OtherEmail', type: 'email' },
senderAddress: '[email protected]',
senderType: 'OrgWideEmailAddress',
template: 'None',
},
],
},
}

const alertTest = {
Workflow: {
'@_xmlns': 'http://soap.sforce.com/2006/04/metadata',
alerts: {
fullName: 'TestEmailAlert',
description: 'awesome',
protected: 'false',
recipients: { field: 'OtherEmail', type: 'email' },
senderAddress: '[email protected]',
senderType: 'OrgWideEmailAddress',
template: 'None',
},
},
}

const wfBase = {
Workflow: {
'@_xmlns': 'http://soap.sforce.com/2006/04/metadata',
},
}

const unTracked = {
Workflow: {
'@_xmlns': 'http://soap.sforce.com/2006/04/metadata',
unTracked: {
fullName: 'untracked',
},
},
}

describe.each([[{}], [xmlHeader]])(`MetadataDiff`, header => {
describe(`MetadataDiff`, () => {
let metadataDiff: MetadataDiff
let globalMetadata: MetadataRepository
let work: Work
let alert: any, alertOther: any, alertTest: any, wfBase: any, unTracked: any
beforeAll(async () => {
// eslint-disable-next-line no-undef
globalMetadata = await getGlobalMetadata()
Expand All @@ -121,9 +47,87 @@ describe.each([[{}], [xmlHeader]])(`MetadataDiff`, header => {
globalMetadata,
workFlowAttributes
)

alert = {
'?xml': { '@_version': '1.0', '@_encoding': 'UTF-8' },
Workflow: {
'@_xmlns': 'http://soap.sforce.com/2006/04/metadata',
alerts: [
{
fullName: 'TestEmailAlert',
description: 'awesome',
protected: 'false',
recipients: { field: 'OtherEmail', type: 'email' },
senderAddress: '[email protected]',
senderType: 'OrgWideEmailAddress',
template: 'None',
},
{
fullName: 'OtherTestEmailAlert',
description: 'awesome',
protected: 'false',
recipients: { field: 'OtherEmail', type: 'email' },
senderAddress: '[email protected]',
senderType: 'OrgWideEmailAddress',
template: 'None',
},
],
},
}

alertOther = {
'?xml': { '@_version': '1.0', '@_encoding': 'UTF-8' },
Workflow: {
'@_xmlns': 'http://soap.sforce.com/2006/04/metadata',
alerts: [
{
fullName: 'OtherTestEmailAlert',
description: 'awesome',
protected: 'false',
recipients: { field: 'OtherEmail', type: 'email' },
senderAddress: '[email protected]',
senderType: 'OrgWideEmailAddress',
template: 'None',
},
],
},
}

alertTest = {
'?xml': { '@_version': '1.0', '@_encoding': 'UTF-8' },
Workflow: {
'@_xmlns': 'http://soap.sforce.com/2006/04/metadata',
alerts: {
fullName: 'TestEmailAlert',
description: 'awesome',
protected: 'false',
recipients: { field: 'OtherEmail', type: 'email' },
senderAddress: '[email protected]',
senderType: 'OrgWideEmailAddress',
template: 'None',
},
},
}

wfBase = {
'?xml': { '@_version': '1.0', '@_encoding': 'UTF-8' },
Workflow: {
'@_xmlns': 'http://soap.sforce.com/2006/04/metadata',
},
}

unTracked = {
'?xml': { '@_version': '1.0', '@_encoding': 'UTF-8' },
Workflow: {
'@_xmlns': 'http://soap.sforce.com/2006/04/metadata',
unTracked: {
fullName: 'untracked',
},
},
}
})

describe(`compare with ${JSON.stringify(header)} header`, () => {
describe('compare', () => {
it('does not detect null file content', async () => {
// Arrange
mockedParseXmlFileToJson.mockResolvedValueOnce('')
Expand All @@ -139,11 +143,8 @@ describe.each([[{}], [xmlHeader]])(`MetadataDiff`, header => {

it('does not detect not tracked elements', async () => {
// Arrange
mockedParseXmlFileToJson.mockResolvedValueOnce({
...header,
...unTracked,
})
mockedParseXmlFileToJson.mockResolvedValueOnce({ ...header, ...wfBase })
mockedParseXmlFileToJson.mockResolvedValueOnce(unTracked)
mockedParseXmlFileToJson.mockResolvedValueOnce(wfBase)

// Act
const { added, deleted } = await metadataDiff.compare('file/path')
Expand All @@ -155,8 +156,8 @@ describe.each([[{}], [xmlHeader]])(`MetadataDiff`, header => {

it('detects added elements', async () => {
// Arrange
mockedParseXmlFileToJson.mockResolvedValueOnce({ ...header, ...alert })
mockedParseXmlFileToJson.mockResolvedValueOnce({ ...header, ...wfBase })
mockedParseXmlFileToJson.mockResolvedValueOnce(alert)
mockedParseXmlFileToJson.mockResolvedValueOnce(wfBase)

// Act
const { added, deleted } = await metadataDiff.compare('file/path')
Expand All @@ -169,8 +170,8 @@ describe.each([[{}], [xmlHeader]])(`MetadataDiff`, header => {
})
it('detects removed elements', async () => {
// Arrange
mockedParseXmlFileToJson.mockResolvedValueOnce({ ...header, ...wfBase })
mockedParseXmlFileToJson.mockResolvedValueOnce({ ...header, ...alert })
mockedParseXmlFileToJson.mockResolvedValueOnce(wfBase)
mockedParseXmlFileToJson.mockResolvedValueOnce(alert)

// Act
const { added, deleted } = await metadataDiff.compare('file/path')
Expand All @@ -185,7 +186,7 @@ describe.each([[{}], [xmlHeader]])(`MetadataDiff`, header => {
it('detects deleted file', async () => {
// Arrange
mockedParseXmlFileToJson.mockResolvedValueOnce('')
mockedParseXmlFileToJson.mockResolvedValueOnce({ ...header, ...alert })
mockedParseXmlFileToJson.mockResolvedValueOnce(alert)

// Act
const { added, deleted } = await metadataDiff.compare('file/path')
Expand All @@ -199,12 +200,8 @@ describe.each([[{}], [xmlHeader]])(`MetadataDiff`, header => {

it('detects modified elements', async () => {
// Arrange
mockedParseXmlFileToJson.mockResolvedValueOnce(alertTest)
mockedParseXmlFileToJson.mockResolvedValueOnce({
...header,
...alertTest,
})
mockedParseXmlFileToJson.mockResolvedValueOnce({
...header,
...alertTest,
Workflow: {
...alertTest.Workflow,
Expand All @@ -220,61 +217,57 @@ describe.each([[{}], [xmlHeader]])(`MetadataDiff`, header => {
expect(added.get('WorkflowAlert')).toEqual(new Set(['TestEmailAlert']))
})
})
describe(`prune with ${JSON.stringify(header)} header`, () => {
describe('prune', () => {
it('given one element added, the generated file contains only this element', async () => {
// Arrange
mockedParseXmlFileToJson.mockResolvedValueOnce({ ...header, ...alert })
mockedParseXmlFileToJson.mockResolvedValueOnce({
...header,
...alertTest,
})
mockedParseXmlFileToJson.mockResolvedValueOnce(alert)
mockedParseXmlFileToJson.mockResolvedValueOnce(alertTest)
await metadataDiff.compare('file/path')

// Act
const { isEmpty } = metadataDiff.prune()

// Assert
expect(convertJsonToXml).toHaveBeenCalledWith({
...header,
...alertOther,
})
expect(convertJsonToXml).toHaveBeenCalledWith(alertOther)
expect(isEmpty).toBe(false)
})
it('given every element deleted, the generated file is empty', async () => {
// Arrange
mockedParseXmlFileToJson.mockResolvedValueOnce({ ...header, ...wfBase })
mockedParseXmlFileToJson.mockResolvedValueOnce({ ...header, ...alert })
mockedParseXmlFileToJson.mockResolvedValueOnce(alertTest)
mockedParseXmlFileToJson.mockResolvedValueOnce(alert)
await metadataDiff.compare('file/path')

// Act
const { isEmpty } = metadataDiff.prune()

// Assert
expect(convertJsonToXml).toHaveBeenCalledWith({ ...header, ...wfBase })
expect(convertJsonToXml).toHaveBeenCalledWith({
...wfBase,
Workflow: {
...wfBase.Workflow,
alerts: [],
},
})
expect(isEmpty).toBe(true)
})
it('given file contains only new element, it keeps the file identical', async () => {
// Arrange
mockedParseXmlFileToJson.mockResolvedValueOnce({ ...header, ...alert })
mockedParseXmlFileToJson.mockResolvedValueOnce({ ...header, ...wfBase })
mockedParseXmlFileToJson.mockResolvedValueOnce(alert)
mockedParseXmlFileToJson.mockResolvedValueOnce(wfBase)
await metadataDiff.compare('file/path')

// Act
const { isEmpty } = metadataDiff.prune()

// Assert
expect(convertJsonToXml).toHaveBeenCalledWith({ ...header, ...alert })
expect(convertJsonToXml).toHaveBeenCalledWith(alert)
expect(isEmpty).toBe(false)
})

it('given one element modified, the generated file contains only this element', async () => {
// Arrange
mockedParseXmlFileToJson.mockResolvedValueOnce(alertOther)
mockedParseXmlFileToJson.mockResolvedValueOnce({
...header,
...alertOther,
})
mockedParseXmlFileToJson.mockResolvedValueOnce({
...header,
...alertOther,
Workflow: {
...alertOther.Workflow,
Expand All @@ -287,27 +280,21 @@ describe.each([[{}], [xmlHeader]])(`MetadataDiff`, header => {
const { isEmpty } = metadataDiff.prune()

// Assert
expect(convertJsonToXml).toHaveBeenCalledWith({
...header,
...alertOther,
})
expect(convertJsonToXml).toHaveBeenCalledWith(alertOther)
expect(isEmpty).toBe(false)
})

it('given untracked element, nothing trackable changed, the generated file contains untracked elements', async () => {
// Arrange
mockedParseXmlFileToJson.mockResolvedValueOnce({
...header,
...unTracked,
})
mockedParseXmlFileToJson.mockResolvedValueOnce({ ...header, ...wfBase })
mockedParseXmlFileToJson.mockResolvedValueOnce(unTracked)
mockedParseXmlFileToJson.mockResolvedValueOnce(wfBase)
await metadataDiff.compare('file/path')

// Act
const { isEmpty } = metadataDiff.prune()

// Assert
expect(convertJsonToXml).toHaveBeenCalledWith({ ...header, ...unTracked })
expect(convertJsonToXml).toHaveBeenCalledWith(unTracked)
expect(isEmpty).toBe(false)
})
})
Expand Down
Loading

0 comments on commit f374a3e

Please sign in to comment.