Skip to content

Commit

Permalink
fix: customer fields not supported by data steps (#69)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: removes `V2` extension methods used as temporary workarounds for EasyRepro issues.
  • Loading branch information
ewingjm committed Mar 11, 2021
1 parent 9e4df85 commit 9e4e6f6
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 269 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</Target>

<ItemGroup>
<PackageReference Include="Dynamics365.UIAutomation.Api" Version="9.1.0.27021" />
<PackageReference Include="Dynamics365.UIAutomation.Api" Version="9.2.21014.138" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.Build.Tasks.Git" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ public class CommandBarSteps : PowerAppsStepDefiner
[When("I select the '(.*)' command")]
public static void WhenISelectTheCommand(string commandName)
{
// TODO: Replace with commented out code when new EasyRepro version available.
// XrmApp.CommandBar.ClickCommand(commandName);
Client.ClickCommandV2(commandName);
XrmApp.CommandBar.ClickCommand(commandName);
}

/// <summary>
Expand All @@ -30,9 +28,7 @@ public static void WhenISelectTheCommand(string commandName)
[When("I select the '([^']+)' command under the '([^']+)' flyout")]
public static void WhenISelectTheCommandUnderTheFlyout(string commandName, string flyoutName)
{
// TODO: Replace with commented out code when new EasyRepro version available.
// XrmApp.CommandBar.ClickCommand(flyoutName, commandName);
Client.ClickCommandV2(flyoutName, commandName);
XrmApp.CommandBar.ClickCommand(flyoutName, commandName);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ public static void WhenISelectTheCommandOnTheSubgrid(string commandName, string
Driver.WaitUntilVisible(
By.CssSelector($"div#dataSetRoot_{subGridName} button[aria-label=\"{commandName}\"]"));

// TODO: Replace with commented out code when new EasyRepro version available.
// XrmApp.Entity.SubGrid.ClickCommand(subGridName, commandName);
Client.ClickSubGridCommandV2(subGridName, commandName);
XrmApp.Entity.SubGrid.ClickCommand(subGridName, commandName);
}

/// <summary>
Expand Down Expand Up @@ -238,9 +236,7 @@ public static void WhenIClickTheFlyoutOnTheSubgrid(string flyoutName, string sub
{
Driver.WaitUntilVisible(By.CssSelector($"div#dataSetRoot_{subGridName} li[aria-label=\"{flyoutName}\"]"));

// TODO: Replace with commented out code when new EasyRepro version available.
// XrmApp.Entity.SubGrid.ClickCommand(subGridName, flyoutName);
Client.ClickSubGridCommandV2(subGridName, flyoutName);
XrmApp.Entity.SubGrid.ClickCommand(subGridName, flyoutName);
}

/// <summary>
Expand Down Expand Up @@ -295,9 +291,7 @@ public static void ThenICanNotSeeTheCommandOnTheFlyoutOfTheSubgrid(string comman
[When(@"I click the '([^']+)' command under the '([^']+)' flyout on the '([^']+)' subgrid")]
public static void WhenIClickTheCommandUnderTheFlyoutOnTheSubgrid(string commandName, string flyoutName, string subGridName)
{
// TODO: Replace with commented out code when new EasyRepro version available.
// XrmApp.Entity.SubGrid.ClickCommand(subGridName, flyoutName, commandName);
Client.ClickSubGridCommandV2(subGridName, flyoutName, commandName);
XrmApp.Entity.SubGrid.ClickCommand(subGridName, flyoutName, commandName);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public static void GivenIAmLoggedInToTheAppAs(string appName, string userAlias)
XrmApp.OnlineLogin.Login(
TestConfig.GetTestUrl(),
user.Username.ToSecureString(),
user.Password.ToSecureString());
user.Password.ToSecureString(),
string.Empty.ToSecureString());

XrmApp.Navigation.OpenApp(appName);

Expand Down

This file was deleted.

25 changes: 24 additions & 1 deletion driver/src/data/deepInsertService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,32 @@ export default class DeepInsertService {
const record = entity;
delete record[singleNavProp];

const entityName = await this.metadataRepository.getEntityForLookupProperty(
let entityName: string | null = null;
const lookupEntity = navigationPropertyMap[singleNavProp];

const targets = await this.metadataRepository.getTargetsForLookupProperty(
logicalName, singleNavProp,
);

if (!targets && (singleNavProp.endsWith('_account') || singleNavProp.endsWith('_contact'))) {
// Possibly a customer field
const fieldWithoutSuffix = singleNavProp.replace('_account', '').replace('_contact', '');
const customerTargets = await this.metadataRepository.getTargetsForLookupProperty(
logicalName, fieldWithoutSuffix,
);
if (customerTargets && customerTargets.length === 2) {
entityName = singleNavProp.endsWith('account') ? 'account' : 'contact';
}
} else if (targets && targets.length === 1) {
[entityName] = targets;
} else if (lookupEntity['@logicalName']) {
entityName = lookupEntity['@logicalName'] as string;
}

if (!entityName) {
throw new Error(`Unable to determine target entity for ${singleNavProp}.`);
}

const deepInsertResponse = await this.deepInsert(
entityName, navigationPropertyMap[singleNavProp], createdRecordsByAlias, repository,
);
Expand Down
6 changes: 3 additions & 3 deletions driver/src/repositories/metadataRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ export default class MetadataRepository {
* @returns {Promise<string>} A promise which contains the logical name of the related entity.
* @memberof MetadataRepository
*/
public async getEntityForLookupProperty(logicalName: string, navigationProperty: string)
: Promise<string> {
public async getTargetsForLookupProperty(logicalName: string, navigationProperty: string)
: Promise<string[] | null> {
const response = await fetch(
'api/data/v9.1/'
+ `${MetadataRepository.EntityMetadataSet}(LogicalName='${logicalName}')/Attributes/Microsoft.Dynamics.CRM.LookupAttributeMetadata?$filter=LogicalName eq '${navigationProperty.toLowerCase()}'&$select=Targets`,
{ cache: 'force-cache' },
);
const result = await response.json();

return result.value[0].Targets[0];
return result.value[0] ? result.value[0].Targets : null;
}

/**
Expand Down
Loading

0 comments on commit 9e4e6f6

Please sign in to comment.