diff --git a/CHANGELOG.md b/CHANGELOG.md index 22e7f8ae7..362e92fd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## Next Release + +- Routes `UpsAccount`, `UpsMailInnovationsAccount`, and `UpsSurepostAccount` create/update requests to the new `/ups_oauth_registrations` endpoint + - Starting `2024-08-05`, UPS accounts will require a new payload to register or update. See [UPS OAuth 2.0 Update](https://support.easypost.com/hc/en-us/articles/26635027512717-UPS-OAuth-2-0-Update?utm_medium=email&_hsenc=p2ANqtz-96MmFtWICOzy9sKRbbcZSiMovZSrY3MSX1_bgY9N3f9yLVfWQdLhjAGq-SmNcOnDIS6GYhZ0OApjDBrGkKyLLMx1z6_TFOVp6-wllhEFQINrkuRuc&_hsmi=313130292&utm_content=313130292&utm_source=hs_email) for more details + ## v7.2.1 (2024-04-12) - Fix `Fields` serialization bug causing carrier account operations to fail diff --git a/Makefile b/Makefile index ea63b8d3e..e3e2c4491 100644 --- a/Makefile +++ b/Makefile @@ -28,8 +28,13 @@ install-styleguide: | update-examples-submodule curl -LJs https://github.com/checkstyle/checkstyle/releases/download/checkstyle-10.3.1/checkstyle-10.3.1-all.jar -o checkstyle.jar sh examples/symlink_directory_files.sh examples/style_guides/java . +## init-examples-submodule - Initialize the examples submodule +init-examples-submodule: + git submodule init + git submodule update + ## install - Install requirements -install: | update-examples-submodule +install: | init-examples-submodule ## lint - Lints the project lint: checkstyle scan diff --git a/examples b/examples index b9fde9bea..b79c16ee6 160000 --- a/examples +++ b/examples @@ -1 +1 @@ -Subproject commit b9fde9bead7750256bc986802841ce7576eee0a4 +Subproject commit b79c16ee6c3ea1e9da707b95c0a67157fa906519 diff --git a/src/main/java/com/easypost/Constants.java b/src/main/java/com/easypost/Constants.java index 75d11c7c7..c470d63b7 100644 --- a/src/main/java/com/easypost/Constants.java +++ b/src/main/java/com/easypost/Constants.java @@ -62,7 +62,12 @@ public abstract static class ErrorCodes { public abstract static class CarrierAccountTypes { public static final List CARRIER_TYPES_WITH_CUSTOM_WORKFLOW = ImmutableList.of("FedexAccount", - "UpsAccount", "FedexSmartpostAccount"); + "FedexSmartpostAccount"); + } + + public abstract static class UpsAccountTypes { + public static final List UPS_OAUTH_CARRIER_ACCOUNT_TYPES = ImmutableList.of("UpsAccount", + "UpsMailInnovationsAccount", "UpsSurepostAccount"); } public abstract static class Http { diff --git a/src/main/java/com/easypost/service/CarrierAccountService.java b/src/main/java/com/easypost/service/CarrierAccountService.java index a1842a752..b40e8ea6a 100644 --- a/src/main/java/com/easypost/service/CarrierAccountService.java +++ b/src/main/java/com/easypost/service/CarrierAccountService.java @@ -33,14 +33,8 @@ public class CarrierAccountService { */ public CarrierAccount create(final Map params) throws EasyPostException { String type = (String) params.get("type"); - if (type == null) { - throw new MissingParameterError( - String.format(Constants.ErrorMessages.MISSING_REQUIRED_PARAMETER, "carrier account type")); - } - Map wrappedParams = new HashMap(); - wrappedParams.put("carrier_account", params); - + wrappedParams.put(selectTopLayerKey(type), params); String endpoint = selectCarrierAccountCreationEndpoint(type); return Requestor.request(RequestMethod.POST, endpoint, wrappedParams, CarrierAccount.class, client); @@ -88,16 +82,20 @@ public List all(final Map params) throws EasyPos /** * Update this carrier account. * - * @param params parameters to update. * @param id The ID of carrier account + * @param params parameters to update. * @return updated CarrierAccount object. * @throws EasyPostException when the request fails. */ public CarrierAccount update(String id, final Map params) throws EasyPostException { + CarrierAccount carrierAccount = this.retrieve(id); + String type = (String) carrierAccount.getType(); Map wrappedParams = new HashMap(); - wrappedParams.put("carrier_account", params); + wrappedParams.put(selectTopLayerKey(type), params); - String endpoint = "carrier_accounts/" + id; + String endpoint = (Constants.UpsAccountTypes.UPS_OAUTH_CARRIER_ACCOUNT_TYPES.contains(type) + ? "ups_oauth_registrations/" + : "carrier_accounts/") + id; return Requestor.request(RequestMethod.PUT, endpoint, wrappedParams, CarrierAccount.class, client); @@ -125,8 +123,28 @@ public void delete(String id) throws EasyPostException { private static String selectCarrierAccountCreationEndpoint(final String carrierAccountType) { if (Constants.CarrierAccountTypes.CARRIER_TYPES_WITH_CUSTOM_WORKFLOW.contains(carrierAccountType)) { return "carrier_accounts/register"; + } else if (Constants.UpsAccountTypes.UPS_OAUTH_CARRIER_ACCOUNT_TYPES.contains(carrierAccountType)) { + return "ups_oauth_registrations"; } else { return "carrier_accounts"; } } + + /** + * Select the top-layer key for the carrier account creation/update request based on the + * carrier type. + * + * @param carrierAccountType The type of carrier account to create. + * @return The top-layer key for the carrier account creation/update request. + */ + private static String selectTopLayerKey(final String carrierAccountType) throws EasyPostException { + if (carrierAccountType == null) { + throw new MissingParameterError( + String.format(Constants.ErrorMessages.MISSING_REQUIRED_PARAMETER, "carrier account type")); + } + + return Constants.UpsAccountTypes.UPS_OAUTH_CARRIER_ACCOUNT_TYPES.contains(carrierAccountType) + ? "ups_oauth_registrations" + : "carrier_account"; + } } diff --git a/src/test/cassettes/carrier_account/create_with_ups.json b/src/test/cassettes/carrier_account/create_with_ups.json new file mode 100644 index 000000000..d21710e30 --- /dev/null +++ b/src/test/cassettes/carrier_account/create_with_ups.json @@ -0,0 +1,263 @@ +[ + { + "recordedAt": 1720548416, + "request": { + "body": "{\n \"ups_oauth_registrations\": {\n \"account_number\": \"123456789\",\n \"type\": \"UpsAccount\"\n }\n}", + "method": "POST", + "headers": { + "Accept-Charset": [ + "UTF-8" + ], + "User-Agent": [ + "REDACTED" + ], + "Content-Type": [ + "application/json" + ] + }, + "uri": "https://api.easypost.com/v2/ups_oauth_registrations" + }, + "response": { + "body": "{\n \"readable\": \"UPS\",\n \"credentials\": {},\n \"created_at\": \"2024-07-09T18:06:56Z\",\n \"description\": null,\n \"type\": \"UpsAccount\",\n \"reference\": null,\n \"updated_at\": \"2024-07-09T18:06:56Z\",\n \"clone\": false,\n \"billing_type\": \"carrier\",\n \"logo\": null,\n \"id\": \"ca_7f975bbec5e44551a6da1db4c2b340b9\",\n \"fields\": {\n \"credentials\": {}\n },\n \"object\": \"CarrierAccount\"\n}", + "httpVersion": null, + "headers": { + "null": [ + "HTTP/1.1 201 Created" + ], + "content-length": [ + "1400" + ], + "expires": [ + "0" + ], + "x-node": [ + "bigweb42nuq" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-backend": [ + "easypost" + ], + "x-permitted-cross-domain-policies": [ + "none" + ], + "x-download-options": [ + "noopen" + ], + "strict-transport-security": [ + "max-age\u003d31536000; includeSubDomains; preload" + ], + "pragma": [ + "no-cache" + ], + "x-content-type-options": [ + "nosniff" + ], + "x-xss-protection": [ + "1; mode\u003dblock" + ], + "x-ep-request-uuid": [ + "7e943982668d7c40e7885d82005399f0" + ], + "x-proxied": [ + "extlb2nuq fa152d4755", + "intlb4nuq fa152d4755" + ], + "referrer-policy": [ + "strict-origin-when-cross-origin" + ], + "x-runtime": [ + "0.086437" + ], + "content-type": [ + "application/json; charset\u003dutf-8" + ], + "x-version-label": [ + "easypost-202407091438-d7c6f02f06-master" + ], + "cache-control": [ + "private, no-cache, no-store" + ] + }, + "status": { + "code": 201, + "message": "Created" + }, + "uri": "https://api.easypost.com/v2/ups_oauth_registrations" + }, + "duration": 549 + }, + { + "recordedAt": 1720548417, + "request": { + "body": "", + "method": "GET", + "headers": { + "Accept-Charset": [ + "UTF-8" + ], + "User-Agent": [ + "REDACTED" + ] + }, + "uri": "https://api.easypost.com/v2/carrier_accounts/ca_7f975bbec5e44551a6da1db4c2b340b9" + }, + "response": { + "body": "{\n \"readable\": \"UPS\",\n \"credentials\": {},\n \"created_at\": \"2024-07-09T18:06:56Z\",\n \"description\": null,\n \"type\": \"UpsAccount\",\n \"reference\": null,\n \"updated_at\": \"2024-07-09T18:06:56Z\",\n \"clone\": false,\n \"billing_type\": \"carrier\",\n \"logo\": null,\n \"id\": \"ca_7f975bbec5e44551a6da1db4c2b340b9\",\n \"fields\": {\n \"credentials\": {}\n },\n \"object\": \"CarrierAccount\"\n}", + "httpVersion": null, + "headers": { + "null": [ + "HTTP/1.1 200 OK" + ], + "content-length": [ + "1400" + ], + "expires": [ + "0" + ], + "x-node": [ + "bigweb38nuq" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-backend": [ + "easypost" + ], + "x-permitted-cross-domain-policies": [ + "none" + ], + "x-download-options": [ + "noopen" + ], + "strict-transport-security": [ + "max-age\u003d31536000; includeSubDomains; preload" + ], + "pragma": [ + "no-cache" + ], + "x-content-type-options": [ + "nosniff" + ], + "x-xss-protection": [ + "1; mode\u003dblock" + ], + "x-ep-request-uuid": [ + "7e943984668d7c40e7885d8300539aa7" + ], + "x-proxied": [ + "extlb2nuq fa152d4755", + "intlb4nuq fa152d4755" + ], + "referrer-policy": [ + "strict-origin-when-cross-origin" + ], + "x-runtime": [ + "0.039495" + ], + "content-type": [ + "application/json; charset\u003dutf-8" + ], + "x-version-label": [ + "easypost-202407091438-d7c6f02f06-master" + ], + "cache-control": [ + "private, no-cache, no-store" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "uri": "https://api.easypost.com/v2/carrier_accounts/ca_7f975bbec5e44551a6da1db4c2b340b9" + }, + "duration": 495 + }, + { + "recordedAt": 1720548417, + "request": { + "body": "", + "method": "DELETE", + "headers": { + "Accept-Charset": [ + "UTF-8" + ], + "User-Agent": [ + "REDACTED" + ] + }, + "uri": "https://api.easypost.com/v2/carrier_accounts/ca_7f975bbec5e44551a6da1db4c2b340b9" + }, + "response": { + "body": "{}", + "httpVersion": null, + "headers": { + "null": [ + "HTTP/1.1 200 OK" + ], + "content-length": [ + "2" + ], + "expires": [ + "0" + ], + "x-node": [ + "bigweb36nuq" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-backend": [ + "easypost" + ], + "x-permitted-cross-domain-policies": [ + "none" + ], + "x-download-options": [ + "noopen" + ], + "strict-transport-security": [ + "max-age\u003d31536000; includeSubDomains; preload" + ], + "pragma": [ + "no-cache" + ], + "x-content-type-options": [ + "nosniff" + ], + "x-xss-protection": [ + "1; mode\u003dblock" + ], + "x-ep-request-uuid": [ + "7e94397e668d7c41e7885d8400539b4e" + ], + "x-proxied": [ + "extlb2nuq fa152d4755", + "intlb3nuq fa152d4755" + ], + "referrer-policy": [ + "strict-origin-when-cross-origin" + ], + "x-runtime": [ + "0.061695" + ], + "content-type": [ + "application/json; charset\u003dutf-8" + ], + "x-version-label": [ + "easypost-202407091438-d7c6f02f06-master" + ], + "cache-control": [ + "private, no-cache, no-store" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "uri": "https://api.easypost.com/v2/carrier_accounts/ca_7f975bbec5e44551a6da1db4c2b340b9" + }, + "duration": 510 + } +] \ No newline at end of file diff --git a/src/test/cassettes/carrier_account/update_ups.json b/src/test/cassettes/carrier_account/update_ups.json new file mode 100644 index 000000000..7f42d7b73 --- /dev/null +++ b/src/test/cassettes/carrier_account/update_ups.json @@ -0,0 +1,355 @@ +[ + { + "recordedAt": 1720548411, + "request": { + "body": "{\n \"ups_oauth_registrations\": {\n \"account_number\": \"123456789\",\n \"type\": \"UpsAccount\"\n }\n}", + "method": "POST", + "headers": { + "Accept-Charset": [ + "UTF-8" + ], + "User-Agent": [ + "REDACTED" + ], + "Content-Type": [ + "application/json" + ] + }, + "uri": "https://api.easypost.com/v2/ups_oauth_registrations" + }, + "response": { + "body": "{\n \"readable\": \"UPS\",\n \"credentials\": {},\n \"created_at\": \"2024-07-09T18:06:51Z\",\n \"description\": null,\n \"type\": \"UpsAccount\",\n \"reference\": null,\n \"updated_at\": \"2024-07-09T18:06:51Z\",\n \"clone\": false,\n \"billing_type\": \"carrier\",\n \"logo\": null,\n \"id\": \"ca_4f4583643b204278b55a5e89acd37e17\",\n \"fields\": {\n \"credentials\": {}\n },\n \"object\": \"CarrierAccount\"\n}", + "httpVersion": null, + "headers": { + "null": [ + "HTTP/1.1 201 Created" + ], + "content-length": [ + "1380" + ], + "expires": [ + "0" + ], + "x-node": [ + "bigweb43nuq" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-backend": [ + "easypost" + ], + "x-permitted-cross-domain-policies": [ + "none" + ], + "x-download-options": [ + "noopen" + ], + "strict-transport-security": [ + "max-age\u003d31536000; includeSubDomains; preload" + ], + "pragma": [ + "no-cache" + ], + "x-canary": [ + "direct" + ], + "x-content-type-options": [ + "nosniff" + ], + "x-xss-protection": [ + "1; mode\u003dblock" + ], + "x-ep-request-uuid": [ + "7e94397d668d7c3be7885d61005394d9" + ], + "x-proxied": [ + "extlb2nuq fa152d4755", + "intlb4nuq fa152d4755" + ], + "referrer-policy": [ + "strict-origin-when-cross-origin" + ], + "x-runtime": [ + "0.096919" + ], + "content-type": [ + "application/json; charset\u003dutf-8" + ], + "x-version-label": [ + "easypost-202407091801-d7c6f02f06-master" + ], + "cache-control": [ + "private, no-cache, no-store" + ] + }, + "status": { + "code": 201, + "message": "Created" + }, + "uri": "https://api.easypost.com/v2/ups_oauth_registrations" + }, + "duration": 557 + }, + { + "recordedAt": 1720548413, + "request": { + "body": "", + "method": "GET", + "headers": { + "Accept-Charset": [ + "UTF-8" + ], + "User-Agent": [ + "REDACTED" + ] + }, + "uri": "https://api.easypost.com/v2/carrier_accounts/ca_4f4583643b204278b55a5e89acd37e17" + }, + "response": { + "body": "{\n \"readable\": \"UPS\",\n \"credentials\": {},\n \"created_at\": \"2024-07-09T18:06:51Z\",\n \"description\": null,\n \"type\": \"UpsAccount\",\n \"reference\": null,\n \"updated_at\": \"2024-07-09T18:06:52Z\",\n \"clone\": false,\n \"billing_type\": \"carrier\",\n \"logo\": null,\n \"id\": \"ca_4f4583643b204278b55a5e89acd37e17\",\n \"fields\": {\n \"credentials\": {}\n },\n \"object\": \"CarrierAccount\"\n}", + "httpVersion": null, + "headers": { + "null": [ + "HTTP/1.1 200 OK" + ], + "content-length": [ + "1392" + ], + "expires": [ + "0" + ], + "x-node": [ + "bigweb53nuq" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-backend": [ + "easypost" + ], + "x-permitted-cross-domain-policies": [ + "none" + ], + "x-download-options": [ + "noopen" + ], + "strict-transport-security": [ + "max-age\u003d31536000; includeSubDomains; preload" + ], + "pragma": [ + "no-cache" + ], + "x-content-type-options": [ + "nosniff" + ], + "x-xss-protection": [ + "1; mode\u003dblock" + ], + "x-ep-request-uuid": [ + "7e943982668d7c3de7885d650053973b" + ], + "x-proxied": [ + "extlb2nuq fa152d4755", + "intlb3nuq fa152d4755" + ], + "referrer-policy": [ + "strict-origin-when-cross-origin" + ], + "x-runtime": [ + "0.042189" + ], + "content-type": [ + "application/json; charset\u003dutf-8" + ], + "x-version-label": [ + "easypost-202407091438-d7c6f02f06-master" + ], + "cache-control": [ + "private, no-cache, no-store" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "uri": "https://api.easypost.com/v2/carrier_accounts/ca_4f4583643b204278b55a5e89acd37e17" + }, + "duration": 483 + }, + { + "recordedAt": 1720548413, + "request": { + "body": "{\n \"ups_oauth_registrations\": {\n \"account_number\": \"987654321\"\n }\n}", + "method": "PUT", + "headers": { + "Accept-Charset": [ + "UTF-8" + ], + "User-Agent": [ + "REDACTED" + ], + "Content-Type": [ + "application/json" + ] + }, + "uri": "https://api.easypost.com/v2/ups_oauth_registrations/ca_4f4583643b204278b55a5e89acd37e17" + }, + "response": { + "body": "{\n \"readable\": \"UPS\",\n \"credentials\": {},\n \"created_at\": \"2024-07-09T18:06:51Z\",\n \"description\": null,\n \"type\": \"UpsAccount\",\n \"reference\": null,\n \"updated_at\": \"2024-07-09T18:06:52Z\",\n \"clone\": false,\n \"billing_type\": \"carrier\",\n \"logo\": null,\n \"id\": \"ca_4f4583643b204278b55a5e89acd37e17\",\n \"fields\": {\n \"credentials\": {}\n },\n \"object\": \"CarrierAccount\"\n}", + "httpVersion": null, + "headers": { + "null": [ + "HTTP/1.1 200 OK" + ], + "content-length": [ + "1392" + ], + "expires": [ + "0" + ], + "x-node": [ + "bigweb33nuq" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-backend": [ + "easypost" + ], + "x-permitted-cross-domain-policies": [ + "none" + ], + "x-download-options": [ + "noopen" + ], + "strict-transport-security": [ + "max-age\u003d31536000; includeSubDomains; preload" + ], + "pragma": [ + "no-cache" + ], + "x-content-type-options": [ + "nosniff" + ], + "x-xss-protection": [ + "1; mode\u003dblock" + ], + "x-ep-request-uuid": [ + "7e94397f668d7c3ce7885d64005396a0" + ], + "x-proxied": [ + "extlb2nuq fa152d4755", + "intlb4nuq fa152d4755" + ], + "referrer-policy": [ + "strict-origin-when-cross-origin" + ], + "x-runtime": [ + "0.071739" + ], + "content-type": [ + "application/json; charset\u003dutf-8" + ], + "x-version-label": [ + "easypost-202407091438-d7c6f02f06-master" + ], + "cache-control": [ + "private, no-cache, no-store" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "uri": "https://api.easypost.com/v2/ups_oauth_registrations/ca_4f4583643b204278b55a5e89acd37e17" + }, + "duration": 517 + }, + { + "recordedAt": 1720548414, + "request": { + "body": "", + "method": "DELETE", + "headers": { + "Accept-Charset": [ + "UTF-8" + ], + "User-Agent": [ + "REDACTED" + ] + }, + "uri": "https://api.easypost.com/v2/carrier_accounts/ca_4f4583643b204278b55a5e89acd37e17" + }, + "response": { + "body": "{}", + "httpVersion": null, + "headers": { + "null": [ + "HTTP/1.1 200 OK" + ], + "content-length": [ + "2" + ], + "expires": [ + "0" + ], + "x-node": [ + "bigweb39nuq" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-backend": [ + "easypost" + ], + "x-permitted-cross-domain-policies": [ + "none" + ], + "x-download-options": [ + "noopen" + ], + "strict-transport-security": [ + "max-age\u003d31536000; includeSubDomains; preload" + ], + "pragma": [ + "no-cache" + ], + "x-content-type-options": [ + "nosniff" + ], + "x-xss-protection": [ + "1; mode\u003dblock" + ], + "x-ep-request-uuid": [ + "7e943984668d7c3ee7885d66005397fe" + ], + "x-proxied": [ + "extlb2nuq fa152d4755", + "intlb4nuq fa152d4755" + ], + "referrer-policy": [ + "strict-origin-when-cross-origin" + ], + "x-runtime": [ + "0.081053" + ], + "content-type": [ + "application/json; charset\u003dutf-8" + ], + "x-version-label": [ + "easypost-202407091438-d7c6f02f06-master" + ], + "cache-control": [ + "private, no-cache, no-store" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "uri": "https://api.easypost.com/v2/carrier_accounts/ca_4f4583643b204278b55a5e89acd37e17" + }, + "duration": 516 + } +] \ No newline at end of file diff --git a/src/test/java/com/easypost/CarrierAccountTest.java b/src/test/java/com/easypost/CarrierAccountTest.java index 0afc53bef..700524459 100644 --- a/src/test/java/com/easypost/CarrierAccountTest.java +++ b/src/test/java/com/easypost/CarrierAccountTest.java @@ -30,6 +30,23 @@ public final class CarrierAccountTest { private static MockedStatic requestMock = Mockito.mockStatic(Requestor.class); + private static CarrierAccount createBasicCarrierAccount() throws EasyPostException { + // This method creates DhlEcsAccount carrier account. + CarrierAccount carrierAccount = vcr.client.carrierAccount.create(Fixtures.basicCarrierAccount()); + testCarrierAccountId = carrierAccount.getId(); // trigger deletion after test + return carrierAccount; + } + + private static CarrierAccount createUpsCarrierAccount() throws EasyPostException { + Map data = new HashMap<>(); + data.put("type", "UpsAccount"); + data.put("account_number", "123456789"); + + CarrierAccount upsAccount = vcr.client.carrierAccount.create(data); + testCarrierAccountId = upsAccount.getId(); // trigger deletion after test + return upsAccount; + } + /** * Set up the testing environment for this file. * @@ -97,10 +114,25 @@ public void testCreateWithCustomWorkflow() throws EasyPostException { } } - private static CarrierAccount createBasicCarrierAccount() throws EasyPostException { - CarrierAccount carrierAccount = vcr.client.carrierAccount.create(Fixtures.basicCarrierAccount()); - testCarrierAccountId = carrierAccount.getId(); // trigger deletion after test - return carrierAccount; + + /** + * Test creating a carrier account with a custom workflow. + * + * @throws EasyPostException when the request fails. + */ + @Test + public void testCreateWithUPS() throws EasyPostException { + vcr.setUpTest("create_with_ups"); + + Map data = new HashMap<>(); + data.put("type", "UpsAccount"); + data.put("account_number", "123456789"); + + CarrierAccount upsAccount = createUpsCarrierAccount(); + + assertInstanceOf(CarrierAccount.class, upsAccount); + assertTrue(upsAccount.getId().startsWith("ca_")); + assertEquals("UpsAccount", upsAccount.getType()); } /** @@ -158,6 +190,26 @@ public void testUpdate() throws EasyPostException { assertEquals(testDescription, updatedCarrierAccount.getDescription()); } + /** + * Test updating an UPS account. + * + * @throws EasyPostException when the request fails. + */ + @Test + public void testUpdateUpsAccount() throws EasyPostException { + vcr.setUpTest("update_ups"); + + CarrierAccount upsAccount = createUpsCarrierAccount(); + Map updateParams = new HashMap<>(); + updateParams.put("account_number", "987654321"); + + CarrierAccount updatedUpsAccount = vcr.client.carrierAccount.update(upsAccount.getId(), updateParams); + + assertInstanceOf(CarrierAccount.class, updatedUpsAccount); + assertTrue(updatedUpsAccount.getId().startsWith("ca_")); + assertEquals("UpsAccount", updatedUpsAccount.getType()); + } + /** * Test deleting a carrier account. *