Skip to content

Commit

Permalink
fix: metadata type detection for subtype not packageable contained in…
Browse files Browse the repository at this point in the history
…side file (scolladon#858)
  • Loading branch information
scolladon authored May 6, 2024
1 parent 5941fcd commit a55a528
Show file tree
Hide file tree
Showing 4 changed files with 501 additions and 418 deletions.
227 changes: 148 additions & 79 deletions __tests__/unit/lib/service/inFileHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,49 +84,85 @@ describe.each([true, false])(`inFileHandler -d: %s`, generateDelta => {
new Set(['Account.test'])
)

expect(mockPrune).toHaveBeenCalled()
if (generateDelta) {
expect(mockPrune).toHaveBeenCalled()
expect(writeFile).toHaveBeenCalled()
} else {
expect(mockPrune).not.toHaveBeenCalled()
expect(writeFile).not.toHaveBeenCalled()
}
})

describe('when metadata in file is not packable', () => {
beforeEach(() => {
// Arrange
sut = new InFileHandler(
'force-app/main/default/globalValueSetTranslations/Numbers-fr.globalValueSetTranslation-meta.xml',
globalValueSetTranslationsType,
work,
globalMetadata
)
mockCompare.mockImplementation(() =>
Promise.resolve({
added: new Map([['ValueTranslation', new Set(['Three'])]]),
deleted: new Map(),
})
)
describe('when file have comparable metadata', () => {
beforeEach(() => {
// Arrange
sut = new InFileHandler(
'force-app/main/default/globalValueSetTranslations/Numbers-fr.globalValueSetTranslation-meta.xml',
globalValueSetTranslationsType,
work,
globalMetadata
)
mockCompare.mockImplementation(() =>
Promise.resolve({
added: new Map([['ValueTranslation', new Set(['Three'])]]),
deleted: new Map(),
})
)
})
it('should only store file name and not the metadata in file', async () => {
// Act
await sut.handleAddition()

// Assert
expect(work.diffs.destructiveChanges.size).toEqual(0)
expect(work.diffs.package.get('GlobalValueSetTranslation')).toEqual(
new Set(['Numbers-fr'])
)
expect(work.diffs.package.size).toEqual(1)

expect(mockPrune).toHaveBeenCalled()
if (generateDelta) {
expect(writeFile).toHaveBeenCalled()
} else {
expect(writeFile).not.toHaveBeenCalled()
}
})
})
it('should only store file name and not the metadata in file', async () => {
// Act
await sut.handleAddition()

// Assert
expect(work.diffs.destructiveChanges.size).toEqual(0)
expect(work.diffs.package.get('GlobalValueSetTranslation')).toEqual(
new Set(['Numbers-fr'])
)
expect(work.diffs.package.size).toEqual(1)
describe('when file does not have comparable metadata but is not empty', () => {
beforeEach(() => {
// Arrange
sut = new InFileHandler(
'force-app/main/default/globalValueSetTranslations/Numbers-fr.globalValueSetTranslation-meta.xml',
globalValueSetTranslationsType,
work,
globalMetadata
)
mockCompare.mockImplementation(() =>
Promise.resolve({
added: new Map(),
deleted: new Map(),
})
)
})
it('should only store file name and not the metadata in file', async () => {
// Act
await sut.handleAddition()

// Assert
expect(work.diffs.destructiveChanges.size).toEqual(0)
expect(work.diffs.package.get('GlobalValueSetTranslation')).toEqual(
new Set(['Numbers-fr'])
)
expect(work.diffs.package.size).toEqual(1)

if (generateDelta) {
expect(mockPrune).toHaveBeenCalled()
expect(writeFile).toHaveBeenCalled()
} else {
expect(mockPrune).not.toHaveBeenCalled()
expect(writeFile).not.toHaveBeenCalled()
}
if (generateDelta) {
expect(writeFile).toHaveBeenCalled()
} else {
expect(writeFile).not.toHaveBeenCalled()
}
})
})
})
})
Expand Down Expand Up @@ -163,11 +199,10 @@ describe.each([true, false])(`inFileHandler -d: %s`, generateDelta => {
new Set(['Account.deleted'])
)
expect(work.diffs.destructiveChanges.has('Workflow')).toBe(false)
expect(mockPrune).toHaveBeenCalled()
if (generateDelta) {
expect(mockPrune).toHaveBeenCalled()
expect(writeFile).toHaveBeenCalled()
} else {
expect(mockPrune).not.toHaveBeenCalled()
expect(writeFile).not.toHaveBeenCalled()
}
})
Expand All @@ -188,6 +223,10 @@ describe.each([true, false])(`inFileHandler -d: %s`, generateDelta => {
deleted: new Map([['WorkflowAlert', new Set(['deleted'])]]),
})
)
mockPrune.mockReturnValue({
xmlContent: '<xmlContent>',
isEmpty: true,
})
})
it('should store the deleted in the destructiveChanges and not copy the file', async () => {
// Act
Expand All @@ -199,13 +238,8 @@ describe.each([true, false])(`inFileHandler -d: %s`, generateDelta => {
new Set(['Account.deleted'])
)
expect(work.diffs.destructiveChanges.has('Workflow')).toBe(false)
if (generateDelta) {
expect(mockPrune).toHaveBeenCalled()
expect(writeFile).toHaveBeenCalled()
} else {
expect(mockPrune).not.toHaveBeenCalled()
expect(writeFile).not.toHaveBeenCalled()
}
expect(mockPrune).toHaveBeenCalled()
expect(writeFile).not.toHaveBeenCalled()
})

describe('when no metadata element are added/deleted and the file does not contains attributes', () => {
Expand Down Expand Up @@ -237,11 +271,10 @@ describe.each([true, false])(`inFileHandler -d: %s`, generateDelta => {
// Assert
expect(work.diffs.package.size).toEqual(0)
expect(work.diffs.destructiveChanges.size).toEqual(0)
expect(mockPrune).toHaveBeenCalled()
if (generateDelta) {
expect(mockPrune).toHaveBeenCalled()
expect(writeFile).not.toHaveBeenCalled()
} else {
expect(mockPrune).not.toHaveBeenCalled()
expect(writeFile).not.toHaveBeenCalled()
}
})
Expand All @@ -264,7 +297,7 @@ describe.each([true, false])(`inFileHandler -d: %s`, generateDelta => {
)
mockPrune.mockReturnValue({
xmlContent: '<xmlContent>',
isEmpty: false,
isEmpty: true,
})
})
it('should store the added metadata in the package and the file should be copied', async () => {
Expand All @@ -277,52 +310,87 @@ describe.each([true, false])(`inFileHandler -d: %s`, generateDelta => {
expect(work.diffs.destructiveChanges.get('Workflow')).toEqual(
new Set(['Account.Deleted'])
)
expect(mockPrune).toHaveBeenCalled()
expect(writeFile).not.toHaveBeenCalled()
})
})
})

