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

feat: handle decomposed type #825

Merged
merged 19 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
dffb7d2
refactor: rename subCustomObjectHandler to decomposedHandler
scolladon Apr 4, 2024
8c16a8b
refactor: fix linting issue
scolladon Apr 4, 2024
bea5a2b
refactor: extract `EXTENSION_SUFFIX_REGEX` constant for later reuse
scolladon Apr 5, 2024
54e8b5d
fix: missing await
scolladon Apr 5, 2024
761af87
feat: add hanging decomposed type to handle permission set decomposition
scolladon Apr 5, 2024
e2ccbcb
refactor: use `xmlName` instead of `directoryName`
scolladon Apr 8, 2024
695d53d
build: fix wireit cache detection configuration
scolladon Apr 8, 2024
dc964f3
refactor: remove `hangingDecomposed` and use `inResource` instead
scolladon Apr 9, 2024
e5659c2
refactor: isolate implementation specific to custom label
scolladon Apr 11, 2024
b108346
refactor: isolate implementation specific to custom fields
scolladon Apr 11, 2024
81a9903
test: fix NUT test assert because of added e2e test cases
scolladon Apr 11, 2024
ffcd1be
fix: remove eslint annotation not needed
scolladon Apr 11, 2024
0293991
build: centralize eslint configuration
scolladon Apr 11, 2024
923d782
refactor: improve searchByExtension performance
scolladon Apr 17, 2024
6b5b853
refactor: improve lisibility and `find` usage
scolladon Apr 17, 2024
ba1ecd5
refactor: secure unsafe extension management
scolladon Apr 17, 2024
0ef1482
refactor: decrease cognitive complexity
scolladon Apr 17, 2024
7cd86c0
build: upgrade dependencies
scolladon Apr 8, 2024
4d4487f
build: fix pr number detection for dev version cleaner
scolladon Apr 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .eslintignore

This file was deleted.

