Skip to content

Commit

Permalink
fix(cli): add api version exclusion to avoid deprecated config name (s…
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbcovert committed Jun 27, 2023
1 parent 7a69ed0 commit 4147a55
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 141 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,16 @@ If you run your CI/CD jobs inside a Docker image, you can add the plugin to your
## How to use it?

<!-- commands -->
* [`sfdx sgd:source:delta -f <string> [-t <string>] [-r <filepath>] [-i <filepath>] [-D <filepath>] [-s <filepath>] [-W] [-o <filepath>] [-a <number>] [-d] [-n <filepath>] [-N <filepath>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-sgdsourcedelta--f-string--t-string--r-filepath--i-filepath--d-filepath--s-filepath--w--o-filepath--a-number--d--n-filepath--n-filepath---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
* [`sfdx sgd:source:delta -f <string> [-t <string>] [-r <filepath>] [-i <filepath>] [-D <filepath>] [-s <filepath>] [-W] [-o <filepath>] [-a <number>] [-x] [-d] [-n <filepath>] [-N <filepath>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-sgdsourcedelta--f-string--t-string--r-filepath--i-filepath--d-filepath--s-filepath--w--o-filepath--a-number--x--d--n-filepath--n-filepath---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)

## `sfdx sgd:source:delta -f <string> [-t <string>] [-r <filepath>] [-i <filepath>] [-D <filepath>] [-s <filepath>] [-W] [-o <filepath>] [-a <number>] [-d] [-n <filepath>] [-N <filepath>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`
## `sfdx sgd:source:delta -f <string> [-t <string>] [-r <filepath>] [-i <filepath>] [-D <filepath>] [-s <filepath>] [-W] [-o <filepath>] [-a <number>] [-x] [-d] [-n <filepath>] [-N <filepath>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`

Generate the sfdx content in source format and destructive change from two git commits

```
USAGE
$ sfdx sgd:source:delta -f <string> [-t <string>] [-r <filepath>] [-i <filepath>] [-D <filepath>] [-s <filepath>] [-W]
[-o <filepath>] [-a <number>] [-d] [-n <filepath>] [-N <filepath>] [--json] [--loglevel
[-o <filepath>] [-a <number>] [-x] [-d] [-n <filepath>] [-N <filepath>] [--json] [--loglevel
trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
Expand All @@ -155,7 +155,8 @@ OPTIONS
-a, --api-version=api-version salesforce metadata API version,
default to sfdx-project.json
"sourceApiVersion" attribute or
latest version
latest version, ignored if
--exclude-api-version enabled
-d, --generate-delta generate delta files in [--output]
folder
Expand All @@ -182,6 +183,10 @@ OPTIONS
-t, --to=to [default: HEAD] commit sha to where
the diff is done
-x, --exclude-api-version Execute sfdx commands without a
specified salesforce metadata API
version
--json format output as json
--loglevel=(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL) [default: warn] logging level for
Expand Down
291 changes: 157 additions & 134 deletions __tests__/unit/lib/utils/cliHelper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,162 +331,185 @@ describe(`test if the application`, () => {
beforeAll(async () => {
latestAPIVersionSupported = await getLatestSupportedVersion()
})
describe('when apiVersion parameter is set with supported value', () => {
test.each([46, 52, 55])(
'config.apiVersion (%s) equals the parameter',
async version => {
// Arrange
const work = {
...testConfig,
config: {
...testConfig.config,
apiVersion: version,
},
warnings: [],

for(const excludeApiVersion of [false, true]) {
describe('when apiVersion parameter is set with supported value', () => {
test.each([46, 52, 55])(
'config.apiVersion (%s) equals the parameter',
async version => {
// Arrange
const work = {
...testConfig,
config: {
...testConfig.config,
apiVersion: version,
excludeApiVersion,
},
warnings: [],
}
const cliHelper = new CLIHelper(work)

// Act
await cliHelper._handleDefault()

// Assert
expect(work.config.apiVersion).toEqual(
excludeApiVersion ? undefined : version
)
expect(work.warnings.length).toEqual(0)
}
const cliHelper = new CLIHelper(work)

// Act
await cliHelper._handleDefault()

// Assert
expect(work.config.apiVersion).toEqual(version)
expect(work.warnings.length).toEqual(0)
}
)
})
describe('when apiVersion parameter is set with unsupported value', () => {
test.each(['NaN', 40, 55.1, 'awesome', '1000000000', 0])(
`config.apiVersion (%s) equals the latest version `,
async version => {
// Arrange
const work = {
...testConfig,
config: {
...testConfig.config,
apiVersion: version,
},
warnings: [],
)
})
describe('when apiVersion parameter is set with unsupported value', () => {
test.each(['NaN', 40, 55.1, 'awesome', '1000000000', 0])(
`config.apiVersion (%s) equals the latest version `,
async version => {
// Arrange
const work = {
...testConfig,
config: {
...testConfig.config,
apiVersion: version,
excludeApiVersion,
},
warnings: [],
}
const cliHelper = new CLIHelper(work)

// Act
await cliHelper._handleDefault()

// Assert
expect(work.config.apiVersion).toEqual(
excludeApiVersion ? undefined : latestAPIVersionSupported
)
expect(work.warnings.length).toEqual(excludeApiVersion ? 0 : 1)
}
const cliHelper = new CLIHelper(work)

// Act
await cliHelper._handleDefault()

// Assert
expect(work.config.apiVersion).toEqual(latestAPIVersionSupported)
expect(work.warnings.length).toEqual(1)
}
)
})

describe('when apiVersion parameter is not set', () => {
describe('when sfdx-project.json file exist', () => {
describe('when "sourceApiVersion" attribute is set with supported value', () => {
test.each(['46', '52', '55', '46.0', '52.0', '55.0'])(
'config.apiVersion (%s) equals the "sourceApiVersion" attribute',
async version => {
// Arrange
fs.__setMockFiles({
...mockFiles,
'sfdx-project.json': `{"sourceApiVersion":${version}}`,
})

const work = {
...testConfig,
config: {
...testConfig.config,
apiVersion: undefined,
},
warnings: [],
)
})

describe('when apiVersion parameter is not set', () => {
describe('when sfdx-project.json file exist', () => {
describe('when "sourceApiVersion" attribute is set with supported value', () => {
test.each(['46', '52', '55', '46.0', '52.0', '55.0'])(
'config.apiVersion (%s) equals the "sourceApiVersion" attribute',
async version => {
// Arrange
fs.__setMockFiles({
...mockFiles,
'sfdx-project.json': `{"sourceApiVersion":${version}}`,
})

const work = {
...testConfig,
config: {
...testConfig.config,
apiVersion: undefined,
excludeApiVersion,
},
warnings: [],
}
const cliHelper = new CLIHelper(work)

// Act
await cliHelper._handleDefault()

// Assert
expect(work.config.apiVersion).toEqual(
excludeApiVersion ? undefined : +version
)
expect(work.warnings.length).toEqual(0)
}
const cliHelper = new CLIHelper(work)

// Act
await cliHelper._handleDefault()

// Assert
expect(work.config.apiVersion).toEqual(+version)
expect(work.warnings.length).toEqual(0)
}
)
})
describe('when "sourceApiVersion" attribute is set with unsupported value', () => {
test.each([NaN, '40', 'awesome', 1000000000, ''])(
'config.apiVersion (%s) equals the latest version',
async version => {
)
})
describe('when "sourceApiVersion" attribute is set with unsupported value', () => {
test.each([NaN, '40', 'awesome', 1000000000, ''])(
'config.apiVersion (%s) equals the latest version',
async version => {
// Arrange
fs.__setMockFiles({
...mockFiles,
'sfdx-project.json': `{"sourceApiVersion":"${version}"}`,
})

const work = {
...testConfig,
config: {
...testConfig.config,
apiVersion: undefined,
excludeApiVersion,
},
warnings: [],
}
const cliHelper = new CLIHelper(work)

// Act
await cliHelper._handleDefault()

// Assert
expect(work.config.apiVersion).toEqual(
excludeApiVersion ? undefined : latestAPIVersionSupported
)
expect(work.warnings.length).toEqual(excludeApiVersion ? 0 : 1)
}
)
})

describe('when "sourceApiVersion" attribute is not set', () => {
test('config.apiVersion equals the latest version', async () => {
// Arrange
fs.__setMockFiles({
...mockFiles,
'sfdx-project.json': `{"sourceApiVersion":"${version}"}`,
'sfdx-project.json': `{}`,
})

const work = {
...testConfig,
config: {
...testConfig.config,
apiVersion: undefined,
excludeApiVersion,
},
warnings: [],
}
const cliHelper = new CLIHelper(work)

// Act
await cliHelper._handleDefault()

// Assert
expect(work.config.apiVersion).toEqual(latestAPIVersionSupported)
expect(work.warnings.length).toEqual(1)
}
)
})

test('when "sourceApiVersion" attribute is not set', async () => {
// Arrange
fs.__setMockFiles({
...mockFiles,
'sfdx-project.json': `{}`,
expect(work.config.apiVersion).toEqual(
excludeApiVersion ? undefined : latestAPIVersionSupported
)
expect(work.warnings.length).toEqual(excludeApiVersion ? 0 : 1)
})
})

const work = {
...testConfig,
config: {
...testConfig.config,
apiVersion: undefined,
},
warnings: [],
}
const cliHelper = new CLIHelper(work)

// Act
await cliHelper._handleDefault()

// Assert
expect(work.config.apiVersion).toEqual(latestAPIVersionSupported)
expect(work.warnings.length).toEqual(1)
})
})
describe('when sfdx-project.json file does not exist', () => {
test('config.apiVersion equals the latest version', async () => {
// Arrange
const work = {
...testConfig,
config: {
...testConfig.config,
apiVersion: undefined,
},
warnings: [],
}
const cliHelper = new CLIHelper(work)

// Act
await cliHelper._handleDefault()

// Assert
expect(work.config.apiVersion).toEqual(latestAPIVersionSupported)
expect(work.warnings.length).toEqual(0)
describe('when sfdx-project.json file does not exist', () => {
test('config.apiVersion equals the latest version', async () => {
// Arrange
const work = {
...testConfig,
config: {
...testConfig.config,
apiVersion: undefined,
excludeApiVersion,
},
warnings: [],
}
const cliHelper = new CLIHelper(work)

// Act
await cliHelper._handleDefault()

// Assert
expect(work.config.apiVersion).toEqual(
excludeApiVersion ? undefined : latestAPIVersionSupported
)
expect(work.warnings.length).toEqual(0)
})
})
})
})
}
})
})
4 changes: 3 additions & 1 deletion messages/delta.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ module.exports = {
ignoreDestructiveFlag:
'file listing paths to explicitly ignore for any destructive actions',
apiVersionFlag:
'salesforce metadata API version, default to sfdx-project.json "sourceApiVersion" attribute or latest version',
'salesforce metadata API version, default to sfdx-project.json "sourceApiVersion" attribute or latest version, ignored if --exclude-api-version enabled',
excludeApiVersionFlag:
'Execute sfdx commands without a specified salesforce metadata API version',
deltaFlag: 'generate delta files in [--output] folder',
ignoreWhitespaceFlag: 'ignore git diff whitespace (space, tab, eol) changes',
includeFlag: 'file listing paths to explicitly include for any diff actions',
Expand Down
7 changes: 7 additions & 0 deletions src/commands/sgd/source/delta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
REPO_DEFAULT_VALUE,
SOURCE_DEFAULT_VALUE,
OUTPUT_DEFAULT_VALUE,
EXCLUDE_API_VERSION_DEFAULT_VALUE,
} = require('../../../utils/cliHelper')

// Initialize Messages with the current plugin directory
Expand Down Expand Up @@ -62,6 +63,11 @@ export default class SourceDeltaGenerate extends SfdxCommand {
char: 'a',
description: messages.getMessage('apiVersionFlag'),
}),
'exclude-api-version': flags.boolean({
char: 'x',
description: messages.getMessage('excludeApiVersionFlag'),
default: EXCLUDE_API_VERSION_DEFAULT_VALUE,
}),
'generate-delta': flags.boolean({
char: 'd',
description: messages.getMessage('deltaFlag'),
Expand Down Expand Up @@ -92,6 +98,7 @@ export default class SourceDeltaGenerate extends SfdxCommand {
ignore: this.flags.ignore,
ignoreDestructive: this.flags['ignore-destructive'],
apiVersion: this.flags['api-version'],
excludeApiVersion: this.flags['exclude-api-version'],
repo: this.flags.repo,
ignoreWhitespace: this.flags['ignore-whitespace'],
generateDelta: this.flags['generate-delta'],
Expand Down
Loading

0 comments on commit 4147a55

Please sign in to comment.