|
| 1 | +using System.Collections.Generic; |
| 2 | +using System.Net; |
| 3 | +using System.Threading.Tasks; |
| 4 | +using EasyPost.Http; |
| 5 | +using EasyPost.Models.API; |
| 6 | +using EasyPost.Tests._Utilities; |
| 7 | +using Xunit; |
| 8 | + |
| 9 | +namespace EasyPost.Tests.ServicesTests |
| 10 | +{ |
| 11 | + public class FedExRegistrationServiceTests : UnitTest |
| 12 | + { |
| 13 | + public FedExRegistrationServiceTests() : base("fedex_registration_service", TestUtils.ApiKey.Production) |
| 14 | + { |
| 15 | + } |
| 16 | + |
| 17 | + protected override IEnumerable<TestUtils.MockRequest> MockRequests |
| 18 | + { |
| 19 | + get |
| 20 | + { |
| 21 | + return new List<TestUtils.MockRequest> |
| 22 | + { |
| 23 | + new( |
| 24 | + new TestUtils.MockRequestMatchRules(Method.Post, @"v2\/fedex_registrations\/\S*\/address$"), |
| 25 | + new TestUtils.MockRequestResponseInfo(HttpStatusCode.OK, data: new FedExAccountValidationResponse |
| 26 | + { |
| 27 | + EmailAddress = "test@example.com", |
| 28 | + PhoneNumber = "5555555555", |
| 29 | + Options = new List<string> { "SMS", "CALL", "INVOICE" }, |
| 30 | + }) |
| 31 | + ), |
| 32 | + new( |
| 33 | + new TestUtils.MockRequestMatchRules(Method.Post, @"v2\/fedex_registrations\/\S*\/pin$"), |
| 34 | + new TestUtils.MockRequestResponseInfo(HttpStatusCode.OK, data: new FedExRequestPinResponse |
| 35 | + { |
| 36 | + Message = "Your secured PIN has been sent to your phone.", |
| 37 | + }) |
| 38 | + ), |
| 39 | + new( |
| 40 | + new TestUtils.MockRequestMatchRules(Method.Post, @"v2\/fedex_registrations\/\S*\/pin\/validate$"), |
| 41 | + new TestUtils.MockRequestResponseInfo(HttpStatusCode.OK, data: new FedExAccountValidationResponse |
| 42 | + { |
| 43 | + Id = "ca_test123", |
| 44 | + ObjectType = "CarrierAccount", |
| 45 | + Type = "FedexAccount", |
| 46 | + Credentials = new Dictionary<string, string> |
| 47 | + { |
| 48 | + { "account_number", "123456789" }, |
| 49 | + { "mfa_key", "test_mfa_key" }, |
| 50 | + }, |
| 51 | + }) |
| 52 | + ), |
| 53 | + new( |
| 54 | + new TestUtils.MockRequestMatchRules(Method.Post, @"v2\/fedex_registrations\/\S*\/invoice$"), |
| 55 | + new TestUtils.MockRequestResponseInfo(HttpStatusCode.OK, data: new FedExAccountValidationResponse |
| 56 | + { |
| 57 | + Id = "ca_test123", |
| 58 | + ObjectType = "CarrierAccount", |
| 59 | + Type = "FedexAccount", |
| 60 | + Credentials = new Dictionary<string, string> |
| 61 | + { |
| 62 | + { "account_number", "123456789" }, |
| 63 | + { "mfa_key", "test_mfa_key" }, |
| 64 | + }, |
| 65 | + }) |
| 66 | + ), |
| 67 | + }; |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + #region Tests |
| 72 | + |
| 73 | + [Fact] |
| 74 | + public async Task TestRegisterAddress() |
| 75 | + { |
| 76 | + UseMockClient(); |
| 77 | + |
| 78 | + Parameters.FedExRegistration.RegisterAddress parameters = new Parameters.FedExRegistration.RegisterAddress |
| 79 | + { |
| 80 | + Name = "test_name", |
| 81 | + Company = "test_company", |
| 82 | + Street1 = "test_street", |
| 83 | + City = "test_city", |
| 84 | + State = "test_state", |
| 85 | + Zip = "test_zip", |
| 86 | + Country = "US", |
| 87 | + Phone = "test_phone", |
| 88 | + }; |
| 89 | + |
| 90 | + FedExAccountValidationResponse response = await Client.FedExRegistration.RegisterAddress("123456789", parameters); |
| 91 | + |
| 92 | + Assert.NotNull(response); |
| 93 | + Assert.NotNull(response.Options); |
| 94 | + Assert.Contains("SMS", response.Options); |
| 95 | + Assert.Contains("CALL", response.Options); |
| 96 | + Assert.Contains("INVOICE", response.Options); |
| 97 | + Assert.NotNull(response.PhoneNumber); |
| 98 | + } |
| 99 | + |
| 100 | + [Fact] |
| 101 | + public async Task TestRequestPin() |
| 102 | + { |
| 103 | + UseMockClient(); |
| 104 | + |
| 105 | + FedExRequestPinResponse response = await Client.FedExRegistration.RequestPin("123456789", "SMS"); |
| 106 | + |
| 107 | + Assert.NotNull(response); |
| 108 | + Assert.NotNull(response.Message); |
| 109 | + Assert.Contains("secured PIN", response.Message); |
| 110 | + } |
| 111 | + |
| 112 | + [Fact] |
| 113 | + public async Task TestValidatePin() |
| 114 | + { |
| 115 | + UseMockClient(); |
| 116 | + |
| 117 | + Parameters.FedExRegistration.ValidatePin parameters = new Parameters.FedExRegistration.ValidatePin |
| 118 | + { |
| 119 | + Name = "test_name", |
| 120 | + Pin = "123456", |
| 121 | + }; |
| 122 | + |
| 123 | + FedExAccountValidationResponse response = await Client.FedExRegistration.ValidatePin("123456789", parameters); |
| 124 | + |
| 125 | + Assert.NotNull(response); |
| 126 | + Assert.NotNull(response.Credentials); |
| 127 | + Assert.True(response.Credentials.ContainsKey("account_number")); |
| 128 | + Assert.True(response.Credentials.ContainsKey("mfa_key")); |
| 129 | + } |
| 130 | + |
| 131 | + [Fact] |
| 132 | + public async Task TestSubmitInvoice() |
| 133 | + { |
| 134 | + UseMockClient(); |
| 135 | + |
| 136 | + Parameters.FedExRegistration.SubmitInvoice parameters = new Parameters.FedExRegistration.SubmitInvoice |
| 137 | + { |
| 138 | + Name = "test_name", |
| 139 | + InvoiceNumber = "test_invoice", |
| 140 | + InvoiceAmount = "100.00", |
| 141 | + InvoiceDate = "2023-01-01", |
| 142 | + }; |
| 143 | + |
| 144 | + FedExAccountValidationResponse response = await Client.FedExRegistration.SubmitInvoice("123456789", parameters); |
| 145 | + |
| 146 | + Assert.NotNull(response); |
| 147 | + Assert.NotNull(response.Credentials); |
| 148 | + Assert.True(response.Credentials.ContainsKey("account_number")); |
| 149 | + Assert.True(response.Credentials.ContainsKey("mfa_key")); |
| 150 | + } |
| 151 | + |
| 152 | + #endregion |
| 153 | + } |
| 154 | +} |
0 commit comments