Skip to content

Commit

Permalink
feat: handle decomposed type (#825)
Browse files Browse the repository at this point in the history
  • Loading branch information
scolladon committed Apr 22, 2024
1 parent 94f1a5a commit ec9ea59
Show file tree
Hide file tree
Showing 62 changed files with 1,648 additions and 1,641 deletions.
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
1 change: 0 additions & 1 deletion __tests__/unit/lib/post-processor/includeProcessor.test.ts
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

0 comments on commit ec9ea59

Please sign in to comment.