Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Commit

Permalink
Merge pull request #179 from amtrack/feat/handle-flows-with-api-44
Browse files Browse the repository at this point in the history
handle flows with api 44
  • Loading branch information
amtrack authored Apr 8, 2019
2 parents e2ee12b + 1fbe0a5 commit 138b5c4
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var Config = module.exports = function(opts) {
config = {};
config.pollTimeout = opts.pollTimeout !== undefined ? opts.pollTimeout : 15 * 60 * 1000; // 15 minutes
config.defaultMetadataTypes = opts.defaultMetadataTypes !== undefined ? opts.defaultMetadataTypes : ['ApexClass', 'ApexComponent', 'ApexPage', 'ApexTrigger', 'CustomField', 'CustomObject', 'CustomTab', 'WebLink'];
config.defaultApiVersion = opts.defaultApiVersion !== undefined ? opts.defaultApiVersion : "41.0";
config.defaultApiVersion = opts.defaultApiVersion !== undefined ? opts.defaultApiVersion : "45.0";
config.folderBasedMetadataMap = opts.folderBasedMetadataMap !== undefined ? opts.folderBasedMetadataMap : {
'EmailFolder': 'EmailTemplate',
'DashboardFolder': 'Dashboard',
Expand Down
9 changes: 7 additions & 2 deletions lib/fetch-result-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ FetchResultParser.prototype.addStandardPicklists = function() {

FetchResultParser.prototype.transform = function() {
var self = this;
var majorApiVersion = parseInt(config.get('defaultApiVersion'));
var describeMetadataService = new(require('./describe-metadata-service'))(self.describeMetadataResult);
var metadataObjectsExtended = describeMetadataService.getTypes();
self.fileProperties = self.fileProperties.map(function(fileProperty) {
Expand All @@ -156,7 +157,7 @@ FetchResultParser.prototype.transform = function() {
if (Object.keys(folderBasedMetadataMap).indexOf(fileProperty.type) > -1) {
// DocumentFolder has to be listed as Document
fileProperty.type = folderBasedMetadataMap[fileProperty.type];
} else if (fileProperty.type === 'Flow' && !new RegExp('^.*-[0-9]+$').test(fileProperty.fullName) && self.flowDefinitions) {
} else if (majorApiVersion < 44 && fileProperty.type === 'Flow' && !new RegExp('^.*-[0-9]+$').test(fileProperty.fullName) && self.flowDefinitions) {
// determine the active version number using the FlowDefinition Metadata
var flowDefinitionMatch = _.findWhere(self.flowDefinitions, {
DeveloperName: fileProperty.fullName
Expand Down Expand Up @@ -245,6 +246,7 @@ FetchResultParser.prototype.filterSuperfluousParents = function() {

FetchResultParser.prototype.filterInvalid = function() {
var self = this;
var majorApiVersion = parseInt(config.get('defaultApiVersion'));
var folderTypes = getFolderTypes();
self.fileProperties = _.filter(self.fileProperties, function(fileProperty) {
if (!fileProperty.type || typeof fileProperty.type !== 'string') {
Expand All @@ -258,9 +260,12 @@ FetchResultParser.prototype.filterInvalid = function() {
} else if (fileProperty.type === 'QuickAction' && new RegExp('^09D26.*').test(fileProperty.id)) {
self.warnings.push('Warning: Skipped non-global QuickAction: ' + fileProperty.fullName);
return false;
} else if (fileProperty.type === 'Flow' && !new RegExp('^.*-[0-9]+$').test(fileProperty.fullName)) {
} else if (majorApiVersion < 44 && fileProperty.type === 'Flow' && !new RegExp('^.*-[0-9]+$').test(fileProperty.fullName)) {
self.warnings.push('Warning: Skipped non-versioned Flow: ' + fileProperty.fullName);
return false;
} else if (majorApiVersion >= 44 && fileProperty.type === 'FlowDefinition') {
self.warnings.push('Warning: Skipped unnecessary FlowDefinition: ' + fileProperty.fullName);
return false;
}
return true;
});
Expand Down
5 changes: 5 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ exports.Manifest = require("./manifest");

exports.MetadataContainer = require("./metadata-container");
exports.MetadataFile = require("./metadata-file");
exports.MetadataFileContainer = require("./metadata-file-container");
exports.MetadataFileFactory = require("./metadata-file-factory");
exports.MetadataComponent = require("./metadata-component");
exports.MetadataWriter = require("./metadata-writer");

exports.DescribeRemote = require("./describe-remote");
exports.FetchResultParser = require("./fetch-result-parser");
exports.DescribeMetadataService = require("./describe-metadata-service");

exports.Project = require("./project");
Expand Down
2 changes: 1 addition & 1 deletion lib/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var folderBasedMetadataMap = config.get('folderBasedMetadataMap');
var Manifest = module.exports = function(opts) {
var self = this;
opts = opts ? opts : {};
self.apiVersion = opts.apiVersion || config.get('apiVersion');
self.apiVersion = opts.apiVersion;
self.manifestJSON = opts.manifestJSON || []; // TODO: rename to components or something like this
self.unique();
};
Expand Down
4 changes: 3 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions test/data/fetch-results/file-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,21 @@ module.exports = {
"type": "Flow"
}
},
FlowDefinition: {
UnversionedFlow: {
"createdById": "005w0000003zTZPAA2",
"createdByName": "John Doe",
"createdDate": "1970-01-01T00:00:00.000Z",
"fileName": "flowDefinitions/UnversionedFlow.flowDefinition",
"fullName": "UnversionedFlow",
"id": "3001100000027muAAA",
"lastModifiedById": "005w0000003zTZPAA2",
"lastModifiedByName": "John Doe",
"lastModifiedDate": "1970-01-01T00:00:00.000Z",
"manageableState": "unmanaged",
"type": "FlowDefinition"
}
},
InstalledPackage: {
al: {
"createdById": "005w0000003zTZPAA2",
Expand Down
37 changes: 35 additions & 2 deletions test/fetch-result-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ describe('FetchResultParser', function() {
assert.deepEqual(fetchResult.fileProperties.length, 1);
assert.deepEqual(new MetadataComponent(fetchResult.fileProperties[0]).toString(), 'Document/various');
});
it('should transform a non-versioned Flow to a versioned Flow', function() {
it('should transform a non-versioned Flow to a versioned Flow with API Version 43.0', function() {
var config = new(require('../lib/config'))();
var oldApiVersion = config.get('defaultApiVersion');
config.set('defaultApiVersion', '43.0');
var fetchResult = new FetchResultParser({
describeMetadataResult: describeMetadataResult,
fileProperties: [
Expand All @@ -72,9 +75,23 @@ describe('FetchResultParser', function() {
flowDefinitions: soqlResponses.flowDefinitions
});
fetchResult.transform();
// reset api version
config.set('defaultApiVersion', oldApiVersion);
assert.deepEqual(fetchResult.fileProperties.length, 1);
assert.deepEqual(new MetadataComponent(fetchResult.fileProperties[0]).toString(), 'Flow/UnversionedFlow-1');
});
it('should not transform a non-versioned Flow to a versioned Flow', function() {
var fetchResult = new FetchResultParser({
describeMetadataResult: describeMetadataResult,
fileProperties: [
fileProperties.Flow.UnversionedFlow
],
flowDefinitions: soqlResponses.flowDefinitions
});
fetchResult.transform();
assert.deepEqual(fetchResult.fileProperties.length, 1);
assert.deepEqual(new MetadataComponent(fetchResult.fileProperties[0]).toString(), 'Flow/UnversionedFlow');
});
it('should transform an Account RecordType to a PersonAccount RecordType using SOQL', function() {
var fetchResult = new FetchResultParser({
describeMetadataResult: describeMetadataResult,
Expand Down Expand Up @@ -113,14 +130,30 @@ describe('FetchResultParser', function() {
assert.deepEqual(fetchResult.fileProperties.length, 0);
assert.deepEqual(fetchResult.getWarnings().length, 1);
});
it('should filter non-versioned Flows', function() {
it('should filter non-versioned Flows with API version 43.0 or older', function() {
var config = new(require('../lib/config'))();
var oldApiVersion = config.get('defaultApiVersion');
config.set('defaultApiVersion', '43.0');
var fetchResult = new FetchResultParser({
describeMetadataResult: describeMetadataResult,
fileProperties: [
fileProperties.Flow.UnversionedFlow
]
});
fetchResult.filterInvalid();
// reset api version
config.set('defaultApiVersion', oldApiVersion);
assert.deepEqual(fetchResult.fileProperties.length, 0);
assert.deepEqual(fetchResult.getWarnings().length, 1);
});
it('should filter unnecessary FlowDefinitions', function() {
var fetchResult = new FetchResultParser({
describeMetadataResult: describeMetadataResult,
fileProperties: [
fileProperties.FlowDefinition.UnversionedFlow
]
});
fetchResult.filterInvalid();
assert.deepEqual(fetchResult.fileProperties.length, 0);
assert.deepEqual(fetchResult.getWarnings().length, 1);
});
Expand Down

0 comments on commit 138b5c4

Please sign in to comment.