-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ccfff0
commit d9dc112
Showing
10 changed files
with
167 additions
and
128 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
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,40 +1,99 @@ | ||
import { TestContext } from '@salesforce/core/testSetup'; | ||
import { fileURLToPath } from 'node:url'; | ||
import { dirname, join } from 'node:path'; | ||
import * as fs from 'node:fs'; | ||
import { expect } from 'chai'; | ||
import { stubSfCommandUx } from '@salesforce/sf-plugins-core'; | ||
import { ux } from '@oclif/core'; | ||
import KcUpdateApi from '../../../src/commands/kc/update-api.js'; | ||
|
||
describe('kc update-api', () => { | ||
const $$ = new TestContext(); | ||
let sfCommandStubs: ReturnType<typeof stubSfCommandUx>; | ||
|
||
beforeEach(() => { | ||
sfCommandStubs = stubSfCommandUx($$.SANDBOX); | ||
it('runs update-api and throws error if no api-version is provided', async () => { | ||
try { | ||
const output = await KcUpdateApi.run(['--type', 'classes']); | ||
expect.fail(`Should throw an error. Response: ${JSON.stringify(output)}`); | ||
} catch (e) { | ||
expect((e as Error).message).to.include('Missing required flag api-version'); | ||
} | ||
}); | ||
|
||
afterEach(() => { | ||
$$.restore(); | ||
it('runs update-api and throws error if no type is provided', async () => { | ||
try { | ||
const output = await KcUpdateApi.run(['--api-version', '61.0']); | ||
expect.fail(`Should throw an error. Response: ${JSON.stringify(output)}`); | ||
} catch (e) { | ||
expect((e as Error).message).to.include('Missing required flag type'); | ||
} | ||
}); | ||
|
||
it('runs update-api', async () => { | ||
await KcUpdateApi.run(['--type', 'classes', '--api-version', '61.0']); | ||
const output = sfCommandStubs.log | ||
.getCalls() | ||
.flatMap((c) => c.args) | ||
.join('\n'); | ||
expect(output).to.include(''); | ||
it('runs update-api and throws error if invalid api version given', async () => { | ||
try { | ||
const output = await KcUpdateApi.run(['--type', 'classes', '--api-version', '10.0']); | ||
expect.fail(`Should throw an error. Response: ${JSON.stringify(output)}`); | ||
} catch (e) { | ||
expect((e as Error).message).to.include('The API version must be greater than'); | ||
} | ||
}); | ||
|
||
// it('runs hello with --json and no provided name', async () => { | ||
// const result = await KcUpdateApi.run([]); | ||
// expect(result.updatedNumber).to.equal(0); | ||
// }); | ||
|
||
// it('runs hello world --name Astro', async () => { | ||
// await KcUpdateApi.run(['--name', 'Astro']); | ||
// const output = sfCommandStubs.log | ||
// .getCalls() | ||
// .flatMap((c) => c.args) | ||
// .join('\n'); | ||
// expect(output).to.include('hello Astro'); | ||
// }); | ||
describe('update xml files', () => { | ||
const filename = fileURLToPath(import.meta.url); | ||
const fileDirName = dirname(filename); | ||
const xmlFilesPath = join(fileDirName, '../../xml'); | ||
const xmlBackupPath = join(fileDirName, '../../xmlBackup'); | ||
|
||
beforeEach(async () => { | ||
try { | ||
fs.cpSync(xmlFilesPath, xmlBackupPath, { recursive: true }); | ||
if (!fs.existsSync(xmlBackupPath)) { | ||
throw new Error(`Backup XML directory does not exist: ${xmlFilesPath}`); | ||
} | ||
} catch (error: unknown) { | ||
ux.error(error as Error); | ||
} | ||
}); | ||
|
||
afterEach(async () => { | ||
try { | ||
fs.rmSync(xmlFilesPath, { recursive: true, force: true }); | ||
fs.cpSync(xmlBackupPath, xmlFilesPath, { recursive: true }); | ||
fs.rmSync(xmlBackupPath, { recursive: true, force: true }); | ||
} catch (error: unknown) { | ||
ux.error(error as Error); | ||
} | ||
}); | ||
|
||
it('runs update-api to update 2 apex classes', async () => { | ||
const result = await KcUpdateApi.run(['-d', xmlFilesPath, '--type', 'classes', '--api-version', '61.0']); | ||
expect(result.updatedNumber).to.equal(2); | ||
}); | ||
|
||
it('runs update-api to update 1 apex class', async () => { | ||
const result = await KcUpdateApi.run(['-d', xmlFilesPath, '--type', 'classes', '--api-version', '58.0']); | ||
expect(result.updatedNumber).to.equal(1); | ||
}); | ||
|
||
it('runs update-api to update 1 trigger', async () => { | ||
const result = await KcUpdateApi.run(['-d', xmlFilesPath, '--type', 'triggers', '--api-version', '60.0']); | ||
expect(result.updatedNumber).to.equal(1); | ||
}); | ||
|
||
it('runs update-api to update 1 flow', async () => { | ||
const result = await KcUpdateApi.run(['-d', xmlFilesPath, '--type', 'flows', '--api-version', '60.0']); | ||
expect(result.updatedNumber).to.equal(1); | ||
}); | ||
|
||
it('runs update-api to update classes, triggers, and flows', async () => { | ||
const result = await KcUpdateApi.run([ | ||
'-d', | ||
xmlFilesPath, | ||
'--type', | ||
'classes', | ||
'--type', | ||
'triggers', | ||
'--type', | ||
'flows', | ||
'--api-version', | ||
'60.0', | ||
]); | ||
expect(result.updatedNumber).to.equal(4); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>57.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>58.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Flow xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>58.0</apiVersion> | ||
<status>Active</status> | ||
</Flow> |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>58.0</apiVersion> | ||
<status>Active</status> | ||
</ApexTrigger> |