describe('when metadata in file is not packable', () => {
describe('when file have comparable metadata', () => {
beforeEach(() => {
// Arrange
sut = new InFileHandler(
'force-app/main/default/globalValueSetTranslations/Numbers-fr.globalValueSetTranslation-meta.xml',
globalValueSetTranslationsType,
work,
globalMetadata
)
mockCompare.mockImplementation(() =>
Promise.resolve({
added: new Map([['ValueTranslation', new Set(['Three'])]]),
deleted: new Map(),
})
)
mockPrune.mockReturnValue({
xmlContent: '<xmlContent>',
isEmpty: false,
})
})
it('should only store file name and not the metadata in file', async () => {
// Act
await sut.handleModification()

// Assert
expect(work.diffs.destructiveChanges.size).toEqual(0)
expect(work.diffs.package.get('GlobalValueSetTranslation')).toEqual(
new Set(['Numbers-fr'])
)
expect(work.diffs.package.size).toEqual(1)

expect(mockPrune).toHaveBeenCalled()
if (generateDelta) {
expect(mockPrune).toHaveBeenCalled()
expect(writeFile).toHaveBeenCalled()
} else {
expect(mockPrune).not.toHaveBeenCalled()
expect(writeFile).not.toHaveBeenCalled()
}
})
})
})

