public void remove_user_should_return_false_for_invalid_user_id() { //making sure it doesnt exist in the db var retNull = UserDbServiceHelper.GetAppUserByIdAsync(service, "invalid_id").Result; Assert.Null(retNull); var retFalse = UserDbServiceHelper.RemoveUser(service, "invalid_id"); Assert.False(retFalse); }
public void remove_user_should_return_true_for_valid_user_id() { var user = new AspNetUser() { Email = "*****@*****.**", MyShopifyDomain = "test5.myshopify.com", UserName = "******", Id = Guid.NewGuid().ToString(), ShopifyAccessToken = "validtoken", BillingOn = null, PlanId = null, ShopifyChargeId = null }; service.Add(user); var retTrue = UserDbServiceHelper.RemoveUser(service, user.Id); Assert.True(retTrue); var retNull = UserDbServiceHelper.GetAppUserByIdAsync(service, user.Id).Result; Assert.Null(retNull); }
/// <summary> /// Called by the uninstall web hook from shopify end /// </summary> /// <param name="userId">User who uninstalled</param> /// <returns></returns> /// public virtual async Task <IActionResult> AppUninstalled(string userId) { Logger.LogInformation("Start handling app/uninstalled webhook."); bool isValidRequest = false; Logger.LogInformation("Checking webhook authenticity."); try { isValidRequest = await ShopifyAPI.IsAuthenticWebhook(Request); } catch (Exception ex) { LogGenericError(ex); Logger.LogWarning("Exception occurred during checking of the webhook authenticity. Gracefully ignoring and continueing."); } if (!isValidRequest) { Logger.LogWarning("Webhook is not authentic.Still returning 200 OK."); return(Content("Webhook is not authentic."));//yet its a 200 OK msg } else { Logger.LogInformation("Request is authentic."); AppUser user = null; Logger.LogInformation("Trying to retrieve user data."); try { user = await UserDbServiceHelper.GetAppUserByIdAsync(UsrDbService, userId); } catch (Exception ex) { LogGenericError(ex); Logger.LogWarning("Exception occurred while retrieving user data. Gracefully ingnoring and continuing."); } if (user != null) { Logger.LogInformation("Found user data. {@user}", user); bool removeSuccess = false; Exception removalException = null; try { Logger.LogInformation("Trying to remove user account."); removeSuccess = UserDbServiceHelper.RemoveUser(UsrDbService, userId); } catch (Exception ex) { LogGenericError(ex); Logger.LogInformation("Error occurred during user account removal. Gracefully ignoring and continuing."); removalException = ex; } if (!removeSuccess) { Logger.LogInformation("Calling CouldNotDeleteUser() event."); await CouldNotDeleteUser(user, removalException ?? new Exception("Reason not known")); Logger.LogInformation("Done handling CouldNotDeleteUser() event."); } else { Logger.LogInformation("user account removal was successfull."); Logger.LogInformation("Calling UserIsDeleted() event."); await UserIsDeleted(user); Logger.LogInformation("Done handling UserIsDeleted() event."); } try { Logger.LogInformation("Trying to clear user cache calling ClearUser()."); UserCache.ClearUser(userId); Logger.LogInformation("Done clearning user cache."); } catch (Exception ex) { LogGenericError(ex); Logger.LogWarning("Error occurred during clearning user cache.Ignoring and continuing."); } } try { Logger.LogInformation("Sending out uninstall event email."); var emailRet = await SendUninstallEmail(user); if (emailRet) { Logger.LogInformation("Successfully sent out uninstall even email."); } else { Logger.LogWarning("Error sending uninstall event email."); } Logger.LogInformation("Calling UnInstallCompleted() event."); await UnInstallCompleted(user); Logger.LogInformation("Done handling UnInstallCompleted() event."); } catch (Exception ex) { Logger.LogError(ex, "Unhandled exection occurred during app uninstall web hook processing."); } Logger.LogInformation("Returning 200 OK to satisfy shopify."); return(Ok()); //shopify wants 200 OK msg } }