public void AuthenticationShouldSucceed() { const string testBaseUri = "https://127.0.0.1"; const string expectedRequestUrl = testBaseUri + "/v15/access_tokens"; const string testClientId = "1a2b3c4d5e6f7g8h9i0j"; const string testMerchantUsername = "******"; const string testMerchantPassword = "******"; string expectedRequestbody = string.Format("{{\"access_token\": {{" + "\"api_key\": \"{0}\"" + ",\"username\": \"{1}\"" + ",\"password\": \"{2}\"" + "}}}}", testClientId, testMerchantUsername, testMerchantPassword); // This response format does not matter for this test. RestResponse expectedResponse = new RestResponse { StatusCode = HttpStatusCode.OK, }; IAuthenticate auth = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <IAuthenticate, AccessTokenRequest>( expectedResponse, expectedRequestbody, expectedAccessToken: null, expectedRequestUrl: expectedRequestUrl, environmentToUse: new LevelUpEnvironment(testBaseUri)); var token = auth.Authenticate(testClientId, testMerchantUsername, testMerchantPassword); }
public void RetrieveMerchantFundedGiftCardCreditShouldPass() { const int locationId = 19; const string qr_code = "LU02000008ZS9OJFUBNEL6ZM030000LU"; const int gift_card_total = 2000; const string auth_Token = "example_auth_token"; string expectedRequestUrl = string.Format(ClientModuleFunctionalTestingUtilities.SANDBOX_URL_PREFIX + "/v15/locations/{0}/get_merchant_funded_gift_card_credit", locationId); string expectedRequestbody = string.Format( "{{\"get_merchant_funded_gift_card_credit\": {{\"payment_token_data\": \"{0}\"}} }}", qr_code); RestResponse expectedResponse = new RestResponse { StatusCode = HttpStatusCode.OK, Content = string.Format("{{\"merchant_funded_gift_card_credit\": {{\"total_amount\": {0} }} }}", gift_card_total) }; IRetrieveMerchantFundedGiftCardCredit client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <IRetrieveMerchantFundedGiftCardCredit, GiftCardCreditQueryRequest>(expectedResponse, expectedRequestbody, expectedAccessToken: auth_Token, expectedRequestUrl: expectedRequestUrl); var credit = client.GetMerchantFundedGiftCardCredit(auth_Token, locationId, qr_code); Assert.AreEqual(credit.TotalAmount, gift_card_total); }
public void ListOrdersShouldSucceedWhenMorePagesQueriedThanExist() { IQueryOrders client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModuleWithPaging <IQueryOrders>(successfulResponses, expectedRequestBaseUrl); var orders = client.ListOrders("not_checking_this", locationId, 1, 10); // Note that we specify pages 1-10 when only 3 pages exist Assert.AreEqual(orders.Count, 9); }
public void ListFilteredOrdersShouldSucceedWithNoModifierFunctions() { IQueryOrders client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModuleWithPaging <IQueryOrders>( successfulResponses, expectedRequestBaseUrl); var orders = client.ListFilteredOrders("not_checking_this", locationId, 1, 3); Assert.AreEqual(orders.Count, 9); }
public void ListOrdersShouldFailWith204ForInvalidStartPageNumbers() { IQueryOrders client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModuleWithPaging <IQueryOrders>( successfulResponses, expectedRequestBaseUrl); var orders = client.ListOrders("not_checking_this", locationId, 5, 10); Assert.AreEqual(orders.Count, 0); }
public void CreateCreditCardShouldSucceed() { const string expectedRequestUrl = ClientModuleFunctionalTestingUtilities.SANDBOX_URL_PREFIX + "/v15/credit_cards"; // The below strings can be arbitrary for the purposes of this test -- These are just the examples from the api docs. const string encrypted_cvv = "$bt4|javascript_1_3_9$Zar7J1+0QNsrHtKFufeJ8UCpSd5RM1PwTjzNE1Dm1N0A969OuWfU03..."; const string encrypted_expiration_month = "$bt4|javascript_1_3_9$7ad9aydahduiw+89w7dHusaihdas..."; const string encrypted_expiration_year = "$bt4|javascript_1_3_9$9asdjaIjashuUHsj+saiUSj..."; const string encrypted_number = "$bt4|javascript_1_3_9$FyreT+o2W/9VHHjS43ZJJe2SmdvTBcve58..."; const string postal_code = "12345"; string expectedRequestbody = string.Format( "{{" + "\"credit_card\": {{" + "\"encrypted_cvv\": \"{0}\"," + "\"encrypted_expiration_month\": \"{1}\"," + "\"encrypted_expiration_year\": \"{2}\"," + "\"encrypted_number\": \"{3}\"," + "\"postal_code\": \"{4}\" " + "}}" + "}}", encrypted_cvv, encrypted_expiration_month, encrypted_expiration_year, encrypted_number, postal_code); RestResponse expectedResponse = new RestResponse { StatusCode = HttpStatusCode.OK, Content = "{" + "\"credit_card\": {" + "\"bin\": \"123456\"," + "\"description\": \"JCB ending in 1234\"," + "\"expiration_month\": 7," + "\"expiration_year\": 2015," + "\"id\": 305999," + "\"last_4\": \"1234\"," + "\"promoted\": true," + "\"state\": \"active\"," + "\"type\": \"JCB\"" + "}" + "}" }; const string accessToken = "abc"; ICreateCreditCards client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <ICreateCreditCards, CreateCreditCardRequest>( expectedResponse, expectedRequestbody, expectedAccessToken: accessToken, expectedRequestUrl: expectedRequestUrl); var card = client.CreateCreditCard(accessToken, encrypted_number, encrypted_expiration_month, encrypted_expiration_year, encrypted_cvv, postal_code); Assert.AreEqual(card.Bin, "123456"); Assert.AreEqual(card.Description, "JCB ending in 1234"); Assert.AreEqual(card.ExpirationMonth, 7); Assert.AreEqual(card.ExpirationYear, 2015); Assert.AreEqual(card.Id, 305999); Assert.AreEqual(card.Last4Numbers, "1234"); Assert.AreEqual(card.Promoted, true); Assert.AreEqual(card.State, "active"); Assert.AreEqual(card.Type, "JCB"); }
public void RefundOrderShouldSucceedSansManagerConfirmation() { const string uuid = "bf143c9084810132faf95a123bd6cde9"; const string created_at = "2015-01-22T11:29:22-05:00"; const int location_id = 19; const int loyalty_id = 20; const string refunded_at = "2015-01-22T14:28:05-05:00"; const string user_display_name = "TestCredsT."; const int earn_amount = 0; const int merchant_funded_credit_amount = 0; const int spend_amount = 10; const int tip_amount = 0; const int total_amount = 10; string expectedRequestUrl = string.Format(ClientModuleFunctionalTestingUtilities.SANDBOX_URL_PREFIX + "/v15/orders/{0}/refund", uuid); RestResponse expectedResponse = new RestResponse { StatusCode = HttpStatusCode.OK, Content = string.Format("{{" + "\"order\":{{" + "\"created_at\":\"{0}\"," + "\"location_id\":{1}," + "\"loyalty_id\":{2}," + "\"refunded_at\":\"{3}\"," + "\"user_display_name\":\"{4}\"," + "\"uuid\":\"{5}\"," + "\"earn_amount\":{6}," + "\"merchant_funded_credit_amount\":{7}," + "\"spend_amount\":{8}," + "\"tip_amount\":{9}," + "\"total_amount\":{10}" + "}}" + "}}", created_at, location_id, loyalty_id, refunded_at, user_display_name, uuid, earn_amount, merchant_funded_credit_amount, spend_amount, tip_amount, total_amount) }; string expectedRequest = string.Empty; ICreateRefund client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <ICreateRefund, RefundRequest>( expectedResponse, expectedRequest, expectedRequestUrl: expectedRequestUrl); var order = client.RefundOrder("not_checking_this", uuid); Assert.AreEqual(order.EarnAmount, earn_amount); Assert.AreEqual(order.LocationId, location_id); Assert.AreEqual(order.LoyaltyId, loyalty_id); Assert.AreEqual(order.MerchantFundedCreditAmount, merchant_funded_credit_amount); Assert.AreEqual(order.OrderIdentifier, uuid); Assert.AreEqual(order.SpendAmount, spend_amount); Assert.AreEqual(order.TipAmount, tip_amount); Assert.AreEqual(order.UserName, user_display_name); Assert.AreEqual(order.TimeOfRefund, refunded_at); Assert.AreEqual(order.CreatedAt, created_at); }
public void ListFilteredOrdersShouldSucceedWithAFilterFunction() { IQueryOrders client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModuleWithPaging <IQueryOrders>( successfulResponses, expectedRequestBaseUrl); var orders = client.ListFilteredOrders("not_checking_this", locationId, 1, 3, (x => (x.OrderIdentifier == "c" || x.OrderIdentifier == "i")), null); Assert.AreEqual(orders.Count, 2); Assert.AreEqual(orders[0].OrderIdentifier, "c"); Assert.AreEqual(orders[1].OrderIdentifier, "i"); }
public void ListOrdersShouldSucceedDespiteInvalidEndPageNumbers() { IQueryOrders client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModuleWithPaging <IQueryOrders>(successfulResponses, expectedRequestBaseUrl); var orders = client.ListOrders("not_checking_this", locationId, 1, 10); Assert.AreEqual(orders.Count, 9); orders = client.ListOrders("not_checking_this", locationId, 3, 11); Assert.AreEqual(orders.Count, 3); }
public void GetLoyaltyShouldSucceed() { const int merchant_Id = 456; const int merchant_earn_amount = 500; const int merchant_spend_amount = 5000; const int orders_count = 77; const int potential_credit_amount = 7350; const int savings_amount = 835; const int spend_remaining_amount = 427; const int total_volume_amount = 6317; const int user_id = 789; const bool merchant_loyalty_enabled = true; const decimal progress_percentage = 42.0m; string expectedRequestUrl = string.Format(ClientModuleFunctionalTestingUtilities.SANDBOX_URL_PREFIX + "/v14/merchants/{0}/loyalty", merchant_Id); RestResponse expectedResponse = new RestResponse { StatusCode = HttpStatusCode.OK, Content = string.Format("{{" + "\"loyalty\":{{" + "\"merchant_earn_amount\":{0}," + "\"merchant_id\":{1}," + "\"merchant_loyalty_enabled\":{2}," + "\"merchant_spend_amount\":{3}," + "\"orders_count\":{4}," + "\"potential_credit_amount\":{5}," + "\"progress_percentage\":{6}," + "\"savings_amount\":{7}," + "\"spend_remaining_amount\":{8}," + "\"total_volume_amount\":{9}," + "\"user_id\":{10}" + "}}" + "}}", merchant_earn_amount, merchant_Id, merchant_loyalty_enabled ? "true" : "false", merchant_spend_amount, orders_count, potential_credit_amount, progress_percentage, savings_amount, spend_remaining_amount, total_volume_amount, user_id) }; ILookupUserLoyalty client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <ILookupUserLoyalty>( expectedResponse, expectedRequestUrl: expectedRequestUrl); var loyalty = client.GetLoyalty("not_checking_this", merchant_Id); Assert.AreEqual(loyalty.MerchantEarnAmount, merchant_earn_amount); Assert.AreEqual(loyalty.MerchantId, merchant_Id); Assert.AreEqual(loyalty.MerchantLoyaltyEnabled, merchant_loyalty_enabled); Assert.AreEqual(loyalty.MerchantSpendAmount, merchant_spend_amount); Assert.AreEqual(loyalty.OrdersCount, orders_count); Assert.AreEqual(loyalty.PotentialCreditAmount, potential_credit_amount); Assert.AreEqual(loyalty.ProgressPercentage, progress_percentage); Assert.AreEqual(loyalty.SavingsAmount, savings_amount); Assert.AreEqual(loyalty.SpendRemainingAmount, spend_remaining_amount); Assert.AreEqual(loyalty.TotalVolumeAmount, total_volume_amount); Assert.AreEqual(loyalty.UserId, user_id); }
public void ListFilteredOrdersShouldSucceedWithAnOrderingFunction() { IQueryOrders client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModuleWithPaging <IQueryOrders>( successfulResponses, expectedRequestBaseUrl); var orders = client.ListFilteredOrders("not_checking_this", locationId, 1, 3, null, ((x, y) => (0 - string.Compare(x.OrderIdentifier, y.OrderIdentifier)))); // i.e. orderbydecending Assert.AreEqual(orders.Count, 9); Assert.AreEqual(orders[0].OrderIdentifier, "i"); Assert.AreEqual(orders[8].OrderIdentifier, "a"); }
public void GiftCardAddValueShouldSucceed() { const string accessToken = "abc"; const int merchant_id = 3554; const string payment_token_data = "LU020000029080KFZ02I9A8V030000LU"; const int value_amount = 1000; const int location_id = 1234; const string order_uuid = "a7e23820d56802321bb64ab3b58dfe6c"; const string identifier_from_merchant = "012345"; const string tender_types = "cash"; string expectedRequestUrl = string.Format(ClientModuleFunctionalTestingUtilities.SANDBOX_URL_PREFIX + "/v15/merchants/{0}/gift_card_value_additions", merchant_id); string expectedRequestbody = string.Format( "{{" + "\"gift_card_value_addition\": {{" + "\"payment_token_data\": \"{0}\"," + "\"value_amount\": {1}," + "\"location_id\": {2}," + "\"order_uuid\": \"{3}\"," + "\"tender_types\": [\"{4}\"], " + "\"identifier_from_merchant\": \"{5}\" " + "}}" + "}}", payment_token_data, value_amount, location_id, order_uuid, tender_types, identifier_from_merchant); RestResponse expectedResponse = new RestResponse { StatusCode = HttpStatusCode.OK, Content = "{" + "\"gift_card_value_addition\": {" + "\"added_value_amount\": 1000," + "\"new_value_at_merchant_amount\": 1000," + "\"old_value_at_merchant_amount\": 0," + "}" + "}" }; ICreateGiftCardValue client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <ICreateGiftCardValue, GiftCardAddValueRequest>( expectedResponse, expectedRequestbody, expectedAccessToken: accessToken, expectedRequestUrl: expectedRequestUrl); var valueAddition = client.GiftCardAddValue(accessToken, merchant_id, location_id, payment_token_data, value_amount, identifier_from_merchant, new List <string>(new[] { tender_types }), order_uuid); Assert.AreEqual(valueAddition.AmountAddedInCents, 1000); Assert.AreEqual(valueAddition.NewGiftCardAmountInCents, 1000); Assert.AreEqual(valueAddition.PreviousGiftCardAmountInCents, 0); }
public void UpdateUserShouldSucceed() { string expectedRequestUrl = ClientModuleFunctionalTestingUtilities.SANDBOX_URL_PREFIX + "/v14/users/123"; IModifyUser client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <IModifyUser>( expectedCreateOrUpdateUserResponse, expectedRequestUrl: expectedRequestUrl); var user = client.UpdateUser("not_checking_this", new UpdateUserRequestBody(123)); Assert.AreEqual(user.GlobalCreditAmount, globalCreditAmount); Assert.AreEqual(user.Gender, gender); Assert.AreEqual(user.CustomAttributes[customAttributes.Key], customAttributes.Value); }
public void CompleteProposedOrderShouldSucceedForDiscountsDisabled() { string expectedRequestUrl = ClientModuleFunctionalTestingUtilities.SANDBOX_URL_PREFIX + "/v15/completed_orders"; string expectedRequest = "{" + "\"completed_order\": {" + "\"applied_discount_amount\": null," + "\"cashier\": \"Bob\"," + "\"exemption_amount\": 40," + "\"identifier_from_merchant\": \"001001\"," + "\"location_id\": 19," + "\"partial_authorization_allowed\": false," + "\"payment_token_data\": \"LU02000008ZS9OJFUBNEL6ZM030000LU\"," + "\"proposed_order_uuid\": \"1b3b3c4d5e6f7g8a9i9h8g7f6e5d4c3b2a1\"," + "\"receipt_message_html\": \"Pick up your order at <strong>counter #4</strong>\"," + "\"register\": \"3\"," + "\"spend_amount\": 200," + "\"tax_amount\": 0," + GetSampleItems().Item1 + "}" + "}"; RestResponse expectedResponse = new RestResponse { StatusCode = HttpStatusCode.OK, Content = "{ " + "\"order\": { " + "\"gift_card_total_amount\": 0, " + "\"gift_card_tip_amount\": 0, " + "\"spend_amount\": 200, " + "\"tip_amount\": 0, " + "\"total_amount\": 200, " + "\"uuid\": \"5a1z9x2h31ah7g8a9i9h8g7f6e5d4c4a21o\"" + "}" + "}" }; var items = GetSampleItems().Item2; IManageProposedOrders client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <IManageProposedOrders, CompleteProposedOrderRequest>( expectedResponse, expectedRequest, expectedRequestUrl: expectedRequestUrl); var completedOrder = client.CompleteProposedOrder("not_checking_this", 19, "LU02000008ZS9OJFUBNEL6ZM030000LU", "1b3b3c4d5e6f7g8a9i9h8g7f6e5d4c3b2a1", 300, 200, 10, 130, null, "3", "Bob", "001001", "Pick up your order at <strong>counter #4</strong>", false, false, items); Assert.AreEqual(completedOrder.GiftCardTotalAmount, 0); Assert.AreEqual(completedOrder.GiftCardTipAmount, 0); Assert.AreEqual(completedOrder.SpendAmount, 200); Assert.AreEqual(completedOrder.TipAmount, 0); Assert.AreEqual(completedOrder.Total, 200); Assert.AreEqual(completedOrder.OrderIdentifier, "5a1z9x2h31ah7g8a9i9h8g7f6e5d4c4a21o"); }
public void GetLocationDetailsShouldSucceed() { const int locationId = 17; string expectedRequestUrl = ClientModuleFunctionalTestingUtilities.SANDBOX_URL_PREFIX + "/v15/locations/" + locationId; RestResponse expectedResponse = new RestResponse { StatusCode = HttpStatusCode.OK, Content = string.Format("{{" + "\"location\": {{" + "\"categories\": [" + "50" + "]," + "\"extended_address\": \"\"," + "\"facebook_url\": \"http://www.facebook.com/pages/PizzaPalace\"," + "\"foodler_url\": \"http://deeplink.me/www.foodler.com/pizza-palace/1234\"," + "\"hours\": null," + "\"id\": {0}," + "\"latitude\": 42.351639," + "\"locality\": \"Boston\"," + "\"longitude\": -71.121797," + "\"menu_url\": null," + "\"merchant_id\": 18," + "\"merchant_description_html\": \"This is a place that has pizza!\"," + "\"merchant_name\": \"Pizza Palace\"," + "\"merchant_tip_preference\": \"no preference\"," + "\"name\": null," + "\"newsletter_url\": null," + "\"opentable_url\": null," + "\"phone\": null," + "\"postal_code\": \"02215\"," + "\"region\": \"MA\"," + "\"street_address\": \"1024 Pizza Road\"," + "\"twitter_url\": null," + "\"updated_at\": \"2014-11-30T10:28:23-05:00\"," + "\"yelp_url\": \"http://www.yelp.com/biz/pizza-palace\"," + "\"shown\": true" + "}}" + "}}", locationId) }; IQueryMerchantData client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <IQueryMerchantData>( expectedResponse, expectedRequestUrl: expectedRequestUrl); var details = client.GetLocationDetails("not_checking_this", locationId); Assert.AreEqual(details.LocationId, locationId); Assert.AreEqual(details.Address.PostalCode, "02215"); }
public void PasswordResetRequestShouldSucceed() { const string expectedRequestUrl = ClientModuleFunctionalTestingUtilities.SANDBOX_URL_PREFIX + "/v14/passwords"; const string expectedRequestBody = "{\"email\": \"[email protected]\"}"; RestResponse expectedResponse = new RestResponse { StatusCode = HttpStatusCode.NoContent }; IModifyUser client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <IModifyUser, PasswordResetRequest>( expectedResponse, expectedRequestBody, expectedRequestUrl); client.PasswordResetRequest("*****@*****.**"); }
public void ListOrdersShouldSucceedWhenAllPagesQueried() { IQueryOrders client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModuleWithPaging <IQueryOrders>(successfulResponses, expectedRequestBaseUrl); var orders = client.ListOrders("not_checking_this", locationId, 1, 3); Assert.AreEqual(orders.Count, 9); Assert.AreEqual(orders[0].OrderIdentifier, "a"); Assert.AreEqual(orders[1].OrderIdentifier, "b"); Assert.AreEqual(orders[2].OrderIdentifier, "c"); Assert.AreEqual(orders[3].OrderIdentifier, "d"); Assert.AreEqual(orders[4].OrderIdentifier, "e"); Assert.AreEqual(orders[5].OrderIdentifier, "f"); Assert.AreEqual(orders[6].OrderIdentifier, "g"); Assert.AreEqual(orders[7].OrderIdentifier, "h"); Assert.AreEqual(orders[8].OrderIdentifier, "i"); }
public void AuthenticationShouldFailForErrorCode404NotFound() { const string testClientId = "1212whatsinthestew34noonesreallysure"; const string testMerchantUsername = "******"; const string testMerchantPassword = "******"; RestResponse expected = new RestResponse { StatusCode = HttpStatusCode.NotFound }; IAuthenticate auth = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <IAuthenticate>(expected); // Should throw exception for non-200 [OK] response Assert.Throws <LevelUpApiException>(() => { auth.Authenticate(testClientId, testMerchantUsername, testMerchantPassword); }, "No LevelUpAPI exception was thrown for a response with a return code of 404."); }
public void ListCreditCardsShouldSucceed() { string expectedRequestUrl = ClientModuleFunctionalTestingUtilities.SANDBOX_URL_PREFIX + "/v15/credit_cards"; RestResponse expectedResponse = new RestResponse { StatusCode = HttpStatusCode.OK, Content = "[" + "{" + "\"credit_card\": {" + "\"bin\": \"123456\"," + "\"description\": \"JCB ending in 1234\"," + "\"expiration_month\": 7," + "\"expiration_year\": 2015," + "\"id\": 305999," + "\"last_4\": \"1234\"," + "\"promoted\": true," + "\"state\": \"active\"," + "\"type\": \"JCB\"" + "}" + "}," + "{" + "\"credit_card\": {" + "\"bin\": \"654321\"," + "\"description\": \"JCB ending in 4321\"," + "\"expiration_month\": 3," + "\"expiration_year\": 2015," + "\"id\": 999503," + "\"last_4\": \"4321\"," + "\"promoted\": false," + "\"state\": \"active\"," + "\"type\": \"JCB\"" + "}" + "}" + "]" }; IQueryCreditCards client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <IQueryCreditCards>( expectedResponse, expectedAccessToken: "access_token", expectedRequestUrl: expectedRequestUrl); var cards = client.ListCreditCards("access_token"); Assert.AreEqual(cards.Count, 2); Assert.AreEqual(cards[0].Bin, "123456"); Assert.AreEqual(cards[1].Bin, "654321"); }
public void ListOrdersShouldSucceedAndAreThereMorePagesShouldBeValid() { IQueryOrders client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModuleWithPaging <IQueryOrders>(successfulResponses, expectedRequestBaseUrl); bool areThereMorePages; var orders = client.ListOrders("not_checking_this", locationId, 1, 1, out areThereMorePages); Assert.IsTrue(areThereMorePages); orders = client.ListOrders("not_checking_this", locationId, 1, 3, out areThereMorePages); Assert.IsFalse(areThereMorePages); orders = client.ListOrders("not_checking_this", locationId, 3, 3, out areThereMorePages); Assert.IsFalse(areThereMorePages); orders = client.ListOrders("not_checking_this", locationId, 2, 5, out areThereMorePages); Assert.IsFalse(areThereMorePages); }
public void GetLoyaltyShouldFailForBadStatusCode() { const int merchant_Id = 456; string expectedRequestUrl = string.Format(ClientModuleFunctionalTestingUtilities.SANDBOX_URL_PREFIX + "/v14/merchants/{0}/loyalty", merchant_Id); RestResponse expectedResponse = new RestResponse { StatusCode = HttpStatusCode.NotFound, }; Assert.Throws <LevelUpApiException>( () => { ILookupUserLoyalty client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <ILookupUserLoyalty>( expectedResponse, expectedRequestUrl: expectedRequestUrl); client.GetLoyalty("not_checking_this", merchant_Id); }, "GetLoyalty failed to throw an exception for an invalid returned http status code."); }
public void CreateCreditCardShouldFailForInvalidCardDetails() { RestResponse expectedResponse = new RestResponse { StatusCode = (HttpStatusCode)422, Content = "[{\"error\":{\"object\":\"credit_card\",\"property\":\"expiration_year\",\"message\":\"Expiration year is invalid.\"}}]" }; try { ICreateCreditCards client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <ICreateCreditCards>(expectedResponse); var card = client.CreateCreditCard("abc", new CreateCreditCardRequestBody("we", "aren't", "checking", "these", "params")); Assert.IsTrue(false, "Failed to throw a LevelUpApiException for invalid card data (422 response code)"); } catch (LevelUpApiException ex) { Assert.AreEqual((int)ex.StatusCode, 422); Assert.AreEqual(ex.Message.Trim(), "Expiration year is invalid."); } }
public void CreateDetachedRefundShouldFailDeserialization() { // Note: This test is not really specific to Detached Refunds. RestResponse expectedResponse = new RestResponse { StatusCode = HttpStatusCode.OK, Content = "{{" + "\"detached_refund\": {{" + "\"cashier\": \"blah\"," + "}}" + "}}" }; ICreateDetachedRefund client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <ICreateDetachedRefund>(expectedResponse); Assert.Throws <LevelUpApiException>(() => { var resp = client.CreateDetachedRefund("we", 0, "are", 0, "not", "checking", "any", "of", "these", "strings"); }, "No LevelUpAPI exception was thrown for an invalid response body."); }
public void GiftCardDestroyValueShouldSucceed() { string paymentTokenData = "LU020000029080KFZ02I9A8V030000LU"; int merchantId = 3; int valueAmountCents = 100; int initialTotalValueAtMerchantCents = 202; string expectedRequestUrl = string.Format(ClientModuleFunctionalTestingUtilities.SANDBOX_URL_PREFIX + "/v15/merchants/{0}/gift_card_value_removals", merchantId); string expectedRequestBody = string.Format("{{" + "\"gift_card_value_removal\":{{" + "\"payment_token_data\":\"{0}\"," + "\"value_amount\":{1}" + "}}" + "}}", paymentTokenData, valueAmountCents); RestResponse expectedResponse = new RestResponse { StatusCode = HttpStatusCode.OK, Content = string.Format("{{" + "\"gift_card_value_removal\":{{" + "\"removed_value_amount\":{0}," + "\"new_value_at_merchant_amount\":{1}," + "\"old_value_at_merchant_amount\":{2}," + "}}" + "}}", valueAmountCents, (initialTotalValueAtMerchantCents - valueAmountCents), initialTotalValueAtMerchantCents) }; IDestroyGiftCardValue client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <IDestroyGiftCardValue, GiftCardRemoveValueRequest>( expectedResponse, expectedRequestBody, expectedRequestUrl: expectedRequestUrl); var destroyed = client.GiftCardDestroyValue("not_checking_this", merchantId, paymentTokenData, valueAmountCents); Assert.AreEqual(destroyed.AmountRemovedInCents, valueAmountCents); Assert.AreEqual(destroyed.PreviousGiftCardAmountInCents, initialTotalValueAtMerchantCents); Assert.AreEqual(destroyed.NewGiftCardAmountInCents, initialTotalValueAtMerchantCents - valueAmountCents); }
public void ListManagedLocationsShouldSucceed() { string expectedRequestUrl = ClientModuleFunctionalTestingUtilities.SANDBOX_URL_PREFIX + "/v15/managed_locations"; RestResponse expectedResponse = new RestResponse { StatusCode = HttpStatusCode.OK, Content = "[{" + "\"location\": {" + "\"address\": \"101 Arch St., Boston, MA\"," + "\"id\": 3," + "\"merchant_id\": 1," + "\"merchant_name\": \"LevelUp Cafe\"," + "\"name\": \"LU#3 - 101 Arch St.\"," + "\"tip_preference\": \"expected\"" + "}" + "}," + "{" + "\"location\": {" + "\"address\": \"1 Beach Dr, Honolulu, HI\"," + "\"id\": 10," + "\"merchant_id\": 1001," + "\"merchant_name\": \"Hang Ten Cafe\"," + "\"name\": \"LU#10 - 1 Beach Dr.\"," + "\"tip_preference\": \"unwanted\"" + "}" + "}]" }; string expectedAccessToken = "token merchant=\"my_access_token\""; IQueryMerchantData client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <IQueryMerchantData>( expectedResponse, expectedRequestUrl: expectedRequestUrl, expectedAccessToken: expectedAccessToken); var locations = client.ListManagedLocations("my_access_token"); Assert.IsTrue(locations.Count == 2); Assert.IsTrue(locations[0].LocationId == 3); Assert.IsTrue(locations[0].TipPreference == "expected"); }
public void GiftCardDestroyValueShouldFailForBadHttpStatusCodes() { List <RestResponse> possibleErrors = new List <RestResponse>(new RestResponse[] { new RestResponse // Invalid QR code { StatusCode = HttpStatusCode.NotFound }, new RestResponse // Destroy value was negative { StatusCode = (HttpStatusCode)422, Content = "[{\"error\":{\"object\":\"gift_cards/value_adder\",\"property\":\"base\",\"message\":\"You must remove a positive value.\"}}]" }, new RestResponse // Destroy value was more than giftcard value { StatusCode = (HttpStatusCode)422, Content = "[{\"error\":{\"object\":\"gift_cards/value_adder\",\"property\":\"base\",\"message\":\"This giftcard has a balance of $X.XX. Please retry with that amount.\"}}]" }, new RestResponse // Bad merchant token { StatusCode = HttpStatusCode.Unauthorized } }); foreach (var response in possibleErrors) { IDestroyGiftCardValue client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <IDestroyGiftCardValue>(response); try { var destroyed = client.GiftCardDestroyValue("not_checking_this", 1, "not_checking_this", 1000); Assert.Fail("GiftCardDestroyValue failed to throw for an invalid HTTP return code of " + response.StatusCode); } catch (LevelUp.Api.Http.LevelUpApiException) { } } }
public void CreateUserShouldSucceed() { string expectedRequestUrl = ClientModuleFunctionalTestingUtilities.SANDBOX_URL_PREFIX + "/v14/users"; string expectedRequestBody = string.Format("{{" + "\"api_key\": \"{0}\"," + "\"user\":{{" + "\"email\":\"{1}\"," + "\"first_name\":\"{2}\"," + "\"last_name\":\"{3}\"," + "\"password\":\"{4}\"" + "}}," + "}}", apiKey, email, firstName, lastName, password); IModifyUser client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <IModifyUser, CreateUserRequest>( expectedCreateOrUpdateUserResponse, expectedRequestBody, expectedRequestUrl: expectedRequestUrl); var user = client.CreateUser(apiKey, firstName, lastName, email, password); Assert.AreEqual(user.GlobalCreditAmount, globalCreditAmount); Assert.AreEqual(user.Gender, gender); Assert.AreEqual(user.CustomAttributes[customAttributes.Key], customAttributes.Value); }
public void AuthenticationShouldSucceedForCode200OK() { const int expectedUserId = 54321; const int expectedmerchantId = 32225; RestResponse expectedResponse = new RestResponse { StatusCode = HttpStatusCode.OK, Content = "{\"access_token\":" + "{\"merchant_id\":" + expectedmerchantId + ",\"token\":\"5564290-ee38925c6de8f4fd945e1606b232296f52f805563fb882fed1c6bq465dc367\"" + // this is not a real token ",\"user_id\":" + expectedUserId + "}}" }; IAuthenticate iAuth = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <IAuthenticate>(expectedResponse); var token = iAuth.Authenticate("This doesn't matter", "This has no bearing", "This can be whatever you want"); Assert.IsNotNull(token, "The deserialization of this successful authentication response should have succeeded"); Assert.AreEqual(token.MerchantId, expectedmerchantId); Assert.AreEqual(token.UserId, expectedUserId); }
public void GetPaymentTokenShouldSucceed() { const string expectedRequestUrl = ClientModuleFunctionalTestingUtilities.SANDBOX_URL_PREFIX + "/v15/payment_token"; RestResponse expectedResponse = new RestResponse { StatusCode = HttpStatusCode.OK, Content = "{" + "\"payment_token\": {" + "\"data\": \"LU02000008ZS9OJFUBNEL6ZM\"," + "\"id\": 323" + "}" + "}" }; IRetrievePaymentToken client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <IRetrievePaymentToken>( expectedResponse, expectedRequestUrl: expectedRequestUrl); var paymentToken = client.GetPaymentToken("not_checking_this"); Assert.AreEqual(paymentToken.Id, 323); Assert.AreEqual(paymentToken.Data, "LU02000008ZS9OJFUBNEL6ZM"); }
public void ListUserAddressesShouldSucceed() { const string expectedRequestUrl = ClientModuleFunctionalTestingUtilities.SANDBOX_URL_PREFIX + "/v15/user_addresses"; RestResponse expectedResponse = new RestResponse { StatusCode = HttpStatusCode.OK, Content = "[{" + "\"user_address\": {" + "\"address_type\": \"payment\"," + "\"extended_address\": \"\"," + "\"id\": 149," + "\"locality\": \"Boston\"," + "\"postal_code\": \"01801\"," + "\"region\": \"MA\"," + "\"street_address\": \"123 Fake St\"" + "}" + "},{" + "\"user_address\": {" + "\"address_type\": \"payment\"," + "\"extended_address\": \"\"," + "\"id\": 149," + "\"locality\": \"Boston\"," + "\"postal_code\": \"01801\"," + "\"region\": \"MA\"," + "\"street_address\": \"123 Fake St\"" + "}" + "}]" }; IQueryUser client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <IQueryUser>( expectedResponse, expectedRequestUrl: expectedRequestUrl); var addresses = client.ListUserAddresses("not_checking_this"); Assert.AreEqual(addresses.Count, 2); }