describe('when metadata in file is not packable', () => {
beforeEach(() => {
// Arrange
sut = new InFileHandler(
'force-app/main/default/globalValueSetTranslations/Numbers-fr.globalValueSetTranslation-meta.xml',
globalValueSetTranslationsType,
work,
globalMetadata
)

mockCompare.mockImplementation(() =>
Promise.resolve({
added: new Map([['ValueTranslation', new Set(['Three'])]]),
deleted: new Map(),
})
)
})
it('should only store file name and not the metadata in file', async () => {
// Act
await sut.handleModification()
describe('when file does not have comparable metadata but is not empty', () => {
beforeEach(() => {
// Arrange
sut = new InFileHandler(
'force-app/main/default/globalValueSetTranslations/Numbers-fr.globalValueSetTranslation-meta.xml',
globalValueSetTranslationsType,
work,
globalMetadata
)
mockCompare.mockImplementation(() =>
Promise.resolve({
added: new Map(),
deleted: new Map(),
})
)
})
it('should only store file name and not the metadata in file', async () => {
// Act
await sut.handleModification()

// Assert
expect(work.diffs.destructiveChanges.size).toEqual(0)
expect(work.diffs.package.get('GlobalValueSetTranslation')).toEqual(
new Set(['Numbers-fr'])
)
expect(work.diffs.package.size).toEqual(1)
// Assert
expect(work.diffs.destructiveChanges.size).toEqual(0)
expect(work.diffs.package.get('GlobalValueSetTranslation')).toEqual(
new Set(['Numbers-fr'])
)
expect(work.diffs.package.size).toEqual(1)

if (generateDelta) {
expect(mockPrune).toHaveBeenCalled()
expect(writeFile).toHaveBeenCalled()
} else {
expect(mockPrune).not.toHaveBeenCalled()
expect(writeFile).not.toHaveBeenCalled()
}
if (generateDelta) {
expect(writeFile).toHaveBeenCalled()
} else {
expect(writeFile).not.toHaveBeenCalled()
}
})
})
})
})
Expand All @@ -343,6 +411,7 @@ describe.each([true, false])(`inFileHandler -d: %s`, generateDelta => {
deleted: new Map([['WorkflowAlert', new Set(['test'])]]),
})
)
mockPrune.mockReturnValue({ xmlContent: '<xmlContent>', isEmpty: true })
})
it('should store the deleted metadata in the destructiveChanges', async () => {
// Act
Expand All @@ -355,7 +424,7 @@ describe.each([true, false])(`inFileHandler -d: %s`, generateDelta => {
new Set(['Account.test'])
)
expect(mockCompare).toHaveBeenCalled()
expect(mockPrune).not.toHaveBeenCalled()
expect(mockPrune).toHaveBeenCalled()
expect(writeFile).not.toHaveBeenCalled()
})
describe('when metadata in file is prune Only', () => {
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
"author": "Sebastien Colladon <colladonsebastien@gmail.com>",
"dependencies": {
"@salesforce/command": "^5.3.9",
"@salesforce/core": "^7.3.1",
"@salesforce/core": "^7.3.4",
"async": "^3.2.5",
"fast-xml-parser": "^4.3.6",
"fs-extra": "^11.2.0",
"ignore": "^5.3.1",
"isomorphic-git": "^1.25.7",
"isomorphic-git": "^1.25.8",
"lodash": "^4.17.21",
"simple-git": "^3.24.0",
"xmlbuilder2": "^3.1.1"
Expand Down Expand Up @@ -193,18 +193,18 @@
"@commitlint/config-conventional": "^19.2.2",
"@jest/globals": "^29.7.0",
"@oclif/dev-cli": "^1.26.10",
"@salesforce/cli-plugins-testkit": "^5.2.3",
"@salesforce/cli-plugins-testkit": "^5.3.2",
"@salesforce/dev-config": "^4.1.0",
"@salesforce/ts-sinon": "^1.4.19",
"@stryker-mutator/core": "^8.2.6",
"@stryker-mutator/jest-runner": "^8.2.6",
"@swc/core": "^1.5.0",
"@swc/core": "^1.4.17",
"@types/async": "^3.2.24",
"@types/jest": "^29.5.12",
"@types/mocha": "^10.0.6",
"@types/node": "^20.12.7",
"@typescript-eslint/eslint-plugin": "^7.7.1",
"@typescript-eslint/parser": "^7.7.1",
"@types/node": "^20.12.8",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"benchmark": "^2.1.4",
"chai": "^4.3.10",
"eslint": "^8.57.0",
Expand All @@ -213,7 +213,7 @@
"eslint-plugin-prettier": "^5.1.3",
"husky": "^9.0.11",
"jest": "^29.7.0",
"knip": "^5.10.0",
"knip": "^5.12.2",
"lint-staged": "^15.2.2",
"mocha": "^10.4.0",
"nyc": "^15.1.0",
Expand Down
Loading

0 comments on commit a55a528

Please sign in to comment.