public async Task ShouldGetReferralCode_WhenReferralCodeExits()
        {
            // Arrange
            var referralCode = "refcod";

            _referralClient.Setup(c => c.ReferralApi.GetAsync(It.IsAny <string>()))
            .ReturnsAsync(new ReferralResultResponse()
            {
                ReferralCode = referralCode
            });

            // Act
            var result = await _referralService.GetOrCreateReferralCodeAsync("123");

            // Assert
            Assert.Equal(referralCode, result);
        }
Ejemplo n.º 2
0
        public async Task <CustomerDetailsModel> GetCustomerByIdAsync([Required][FromQuery] string customerId)
        {
            var parsedCustomerId = Guid.TryParse(customerId, out var customerIdGuid);

            if (!parsedCustomerId)
            {
                throw LykkeApiErrorException.BadRequest(ApiErrorCodes.Service.CustomerNotFound);
            }

            var customerProfileResponseTask =
                await _customerProfileClient.CustomerProfiles.GetByCustomerIdAsync(customerId, true);

            if (customerProfileResponseTask.Profile == null)
            {
                throw LykkeApiErrorException.BadRequest(ApiErrorCodes.Service.CustomerNotFound);
            }

            var customer = _mapper.Map <CustomerDetailsModel>(customerProfileResponseTask.Profile);

            if (customerProfileResponseTask.Profile.IsEmailVerified &&
                (_settingsService.IsPhoneVerificationDisabled() || customerProfileResponseTask.Profile.IsPhoneVerified))
            {
                var customerStatusTask =
                    _customerManagementServiceClient.CustomersApi.GetCustomerBlockStateAsync(customerId);

                var walletStatusTask =
                    _walletManagementClient.Api.GetCustomerWalletBlockStateAsync(customerId);

                await Task.WhenAll(
                    customerStatusTask,
                    walletStatusTask);

                if (customerStatusTask.Result.Error == CustomerBlockStatusError.CustomerNotFound)
                {
                    throw LykkeApiErrorException.BadRequest(ApiErrorCodes.Service.CustomerNotFound);
                }

                if (walletStatusTask.Result.Error == CustomerWalletBlockStatusError.CustomerNotFound)
                {
                    throw LykkeApiErrorException.BadRequest(ApiErrorCodes.Service.CustomerNotFound);
                }

                customer.WalletStatus =
                    _mapper.Map <Models.Customers.Enums.CustomerWalletActivityStatus>(walletStatusTask.Result.Status);
                customer.CustomerStatus =
                    _mapper.Map <CustomerActivityStatus>(customerStatusTask.Result.Status);
            }

            customer.ReferralCode = await _referralService.GetOrCreateReferralCodeAsync(customer.CustomerId);

            return(customer);
        }
        public async Task <ReferralResponseModel> GetReferralCodeAsync()
        {
            var result = await _referralService.GetOrCreateReferralCodeAsync(_requestContext.UserId);

            if (result != null)
            {
                return(new ReferralResponseModel {
                    ReferralCode = result
                });
            }

            throw LykkeApiErrorException.BadRequest(ApiErrorCodes.Service.ReferralNotFound);
        }