diff --git a/examples b/examples index e7b0cad0c..036f84ca8 160000 --- a/examples +++ b/examples @@ -1 +1 @@ -Subproject commit e7b0cad0c8f5a8d66b4da7bd5b403b01c3a8a05c +Subproject commit 036f84ca892e1ca29bb56edc4574fa0e3095a4b4 diff --git a/src/test/cassettes/address/create_verify.json b/src/test/cassettes/address/create_verify.json index 1cf0b28f7..09da8d109 100644 --- a/src/test/cassettes/address/create_verify.json +++ b/src/test/cassettes/address/create_verify.json @@ -1,8 +1,8 @@ [ { - "recordedAt": 1703706101, + "recordedAt": 1704499801, "request": { - "body": "{\n \"address\": {\n \"zip\": \"94104\",\n \"country\": \"US\",\n \"city\": \"San Francisco\",\n \"phone\": \"REDACTED\",\n \"company\": \"EasyPost\",\n \"street1\": \"417 montgomery street\",\n \"street2\": \"FL 5\",\n \"state\": \"CA\",\n \"email\": \"test@example.com\"\n },\n \"verify\": true\n}", + "body": "{\n \"address\": {\n \"zip\": \"00001\",\n \"country\": \"US\",\n \"city\": \"Not A City\",\n \"phone\": \"REDACTED\",\n \"company\": \"EasyPost\",\n \"street1\": \"000 unknown street\",\n \"state\": \"ZZ\",\n \"email\": \"test@example.com\"\n }\n}", "method": "POST", "headers": { "Accept-Charset": [ @@ -18,20 +18,20 @@ "uri": "https://api.easypost.com/v2/addresses" }, "response": { - "body": "{\n \"zip\": \"94104-1129\",\n \"country\": \"US\",\n \"city\": \"SAN FRANCISCO\",\n \"created_at\": \"2023-12-27T19:41:41+00:00\",\n \"verifications\": {\n \"delivery\": {\n \"success\": true,\n \"details\": {\n \"latitude\": 37.79342,\n \"time_zone\": \"America/Los_Angeles\",\n \"longitude\": -122.40288\n },\n \"errors\": []\n },\n \"zip4\": {\n \"success\": true,\n \"details\": null,\n \"errors\": []\n }\n },\n \"mode\": \"test\",\n \"federal_tax_id\": null,\n \"state_tax_id\": null,\n \"carrier_facility\": null,\n \"residential\": false,\n \"updated_at\": \"2023-12-27T19:41:41+00:00\",\n \"phone\": \"REDACTED\",\n \"name\": null,\n \"company\": \"EASYPOST\",\n \"street1\": \"417 MONTGOMERY ST FL 5\",\n \"id\": \"adr_f50904daa4ef11eeb77e3cecef1b359e\",\n \"street2\": \"\",\n \"state\": \"CA\",\n \"email\": \"TEST@EXAMPLE.COM\",\n \"object\": \"Address\"\n}", + "body": "{\n \"zip\": \"00001\",\n \"country\": \"US\",\n \"city\": \"Not A City\",\n \"created_at\": \"2024-01-06T00:10:01+00:00\",\n \"verifications\": {},\n \"mode\": \"test\",\n \"federal_tax_id\": null,\n \"state_tax_id\": null,\n \"carrier_facility\": null,\n \"residential\": null,\n \"updated_at\": \"2024-01-06T00:10:01+00:00\",\n \"phone\": \"REDACTED\",\n \"name\": null,\n \"company\": \"EasyPost\",\n \"street1\": \"000 unknown street\",\n \"id\": \"adr_ef6bc01bac2711eeb057ac1f6bc539ae\",\n \"street2\": null,\n \"state\": \"ZZ\",\n \"email\": \"test@example.com\",\n \"object\": \"Address\"\n}", "httpVersion": null, "headers": { "null": [ "HTTP/1.1 201 Created" ], "content-length": [ - "643" + "453" ], "expires": [ "0" ], "x-node": [ - "bigweb31nuq" + "bigweb42nuq" ], "x-frame-options": [ "SAMEORIGIN" @@ -58,26 +58,26 @@ "nosniff" ], "x-ep-request-uuid": [ - "05b5dcb6658c7df4f020693a0012b9cb" + "dc2c57f265989a59f441c5b0003fa0e6" ], "x-proxied": [ - "intlb2nuq b3de2c47ef", + "intlb1nuq ab82b2e6e9", "extlb1nuq 003ad9bca0" ], "referrer-policy": [ "strict-origin-when-cross-origin" ], "x-runtime": [ - "0.058263" + "0.034633" ], "location": [ - "/api/v2/addresses/adr_f50904daa4ef11eeb77e3cecef1b359e" + "/api/v2/addresses/adr_ef6bc01bac2711eeb057ac1f6bc539ae" ], "content-type": [ "application/json; charset\u003dutf-8" ], "x-version-label": [ - "easypost-202312202038-ae3ff8e94e-master" + "easypost-202401051829-4cf193bd35-master" ], "cache-control": [ "private, no-cache, no-store" @@ -89,6 +89,98 @@ }, "uri": "https://api.easypost.com/v2/addresses" }, - "duration": 206 + "duration": 180 + }, + { + "recordedAt": 1704499801, + "request": { + "body": "{\n \"address\": {\n \"zip\": \"00001\",\n \"country\": \"US\",\n \"city\": \"Not A City\",\n \"phone\": \"REDACTED\",\n \"company\": \"EasyPost\",\n \"street1\": \"000 unknown street\",\n \"state\": \"ZZ\",\n \"email\": \"test@example.com\"\n },\n \"verify\": true\n}", + "method": "POST", + "headers": { + "Accept-Charset": [ + "UTF-8" + ], + "User-Agent": [ + "REDACTED" + ], + "Content-Type": [ + "application/json" + ] + }, + "uri": "https://api.easypost.com/v2/addresses" + }, + "response": { + "body": "{\n \"zip\": \"00001\",\n \"country\": \"US\",\n \"city\": \"Not A City\",\n \"created_at\": \"2024-01-06T00:10:01+00:00\",\n \"verifications\": {\n \"delivery\": {\n \"success\": false,\n \"details\": {},\n \"errors\": [\n {\n \"code\": \"E.ADDRESS.NOT_FOUND\",\n \"field\": \"address\",\n \"suggestion\": null,\n \"message\": \"Address not found\"\n }\n ]\n },\n \"zip4\": {\n \"success\": false,\n \"details\": null,\n \"errors\": [\n {\n \"code\": \"E.ADDRESS.NOT_FOUND\",\n \"field\": \"address\",\n \"suggestion\": null,\n \"message\": \"Address not found\"\n }\n ]\n }\n },\n \"mode\": \"test\",\n \"federal_tax_id\": null,\n \"state_tax_id\": null,\n \"carrier_facility\": null,\n \"residential\": null,\n \"updated_at\": \"2024-01-06T00:10:01+00:00\",\n \"phone\": \"REDACTED\",\n \"name\": null,\n \"company\": \"EasyPost\",\n \"street1\": \"000 unknown street\",\n \"id\": \"adr_efa64a91ac2711ee8e9dac1f6bc539aa\",\n \"street2\": null,\n \"state\": \"ZZ\",\n \"email\": \"test@example.com\",\n \"object\": \"Address\"\n}", + "httpVersion": null, + "headers": { + "null": [ + "HTTP/1.1 201 Created" + ], + "content-length": [ + "750" + ], + "expires": [ + "0" + ], + "x-node": [ + "bigweb42nuq" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-download-options": [ + "noopen" + ], + "x-permitted-cross-domain-policies": [ + "none" + ], + "x-backend": [ + "easypost" + ], + "pragma": [ + "no-cache" + ], + "strict-transport-security": [ + "max-age\u003d31536000; includeSubDomains; preload" + ], + "x-xss-protection": [ + "1; mode\u003dblock" + ], + "x-content-type-options": [ + "nosniff" + ], + "x-ep-request-uuid": [ + "dc2c57f265989a59f41a67ce003fa135" + ], + "x-proxied": [ + "intlb1nuq ab82b2e6e9", + "extlb1nuq 003ad9bca0" + ], + "referrer-policy": [ + "strict-origin-when-cross-origin" + ], + "x-runtime": [ + "0.048658" + ], + "location": [ + "/api/v2/addresses/adr_efa64a91ac2711ee8e9dac1f6bc539aa" + ], + "content-type": [ + "application/json; charset\u003dutf-8" + ], + "x-version-label": [ + "easypost-202401051829-4cf193bd35-master" + ], + "cache-control": [ + "private, no-cache, no-store" + ] + }, + "status": { + "code": 201, + "message": "Created" + }, + "uri": "https://api.easypost.com/v2/addresses" + }, + "duration": 183 } ] \ No newline at end of file diff --git a/src/test/cassettes/address/create_verify_array.json b/src/test/cassettes/address/create_verify_array.json index 95ef973e3..f7f6e4c3b 100644 --- a/src/test/cassettes/address/create_verify_array.json +++ b/src/test/cassettes/address/create_verify_array.json @@ -1,8 +1,8 @@ [ { - "recordedAt": 1703706103, + "recordedAt": 1704499962, "request": { - "body": "{\n \"address\": {\n \"zip\": \"94104\",\n \"country\": \"US\",\n \"city\": \"San Francisco\",\n \"phone\": \"REDACTED\",\n \"company\": \"EasyPost\",\n \"street1\": \"417 montgomery street\",\n \"street2\": \"FL 5\",\n \"state\": \"CA\",\n \"email\": \"test@example.com\"\n },\n \"verify\": [\n true\n ]\n}", + "body": "{\n \"address\": {\n \"zip\": \"00001\",\n \"country\": \"US\",\n \"city\": \"Not A City\",\n \"phone\": \"REDACTED\",\n \"company\": \"EasyPost\",\n \"street1\": \"000 unknown street\",\n \"state\": \"ZZ\",\n \"email\": \"test@example.com\"\n }\n}", "method": "POST", "headers": { "Accept-Charset": [ @@ -18,20 +18,20 @@ "uri": "https://api.easypost.com/v2/addresses" }, "response": { - "body": "{\n \"zip\": \"94104-1129\",\n \"country\": \"US\",\n \"city\": \"SAN FRANCISCO\",\n \"created_at\": \"2023-12-27T19:41:43+00:00\",\n \"verifications\": {\n \"delivery\": {\n \"success\": true,\n \"details\": {\n \"latitude\": 37.79342,\n \"time_zone\": \"America/Los_Angeles\",\n \"longitude\": -122.40288\n },\n \"errors\": []\n },\n \"zip4\": {\n \"success\": true,\n \"details\": null,\n \"errors\": []\n }\n },\n \"mode\": \"test\",\n \"federal_tax_id\": null,\n \"state_tax_id\": null,\n \"carrier_facility\": null,\n \"residential\": false,\n \"updated_at\": \"2023-12-27T19:41:43+00:00\",\n \"phone\": \"REDACTED\",\n \"name\": null,\n \"company\": \"EASYPOST\",\n \"street1\": \"417 MONTGOMERY ST FL 5\",\n \"id\": \"adr_f66fb331a4ef11eea653ac1f6bc539aa\",\n \"street2\": \"\",\n \"state\": \"CA\",\n \"email\": \"TEST@EXAMPLE.COM\",\n \"object\": \"Address\"\n}", + "body": "{\n \"zip\": \"00001\",\n \"country\": \"US\",\n \"city\": \"Not A City\",\n \"created_at\": \"2024-01-06T00:12:42+00:00\",\n \"verifications\": {},\n \"mode\": \"test\",\n \"federal_tax_id\": null,\n \"state_tax_id\": null,\n \"carrier_facility\": null,\n \"residential\": null,\n \"updated_at\": \"2024-01-06T00:12:42+00:00\",\n \"phone\": \"REDACTED\",\n \"name\": null,\n \"company\": \"EasyPost\",\n \"street1\": \"000 unknown street\",\n \"id\": \"adr_4f493571ac2811eeaad6ac1f6bc539aa\",\n \"street2\": null,\n \"state\": \"ZZ\",\n \"email\": \"test@example.com\",\n \"object\": \"Address\"\n}", "httpVersion": null, "headers": { "null": [ "HTTP/1.1 201 Created" ], "content-length": [ - "643" + "453" ], "expires": [ "0" ], "x-node": [ - "bigweb43nuq" + "bigweb36nuq" ], "x-frame-options": [ "SAMEORIGIN" @@ -51,8 +51,97 @@ "strict-transport-security": [ "max-age\u003d31536000; includeSubDomains; preload" ], - "x-canary": [ - "direct" + "x-xss-protection": [ + "1; mode\u003dblock" + ], + "x-content-type-options": [ + "nosniff" + ], + "x-ep-request-uuid": [ + "dc2c57ee65989afaf3f5ae64004015b7" + ], + "x-proxied": [ + "intlb2nuq ab82b2e6e9", + "extlb1nuq 003ad9bca0" + ], + "referrer-policy": [ + "strict-origin-when-cross-origin" + ], + "x-runtime": [ + "0.034801" + ], + "location": [ + "/api/v2/addresses/adr_4f493571ac2811eeaad6ac1f6bc539aa" + ], + "content-type": [ + "application/json; charset\u003dutf-8" + ], + "x-version-label": [ + "easypost-202401051829-4cf193bd35-master" + ], + "cache-control": [ + "private, no-cache, no-store" + ] + }, + "status": { + "code": 201, + "message": "Created" + }, + "uri": "https://api.easypost.com/v2/addresses" + }, + "duration": 170 + }, + { + "recordedAt": 1704499962, + "request": { + "body": "{\n \"address\": {\n \"zip\": \"00001\",\n \"country\": \"US\",\n \"city\": \"Not A City\",\n \"phone\": \"REDACTED\",\n \"company\": \"EasyPost\",\n \"street1\": \"000 unknown street\",\n \"state\": \"ZZ\",\n \"email\": \"test@example.com\"\n },\n \"verify\": [\n true\n ]\n}", + "method": "POST", + "headers": { + "Accept-Charset": [ + "UTF-8" + ], + "User-Agent": [ + "REDACTED" + ], + "Content-Type": [ + "application/json" + ] + }, + "uri": "https://api.easypost.com/v2/addresses" + }, + "response": { + "body": "{\n \"zip\": \"00001\",\n \"country\": \"US\",\n \"city\": \"Not A City\",\n \"created_at\": \"2024-01-06T00:12:42+00:00\",\n \"verifications\": {\n \"delivery\": {\n \"success\": false,\n \"details\": {},\n \"errors\": [\n {\n \"code\": \"E.ADDRESS.NOT_FOUND\",\n \"field\": \"address\",\n \"suggestion\": null,\n \"message\": \"Address not found\"\n }\n ]\n },\n \"zip4\": {\n \"success\": false,\n \"details\": null,\n \"errors\": [\n {\n \"code\": \"E.ADDRESS.NOT_FOUND\",\n \"field\": \"address\",\n \"suggestion\": null,\n \"message\": \"Address not found\"\n }\n ]\n }\n },\n \"mode\": \"test\",\n \"federal_tax_id\": null,\n \"state_tax_id\": null,\n \"carrier_facility\": null,\n \"residential\": null,\n \"updated_at\": \"2024-01-06T00:12:42+00:00\",\n \"phone\": \"REDACTED\",\n \"name\": null,\n \"company\": \"EasyPost\",\n \"street1\": \"000 unknown street\",\n \"id\": \"adr_4f7b425cac2811eeb51e3cecef1b359e\",\n \"street2\": null,\n \"state\": \"ZZ\",\n \"email\": \"test@example.com\",\n \"object\": \"Address\"\n}", + "httpVersion": null, + "headers": { + "null": [ + "HTTP/1.1 201 Created" + ], + "content-length": [ + "750" + ], + "expires": [ + "0" + ], + "x-node": [ + "bigweb33nuq" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-download-options": [ + "noopen" + ], + "x-permitted-cross-domain-policies": [ + "none" + ], + "x-backend": [ + "easypost" + ], + "pragma": [ + "no-cache" + ], + "strict-transport-security": [ + "max-age\u003d31536000; includeSubDomains; preload" ], "x-xss-protection": [ "1; mode\u003dblock" @@ -61,26 +150,26 @@ "nosniff" ], "x-ep-request-uuid": [ - "05b5dcb5658c7df7f41d25110012bb9e" + "dc2c57f365989afaf419c203004015f7" ], "x-proxied": [ - "intlb2nuq b3de2c47ef", + "intlb2nuq ab82b2e6e9", "extlb1nuq 003ad9bca0" ], "referrer-policy": [ "strict-origin-when-cross-origin" ], "x-runtime": [ - "0.055396" + "0.043753" ], "location": [ - "/api/v2/addresses/adr_f66fb331a4ef11eea653ac1f6bc539aa" + "/api/v2/addresses/adr_4f7b425cac2811eeb51e3cecef1b359e" ], "content-type": [ "application/json; charset\u003dutf-8" ], "x-version-label": [ - "easypost-202312202038-ae3ff8e94e-master" + "easypost-202401051829-4cf193bd35-master" ], "cache-control": [ "private, no-cache, no-store" @@ -92,6 +181,6 @@ }, "uri": "https://api.easypost.com/v2/addresses" }, - "duration": 193 + "duration": 170 } ] \ No newline at end of file diff --git a/src/test/java/com/easypost/AddressTest.java b/src/test/java/com/easypost/AddressTest.java index 62c7635a5..b68a1f601 100644 --- a/src/test/java/com/easypost/AddressTest.java +++ b/src/test/java/com/easypost/AddressTest.java @@ -19,6 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -75,23 +76,22 @@ public void testCreateVerify() throws EasyPostException { vcr.setUpTest("create_verify"); Map addressData = Fixtures.incorrectAddress(); - addressData.put("verify", true); + // Creating normally (without specifying "verify") will make the address, perform no verifications Address address = vcr.client.address.create(addressData); assertInstanceOf(Address.class, address); - assertTrue(address.getId().startsWith("adr_")); - assertEquals("417 MONTGOMERY ST FL 5", address.getStreet1()); - - assertNotNull(address.getVerifications()); + assertNull(address.getVerifications().getDelivery()); + assertNull(address.getVerifications().getZip4()); - assertFalse(address.getVerifications().getDelivery().getErrors().isEmpty()); // should have at least one error - Error error = address.getVerifications().getDelivery().getErrors().get(0); - assertEquals("E.SECONDARY_INFORMATION.INVALID", error.getCode()); + // Creating with verify would make the address and perform verifications + // internally, we're just checking for the presence of "verify" in the dictionary, so the value doesn't matter + addressData.put("verify", true); + address = vcr.client.address.create(addressData); - assertFalse(address.getVerifications().getZip4().getErrors().isEmpty()); // should have at least one error - error = address.getVerifications().getZip4().getErrors().get(0); - assertEquals("E.SECONDARY_INFORMATION.INVALID", error.getCode()); + assertInstanceOf(Address.class, address); + assertNotNull(address.getVerifications().getDelivery()); + assertNotNull(address.getVerifications().getZip4()); } /** @@ -125,15 +125,25 @@ public void testCreateVerifyArray() throws EasyPostException { vcr.setUpTest("create_verify_array"); Map addressData = Fixtures.incorrectAddress(); + + // Creating normally (without specifying "verify") will make the address, perform no verifications + Address address = vcr.client.address.create(addressData); + + assertInstanceOf(Address.class, address); + assertNull(address.getVerifications().getDelivery()); + assertNull(address.getVerifications().getZip4()); + + // Creating with verify would make the address and perform verifications + // internally, we're just checking for the presence of "verify" in the dictionary, so the value doesn't matter List verificationList = new ArrayList<>(); verificationList.add(true); addressData.put("verify", verificationList); - Address address = vcr.client.address.create(addressData); + address = vcr.client.address.create(addressData); assertInstanceOf(Address.class, address); - assertTrue(address.getId().startsWith("adr_")); - assertEquals("417 MONTGOMERY ST FL 5", address.getStreet1()); + assertNotNull(address.getVerifications().getDelivery()); + assertNotNull(address.getVerifications().getZip4()); } /**