Skip to content

Commit 9e4e6f6

Browse files
authored
fix: customer fields not supported by data steps (#69)
BREAKING CHANGE: removes `V2` extension methods used as temporary workarounds for EasyRepro issues.
1 parent 9e4df85 commit 9e4e6f6

File tree

12 files changed

+115
-269
lines changed

12 files changed

+115
-269
lines changed

bindings/src/Capgemini.PowerApps.SpecFlowBindings/Capgemini.PowerApps.SpecFlowBindings.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
</Target>
4646

4747
<ItemGroup>
48-
<PackageReference Include="Dynamics365.UIAutomation.Api" Version="9.1.0.27021" />
48+
<PackageReference Include="Dynamics365.UIAutomation.Api" Version="9.2.21014.138" />
4949
<PackageReference Include="FluentAssertions" Version="5.10.3" />
5050
<PackageReference Include="Microsoft.Build.Tasks.Git" Version="1.0.0">
5151
<PrivateAssets>all</PrivateAssets>

bindings/src/Capgemini.PowerApps.SpecFlowBindings/Extensions/WebClientExtensions.cs

Lines changed: 0 additions & 207 deletions
This file was deleted.

bindings/src/Capgemini.PowerApps.SpecFlowBindings/Steps/CommandBarSteps.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ public class CommandBarSteps : PowerAppsStepDefiner
1717
[When("I select the '(.*)' command")]
1818
public static void WhenISelectTheCommand(string commandName)
1919
{
20-
// TODO: Replace with commented out code when new EasyRepro version available.
21-
// XrmApp.CommandBar.ClickCommand(commandName);
22-
Client.ClickCommandV2(commandName);
20+
XrmApp.CommandBar.ClickCommand(commandName);
2321
}
2422

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

3834
/// <summary>

bindings/src/Capgemini.PowerApps.SpecFlowBindings/Steps/EntitySubGridSteps.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ public static void WhenISelectTheCommandOnTheSubgrid(string commandName, string
2828
Driver.WaitUntilVisible(
2929
By.CssSelector($"div#dataSetRoot_{subGridName} button[aria-label=\"{commandName}\"]"));
3030

31-
// TODO: Replace with commented out code when new EasyRepro version available.
32-
// XrmApp.Entity.SubGrid.ClickCommand(subGridName, commandName);
33-
Client.ClickSubGridCommandV2(subGridName, commandName);
31+
XrmApp.Entity.SubGrid.ClickCommand(subGridName, commandName);
3432
}
3533

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

241-
// TODO: Replace with commented out code when new EasyRepro version available.
242-
// XrmApp.Entity.SubGrid.ClickCommand(subGridName, flyoutName);
243-
Client.ClickSubGridCommandV2(subGridName, flyoutName);
239+
XrmApp.Entity.SubGrid.ClickCommand(subGridName, flyoutName);
244240
}
245241

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

303297
/// <summary>

bindings/src/Capgemini.PowerApps.SpecFlowBindings/Steps/LoginSteps.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public static void GivenIAmLoggedInToTheAppAs(string appName, string userAlias)
2323
XrmApp.OnlineLogin.Login(
2424
TestConfig.GetTestUrl(),
2525
user.Username.ToSecureString(),
26-
user.Password.ToSecureString());
26+
user.Password.ToSecureString(),
27+
string.Empty.ToSecureString());
2728

2829
XrmApp.Navigation.OpenApp(appName);
2930

bindings/tests/Capgemini.PowerApps.SpecFlowBindings.UiTests/Hooks/EasyReproSelectorFixHooks.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.

driver/src/data/deepInsertService.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,32 @@ export default class DeepInsertService {
135135
const record = entity;
136136
delete record[singleNavProp];
137137

138-
const entityName = await this.metadataRepository.getEntityForLookupProperty(
138+
let entityName: string | null = null;
139+
const lookupEntity = navigationPropertyMap[singleNavProp];
140+
141+
const targets = await this.metadataRepository.getTargetsForLookupProperty(
139142
logicalName, singleNavProp,
140143
);
144+
145+
if (!targets && (singleNavProp.endsWith('_account') || singleNavProp.endsWith('_contact'))) {
146+
// Possibly a customer field
147+
const fieldWithoutSuffix = singleNavProp.replace('_account', '').replace('_contact', '');
148+
const customerTargets = await this.metadataRepository.getTargetsForLookupProperty(
149+
logicalName, fieldWithoutSuffix,
150+
);
151+
if (customerTargets && customerTargets.length === 2) {
152+
entityName = singleNavProp.endsWith('account') ? 'account' : 'contact';
153+
}
154+
} else if (targets && targets.length === 1) {
155+
[entityName] = targets;
156+
} else if (lookupEntity['@logicalName']) {
157+
entityName = lookupEntity['@logicalName'] as string;
158+
}
159+
160+
if (!entityName) {
161+
throw new Error(`Unable to determine target entity for ${singleNavProp}.`);
162+
}
163+
141164
const deepInsertResponse = await this.deepInsert(
142165
entityName, navigationPropertyMap[singleNavProp], createdRecordsByAlias, repository,
143166
);

driver/src/repositories/metadataRepository.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ export default class MetadataRepository {
4040
* @returns {Promise<string>} A promise which contains the logical name of the related entity.
4141
* @memberof MetadataRepository
4242
*/
43-
public async getEntityForLookupProperty(logicalName: string, navigationProperty: string)
44-
: Promise<string> {
43+
public async getTargetsForLookupProperty(logicalName: string, navigationProperty: string)
44+
: Promise<string[] | null> {
4545
const response = await fetch(
4646
'api/data/v9.1/'
4747
+ `${MetadataRepository.EntityMetadataSet}(LogicalName='${logicalName}')/Attributes/Microsoft.Dynamics.CRM.LookupAttributeMetadata?$filter=LogicalName eq '${navigationProperty.toLowerCase()}'&$select=Targets`,
4848
{ cache: 'force-cache' },
4949
);
5050
const result = await response.json();
5151

52-
return result.value[0].Targets[0];
52+
return result.value[0] ? result.value[0].Targets : null;
5353
}
5454

5555
/**

0 commit comments

Comments
 (0)