assert.True(t, managerUnderTest.IsFunctionRegistered("APF_id_rApp_as_APF"))
}
-func TestUpdateValidProvider(t *testing.T) {
+func TestUpdateValidProviderWithNewFunction(t *testing.T) {
managerUnderTest, requestHandler := getEcho()
provider := getProvider()
(*provider.ApiProvFuncs)[0].ApiProvFuncId = &funcIdAPF
(*provider.ApiProvFuncs)[1].ApiProvFuncId = &funcIdAMF
(*provider.ApiProvFuncs)[2].ApiProvFuncId = &funcIdAEF
- managerUnderTest.onboardedProviders[domainID] = provider
+ managerUnderTest.registeredProviders[domainID] = provider
// Modify the provider
updatedProvider := getProvider()
assert.True(t, managerUnderTest.IsFunctionRegistered("AEF_id_new_func_as_AEF"))
}
+func TestUpdateValidProviderWithDeletedFunction(t *testing.T) {
+ managerUnderTest, requestHandler := getEcho()
+
+ provider := getProvider()
+ provider.ApiProvDomId = &domainID
+ (*provider.ApiProvFuncs)[0].ApiProvFuncId = &funcIdAPF
+ (*provider.ApiProvFuncs)[1].ApiProvFuncId = &funcIdAMF
+ (*provider.ApiProvFuncs)[2].ApiProvFuncId = &funcIdAEF
+ managerUnderTest.registeredProviders[domainID] = provider
+
+ // Modify the provider
+ updatedProvider := getProvider()
+ updatedProvider.ApiProvDomId = &domainID
+ (*updatedProvider.ApiProvFuncs)[0].ApiProvFuncId = &funcIdAPF
+ (*updatedProvider.ApiProvFuncs)[2].ApiProvFuncId = &funcIdAEF
+ testFuncs := []provapi.APIProviderFunctionDetails{
+ (*updatedProvider.ApiProvFuncs)[0],
+ (*updatedProvider.ApiProvFuncs)[2],
+ }
+ updatedProvider.ApiProvFuncs = &testFuncs
+
+ result := testutil.NewRequest().Put("/registrations/"+domainID).WithJsonBody(updatedProvider).Go(t, requestHandler)
+
+ var resultProvider provapi.APIProviderEnrolmentDetails
+ assert.Equal(t, http.StatusOK, result.Code())
+ err := result.UnmarshalBodyToObject(&resultProvider)
+ assert.NoError(t, err, "error unmarshaling response")
+ assert.Len(t, (*resultProvider.ApiProvFuncs), 2)
+ assert.Empty(t, resultProvider.FailReason)
+ assert.False(t, managerUnderTest.IsFunctionRegistered(funcIdAMF))
+}
+
func TestUpdateMissingFunction(t *testing.T) {
managerUnderTest, requestHandler := getEcho()
(*provider.ApiProvFuncs)[0].ApiProvFuncId = &otherId
(*provider.ApiProvFuncs)[1].ApiProvFuncId = &funcIdAMF
(*provider.ApiProvFuncs)[2].ApiProvFuncId = &funcIdAEF
- managerUnderTest.onboardedProviders[domainID] = provider
+ managerUnderTest.registeredProviders[domainID] = provider
// Modify the provider
updatedProvider := getProvider()
provider := getProvider()
provider.ApiProvDomId = &domainID
(*provider.ApiProvFuncs)[0].ApiProvFuncId = &funcIdAPF
- managerUnderTest.onboardedProviders[domainID] = provider
+ managerUnderTest.registeredProviders[domainID] = provider
assert.True(t, managerUnderTest.IsFunctionRegistered(funcIdAPF))
result := testutil.NewRequest().Delete("/registrations/"+domainID).Go(t, requestHandler)
(*provider.ApiProvFuncs)[0].ApiProvFuncId = &funcIdAPF
(*provider.ApiProvFuncs)[1].ApiProvFuncId = &funcIdAMF
(*provider.ApiProvFuncs)[2].ApiProvFuncId = &funcIdAEF
- managerUnderTest.onboardedProviders[domainID] = provider
- managerUnderTest.onboardedProviders[otherDomainID] = getOtherProvider()
+ managerUnderTest.registeredProviders[domainID] = provider
+ managerUnderTest.registeredProviders[otherDomainID] = getOtherProvider()
exposedFuncs := managerUnderTest.GetAefsForPublisher(funcIdAPF)
assert.Equal(t, 1, len(exposedFuncs))