1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = {
'output',
'reports',
'e2e',
'.github',
],
parser: '@typescript-eslint/parser',
parserOptions: {
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/on-merged-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:

- uses: jwalton/gh-find-current-pr@master
id: pr-number
with:
state: closed

- name: Set dev channel value
run: |
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ This repository provide [.prettierignore](.prettierignore) and [.prettierrc](.pr

### Code linting

[ESLint](https://eslint.org/) is a popular JavaScript linting tool used to identify stylistic errors and erroneous constructs. This repository provide [.eslintignore](.eslintignore) file to exclude specific files from the linting process.
[ESLint](https://eslint.org/) is a popular JavaScript linting tool used to identify stylistic errors and erroneous constructs.

### Commit linting

Expand Down
4 changes: 2 additions & 2 deletions __tests__/functional/delta.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ describe('sgd:source:delta NUTS', () => {
const destructiveChangesLineCount = await getFileLineNumber(
'e2e/expected/destructiveChanges/destructiveChanges.xml'
)
expect(packageLineCount).to.equal(221)
expect(destructiveChangesLineCount).to.equal(130)
expect(packageLineCount).to.equal(232)
expect(destructiveChangesLineCount).to.equal(137)
expect(result).to.include('"error": null')
expect(result).to.include('"success": true')
})
Expand Down
16 changes: 15 additions & 1 deletion __tests__/integration/services.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ jest.mock('../../src/utils/fsHelper')

const mockedReadPathFromGit = jest.mocked(readPathFromGit)
const testContext = [
[
'force-app/main/default/permissionsets/Admin/permissionSetFieldPermissions/Account.Test__c.permissionSetFieldPermission-meta.xml',
new Set(['Admin']),
'PermissionSet',
],
[
'force-app/main/default/sharingRules/Account/sharingCriteriaRules/TestSharingCriteria.sharingCriteriaRule-meta.xml',
new Set(['Account.TestSharingCriteria']),
'SharingCriteriaRule',
],
[
'force-app/main/default/workflows/Account/alerts/TestWFAlert.alert-meta.xml',
new Set(['Account.TestWFAlert']),
'WorkflowAlert',
],
[
'force-app/main/default/bots/TestBot/TestBot.bot-meta.xml',
new Set(['TestBot']),
Expand Down Expand Up @@ -426,7 +441,6 @@ const testContext = [

let globalMetadata: MetadataRepository
beforeAll(async () => {
// eslint-disable-next-line no-undef
globalMetadata = await getGlobalMetadata()
})
let work: Work
Expand Down
14 changes: 7 additions & 7 deletions __tests__/unit/lib/metadata/MetadataRepositoryImpl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ describe('MetadataRepositoryImpl', () => {
suffix: 'document',
xmlName: 'Document',
},
{
directoryName: 'restrictionRules',
inFolder: false,
metaFile: false,
suffix: 'rule',
xmlName: 'RestrictionRule',
},
{
directoryName: 'moderation',
inFolder: false,
Expand Down Expand Up @@ -70,13 +77,6 @@ describe('MetadataRepositoryImpl', () => {
suffix: 'object',
xmlName: 'CustomObject',
},
{
directoryName: 'restrictionRules',
inFolder: false,
metaFile: false,
suffix: 'rule',
xmlName: 'RestrictionRule',
},
{
directoryName: 'classes',
inFolder: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ describe('IncludeProcessor', () => {
let metadata: MetadataRepository

beforeAll(async () => {
// eslint-disable-next-line no-undef
metadata = await getGlobalMetadata()
})

Expand Down
18 changes: 16 additions & 2 deletions __tests__/unit/lib/service/botHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,28 @@ import { expect, jest, describe, it } from '@jest/globals'

import { MetadataRepository } from '../../../../src/metadata/MetadataRepository'
import BotHandler from '../../../../src/service/botHandler'
import { Metadata } from '../../../../src/types/metadata'
import type { Work } from '../../../../src/types/work'
import { copyFiles } from '../../../../src/utils/fsHelper'
import { getGlobalMetadata, getWork } from '../../../__utils__/globalTestHelper'

jest.mock('../../../../src/utils/fsHelper')

const objectType = 'bots'
const objectType: Metadata = {
directoryName: 'bots',
inFolder: false,
metaFile: true,
content: [
{
suffix: 'bot',
xmlName: 'Bot',
},
{
suffix: 'botVersion',
xmlName: 'BotVersion',
},
],
}
const line =
'A force-app/main/default/bots/TestBot/v1.botVersion-meta.xml'

Expand All @@ -22,7 +37,6 @@ beforeEach(() => {
describe('BotHandler', () => {
let globalMetadata: MetadataRepository
beforeAll(async () => {
// eslint-disable-next-line no-undef
globalMetadata = await getGlobalMetadata()
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect, jest, describe, it } from '@jest/globals'

import { MASTER_DETAIL_TAG } from '../../../../src/constant/metadataConstants'
import { MetadataRepository } from '../../../../src/metadata/MetadataRepository'
import SubCustomObjectHandler from '../../../../src/service/subCustomObjectHandler'
import CustomFieldHandler from '../../../../src/service/customFieldHandler'
import type { Work } from '../../../../src/types/work'
import { readPathFromGit, copyFiles } from '../../../../src/utils/fsHelper'
import { getGlobalMetadata, getWork } from '../../../__utils__/globalTestHelper'
Expand All @@ -12,7 +12,13 @@ jest.mock('../../../../src/utils/fsHelper')

const mockedReadPathFromGit = jest.mocked(readPathFromGit)

const objectType = 'fields'
const objectType = {
directoryName: 'fields',
inFolder: false,
metaFile: false,
suffix: 'field',
xmlName: 'CustomField',
}
const line =
'A force-app/main/default/objects/Account/fields/awesome.field-meta.xml'

Expand All @@ -22,23 +28,17 @@ beforeEach(() => {
work = getWork()
})

describe('SubCustomObjectHandler', () => {
describe('CustomFieldHandler', () => {
let globalMetadata: MetadataRepository
beforeAll(async () => {
// eslint-disable-next-line no-undef
globalMetadata = await getGlobalMetadata()
})

describe('when called with generateDelta false', () => {
it('should not handle master detail exception', async () => {
// Arrange
work.config.generateDelta = false
const sut = new SubCustomObjectHandler(
line,
objectType,
work,
globalMetadata
)
const sut = new CustomFieldHandler(line, objectType, work, globalMetadata)

// Act
await sut.handleAddition()
Expand All @@ -52,7 +52,7 @@ describe('SubCustomObjectHandler', () => {
it('should not handle master detail exception', async () => {
// Arrange
mockedReadPathFromGit.mockResolvedValueOnce('')
const sut = new SubCustomObjectHandler(
const sut = new CustomFieldHandler(
line,
objectType,
work,
Expand All @@ -71,7 +71,7 @@ describe('SubCustomObjectHandler', () => {
it('should copy the parent object', async () => {
// Arrange
mockedReadPathFromGit.mockResolvedValueOnce(MASTER_DETAIL_TAG)
const sut = new SubCustomObjectHandler(
const sut = new CustomFieldHandler(
line,
objectType,
work,
Expand Down
88 changes: 88 additions & 0 deletions __tests__/unit/lib/service/customLabelHandler.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
'use strict'
import { expect, jest, describe, it } from '@jest/globals'

import { MetadataRepository } from '../../../../src/metadata/MetadataRepository'
import CustomLabelHandler from '../../../../src/service/customLabelHandler'
import type { Work } from '../../../../src/types/work'
import { getGlobalMetadata, getWork } from '../../../__utils__/globalTestHelper'

const labelType = {
directoryName: 'labels',
inFolder: false,
metaFile: false,
parentXmlName: 'CustomLabels',
xmlName: 'CustomLabel',
childXmlNames: ['CustomLabel'],
suffix: 'labels',
xmlTag: 'labels',
key: 'fullName',
}

let globalMetadata: MetadataRepository
beforeAll(async () => {
globalMetadata = await getGlobalMetadata()
})
let work: Work
beforeEach(() => {
jest.clearAllMocks()
work = getWork()
})

describe('Decomposed CustomLabel spec', () => {
const line = 'force-app/main/default/labels/Test.label-meta.xml'
describe('when file is added', () => {
let sut: CustomLabelHandler
beforeEach(() => {
// Arrange
sut = new CustomLabelHandler(line, labelType, work, globalMetadata)
})
it('should add the element in the package', async () => {
// Arrange

// Act
await sut.handleAddition()

// Assert
expect(work.diffs.destructiveChanges.size).toEqual(0)
expect(work.diffs.package.get('CustomLabel')).toEqual(new Set(['Test']))
})
})

describe('when file is modified', () => {
let sut: CustomLabelHandler
beforeEach(() => {
// Arrange
sut = new CustomLabelHandler(line, labelType, work, globalMetadata)
})
it('should add the element in the package', async () => {
// Arrange

// Act
await sut.handleModification()

// Assert
expect(work.diffs.destructiveChanges.size).toEqual(0)
expect(work.diffs.package.get('CustomLabel')).toEqual(new Set(['Test']))
})
})

describe('when file is deleted', () => {
let sut: CustomLabelHandler
beforeEach(() => {
// Arrange
sut = new CustomLabelHandler(line, labelType, work, globalMetadata)
})
it('should add the element in the destructiveChanges', async () => {
// Arrange

// Act
await sut.handleDeletion()

// Assert
expect(work.diffs.package.size).toEqual(0)
expect(work.diffs.destructiveChanges.get('CustomLabel')).toEqual(
new Set(['Test'])
)
})
})
})
32 changes: 29 additions & 3 deletions __tests__/unit/lib/service/customObjectHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,34 @@ const mockedReadPathFromGit = jest.mocked(readPathFromGit)

mockedPathExist.mockResolvedValue(true)

const objectType = 'objects'
const territoryModelType = {
childXmlNames: ['Territory2Rule', 'Territory2'],
directoryName: 'territory2Models',
inFolder: false,
metaFile: false,
suffix: 'territory2Model',
xmlName: 'Territory2Model',
}
const objectType = {
childXmlNames: [
'CustomField',
'Index',
'BusinessProcess',
'RecordType',
'CompactLayout',
'WebLink',
'ValidationRule',
'SharingReason',
'ListView',
'FieldSet',
],
directoryName: 'objects',
inFolder: false,
metaFile: false,
suffix: 'object',
xmlName: 'CustomObject',
}

const line =
'A force-app/main/default/objects/Account/Account.object-meta.xml'

Expand All @@ -34,7 +61,6 @@ beforeEach(() => {
describe('CustomObjectHandler', () => {
let globalMetadata: MetadataRepository
beforeAll(async () => {
// eslint-disable-next-line no-undef
globalMetadata = await getGlobalMetadata()
})

Expand Down Expand Up @@ -63,7 +89,7 @@ describe('CustomObjectHandler', () => {
// Arrange
const sut = new CustomObjectHandler(
'A force-app/main/default/territory2Models/EU/EU.territory2Model-meta.xml',
'territory2Models',
territoryModelType,
work,
globalMetadata
)
Expand Down
Loading
Loading