Skip to content

Commit

Permalink
fix(connectors): add updation for provider and host company id in man…
Browse files Browse the repository at this point in the history
…aged endpoint (eclipse-tractusx#948)

Refs: eclipse-tractusx#944
Co-authored-by: Phil Schneider <info@philschneider.de>
Reviewed-by: Phil Schneider <info@philschneider.de>
  • Loading branch information
2 people authored and dhiren-singh-007 committed Aug 28, 2024
1 parent 356475f commit d5b9832
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private async Task<Guid> CreateManagedConnectorInternalAsync(ManagedConnectorInp

await ValidateTechnicalUser(technicalUserId, result.CompanyId).ConfigureAwait(ConfigureAwaitOptions.None);

var connectorRequestModel = new ConnectorRequestModel(name, connectorUrl, ConnectorTypeId.CONNECTOR_AS_A_SERVICE, location, result.CompanyId, companyId, technicalUserId);
var connectorRequestModel = new ConnectorRequestModel(name, connectorUrl, ConnectorTypeId.CONNECTOR_AS_A_SERVICE, location, companyId, result.CompanyId, technicalUserId);
return await CreateAndRegisterConnectorAsync(
connectorRequestModel,
result.ProviderBpn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class ConnectorsBusinessLogicTests
private static readonly Guid CompanyUserId = new("ac1cf001-7fbc-1f2f-817f-bce058020002");
private static readonly Guid ServiceAccountUserId = new("ac1cf001-7fbc-1f2f-817f-bce058020003");
private static readonly Guid ValidCompanyId = Guid.NewGuid();
private static readonly Guid HostCompanyId = new("ac1cf001-7fbc-1f2f-817f-bce058020029");
private static readonly Guid CompanyIdWithoutSdDocument = Guid.NewGuid();
private static readonly Guid ExistingConnectorId = Guid.NewGuid();
private static readonly Guid CompanyWithoutBpnId = Guid.NewGuid();
Expand Down Expand Up @@ -312,13 +313,15 @@ public async Task CreateManagedConnectorAsync_WithValidInput_ReturnsCreatedConne
}), _sdFactoryBusinessLogic, _identityService, A.Fake<ILogger<ConnectorsBusinessLogic>>());

var connectorInput = new ManagedConnectorInputModel("connectorName", "https://test.de", "de", _validOfferSubscriptionId, ServiceAccountUserId);

SetupCheckActiveServiceAccountExistsForCompanyAsyncForManaged();
// Act
var result = await sut.CreateManagedConnectorAsync(connectorInput, CancellationToken.None);

// Assert
result.Should().NotBeEmpty();
_connectors.Should().HaveCount(1);
_connectors.Should().ContainSingle().And.Satisfy(x =>
x.HostId == HostCompanyId &&
x.ProviderId == _identity.CompanyId);
A.CallTo(() => _connectorsRepository.CreateConnectorAssignedSubscriptions(A<Guid>._, _validOfferSubscriptionId)).MustHaveHappenedOnceExactly();
A.CallTo(() => _sdFactoryBusinessLogic.RegisterConnectorAsync(A<Guid>._, A<string>._, A<string>._, A<CancellationToken>._)).MustHaveHappened(clearingHouseDisabled ? 0 : 1, Times.Exactly);
}
Expand Down Expand Up @@ -505,7 +508,7 @@ public async Task CreateManagedConnectorAsync_WithInvalidTechnicalUser_ThrowsCon
x.Value == saId.ToString(),
y => y.Name == "companyId"
&&
y.Value == _identity.CompanyId.ToString()
y.Value == HostCompanyId.ToString()
);
}

Expand Down Expand Up @@ -1333,7 +1336,7 @@ private void SetupRepositoryMethods()
A.CallTo(() => _companyRepository.GetCompanyBpnAndSelfDescriptionDocumentByIdAsync(A<Guid>.That.Not.Matches(x => x == ValidCompanyId || x == CompanyIdWithoutSdDocument)))
.Returns((null, null));
A.CallTo(() => _offerSubscriptionRepository.CheckOfferSubscriptionWithOfferProvider(_validOfferSubscriptionId, ValidCompanyId))
.Returns((true, true, false, OfferSubscriptionStatusId.ACTIVE, Guid.NewGuid(), ValidCompanyId, ValidCompanyBpn));
.Returns((true, true, false, OfferSubscriptionStatusId.ACTIVE, Guid.NewGuid(), ProviderCompanyId: HostCompanyId, ValidCompanyBpn));

A.CallTo(() => _connectorsRepository.CreateConnector(A<string>._, A<string>._, A<string>._, A<Action<Connector>?>._))
.Invokes((string name, string location, string connectorUrl, Action<Connector>? setupOptionalFields) =>
Expand Down Expand Up @@ -1375,6 +1378,12 @@ private void SetupRepositoryMethods()
A.CallTo(() => _portalRepositories.GetInstance<IProcessStepRepository>()).Returns(_processStepRepository);
}

private void SetupCheckActiveServiceAccountExistsForCompanyAsyncForManaged()
{
A.CallTo(() => _serviceAccountRepository.CheckActiveServiceAccountExistsForCompanyAsync(ServiceAccountUserId, HostCompanyId))
.Returns(true);
}

private void SetupIdentity()
{
A.CallTo(() => _identity.IdentityId).Returns(CompanyUserId);
Expand Down

0 comments on commit d5b9832

Please sign in to comment.