forked from scolladon/sfdx-git-delta
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "fix: xml header consideration for inFile metadata type handler (
scolladon#811)" This reverts commit 71b1217.
- Loading branch information
Showing
6 changed files
with
329 additions
and
350 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
|
@@ -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('') | ||
|
@@ -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') | ||
|
@@ -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') | ||
|
@@ -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') | ||
|
@@ -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') | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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) | ||
}) | ||
}) | ||
|
Oops, something went wrong.