From 9206bf837582be4e2b21d73d695e78236295fc7e Mon Sep 17 00:00:00 2001 From: Martin Schelldorfer Date: Tue, 21 Nov 2023 11:28:51 +0100 Subject: [PATCH] add fields platfrom_type and throughput to PhoneNumber see https://developers.facebook.com/docs/whatsapp/business-platform/changelog/#september-12--2023 --- .../api/domain/phone/PhoneNumber.java | 34 ++- .../whatsapp/api/domain/phone/Throughput.java | 16 ++ .../api/domain/phone/type/LevelType.java | 38 +++ .../api/domain/phone/type/PlatformType.java | 38 +++ .../WhatsappBusinessManagementApiTest.java | 246 ++++++++++-------- src/test/resources/phone/phoneNumber.json | 4 + 6 files changed, 249 insertions(+), 127 deletions(-) create mode 100644 src/main/java/com/whatsapp/api/domain/phone/Throughput.java create mode 100644 src/main/java/com/whatsapp/api/domain/phone/type/LevelType.java create mode 100644 src/main/java/com/whatsapp/api/domain/phone/type/PlatformType.java diff --git a/src/main/java/com/whatsapp/api/domain/phone/PhoneNumber.java b/src/main/java/com/whatsapp/api/domain/phone/PhoneNumber.java index 74d3b131e..61708c3e2 100644 --- a/src/main/java/com/whatsapp/api/domain/phone/PhoneNumber.java +++ b/src/main/java/com/whatsapp/api/domain/phone/PhoneNumber.java @@ -4,24 +4,29 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.whatsapp.api.domain.phone.type.NameStatusType; +import com.whatsapp.api.domain.phone.type.PlatformType; import com.whatsapp.api.domain.phone.type.QualityRatingType; /** * The type Phone number. * - * @param id The ID associated with the phone number. - * @param displayPhoneNumber The string representation of the phone number. - * @param nameStatus The current status of the review of your business name. + * @param id The ID associated with the phone number. + * @param displayPhoneNumber The string representation of the phone number. + * @param nameStatus The current status of the review of your business name. * @param codeVerificationStatus Code Verification Status - * @param qualityRating The quality rating of the phone number based on how messages have been received by recipients in recent days. Valid values are: - * - * @param verifiedName the verified name + * @param qualityRating The quality rating of the phone number based on how messages have been received by recipients in recent days. Valid values are: + * + * @param verifiedName the verified name + * @param platformType Platform the business phone number is registered with. + * @param throughput The business phone number's Cloud API throughput level. * @see About WhatsApp Business Account Message Quality Rating + * @see WhatsApp Business Phone Number + * @see WhatsApp Business Platform - Changelog - September 12, 2023 */ @JsonInclude(value = Include.NON_NULL) public record PhoneNumber( @@ -36,5 +41,10 @@ public record PhoneNumber( @JsonProperty("code_verification_status") String codeVerificationStatus, - @JsonProperty("name_status") NameStatusType nameStatus) { + @JsonProperty("name_status") NameStatusType nameStatus, + + @JsonProperty("platform_type") PlatformType platformType, + + @JsonProperty("throughput") Throughput throughput) +{ } \ No newline at end of file diff --git a/src/main/java/com/whatsapp/api/domain/phone/Throughput.java b/src/main/java/com/whatsapp/api/domain/phone/Throughput.java new file mode 100644 index 000000000..167c2e5c5 --- /dev/null +++ b/src/main/java/com/whatsapp/api/domain/phone/Throughput.java @@ -0,0 +1,16 @@ +package com.whatsapp.api.domain.phone; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.whatsapp.api.domain.phone.type.LevelType; + +/** + * The type Throughput. + */ +@JsonInclude(value = Include.NON_NULL) +public record Throughput( + + @JsonProperty("level") LevelType Level) +{ +} \ No newline at end of file diff --git a/src/main/java/com/whatsapp/api/domain/phone/type/LevelType.java b/src/main/java/com/whatsapp/api/domain/phone/type/LevelType.java new file mode 100644 index 000000000..0993400a1 --- /dev/null +++ b/src/main/java/com/whatsapp/api/domain/phone/type/LevelType.java @@ -0,0 +1,38 @@ +package com.whatsapp.api.domain.phone.type; + +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * The enum Level type. + */ +public enum LevelType +{ + + /** + * Standard Level type. + */ + STANDARD("STANDARD"), + /** + * High Level type. + */ + HIGH("HIGH"), + NOT_APPLICABLE("NOT_APPLICABLE"); + + private final String value; + + LevelType(String value) + { + this.value = value; + } + + /** + * Gets value. + * + * @return the value + */ + @JsonValue + public String getValue() + { + return value; + } +} diff --git a/src/main/java/com/whatsapp/api/domain/phone/type/PlatformType.java b/src/main/java/com/whatsapp/api/domain/phone/type/PlatformType.java new file mode 100644 index 000000000..5e3856dad --- /dev/null +++ b/src/main/java/com/whatsapp/api/domain/phone/type/PlatformType.java @@ -0,0 +1,38 @@ +package com.whatsapp.api.domain.phone.type; + +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * The enum Platform type. + */ +public enum PlatformType +{ + + /** + * Cloud API Platform type. + */ + CLOUD_API("CLOUD_API"), + /** + * On-Premises API Platform type. + */ + ON_PREMISE("ON_PREMISE"), + NOT_APPLICABLE("NOT_APPLICABLE"); + + private final String value; + + PlatformType(String value) + { + this.value = value; + } + + /** + * Gets value. + * + * @return the value + */ + @JsonValue + public String getValue() + { + return value; + } +} diff --git a/src/test/java/com/whatsapp/api/impl/WhatsappBusinessManagementApiTest.java b/src/test/java/com/whatsapp/api/impl/WhatsappBusinessManagementApiTest.java index 5161834b5..2c93ab9ed 100644 --- a/src/test/java/com/whatsapp/api/impl/WhatsappBusinessManagementApiTest.java +++ b/src/test/java/com/whatsapp/api/impl/WhatsappBusinessManagementApiTest.java @@ -7,18 +7,8 @@ import com.whatsapp.api.domain.config.CommerceDataItem; import com.whatsapp.api.domain.phone.RequestCode; import com.whatsapp.api.domain.phone.VerifyCode; -import com.whatsapp.api.domain.phone.type.CodeMethodType; -import com.whatsapp.api.domain.phone.type.NameStatusType; -import com.whatsapp.api.domain.phone.type.QualityRatingType; -import com.whatsapp.api.domain.templates.BodyComponent; -import com.whatsapp.api.domain.templates.ButtonComponent; -import com.whatsapp.api.domain.templates.Example; -import com.whatsapp.api.domain.templates.FooterComponent; -import com.whatsapp.api.domain.templates.HeaderComponent; -import com.whatsapp.api.domain.templates.MessageTemplate; -import com.whatsapp.api.domain.templates.PhoneNumberButton; -import com.whatsapp.api.domain.templates.QuickReplyButton; -import com.whatsapp.api.domain.templates.UrlButton; +import com.whatsapp.api.domain.phone.type.*; +import com.whatsapp.api.domain.templates.*; import com.whatsapp.api.domain.templates.type.ButtonType; import com.whatsapp.api.domain.templates.type.Category; import com.whatsapp.api.domain.templates.type.HeaderFormat; @@ -39,7 +29,8 @@ import static com.whatsapp.api.configuration.WhatsappApiConfig.API_VERSION; -class WhatsappBusinessManagementApiTest extends MockServerUtilsTest { +class WhatsappBusinessManagementApiTest extends MockServerUtilsTest +{ public final String DEFAULT_TEMPLATE_RESPONSE = """ { @@ -56,7 +47,8 @@ class WhatsappBusinessManagementApiTest extends MockServerUtilsTest { * Method under test: {@link WhatsappBusinessManagementApi#createMessageTemplate(String, MessageTemplate)} */ @Test - void testCreateMessageTemplate() throws InterruptedException, JSONException { + void testCreateMessageTemplate() throws InterruptedException, JSONException + { WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); @@ -96,13 +88,13 @@ void testCreateMessageTemplate() throws InterruptedException, JSONException { .setCategory(Category.UTILITY)// .setLanguage(LanguageType.EN_US)// .addComponent(new HeaderComponent()// - .setText("Wellcome title")// - .setFormat(HeaderFormat.TEXT))// + .setText("Wellcome title")// + .setFormat(HeaderFormat.TEXT))// .addComponent(new BodyComponent()// - .setText("Hello {{1}}, welcome to our {{2}} test. ")// - .setExample(new Example()// - .addBodyTextExamples("Mr. José", "s")// - )); + .setText("Hello {{1}}, welcome to our {{2}} test. ")// + .setExample(new Example()// + .addBodyTextExamples("Mr. José", "s")// + )); var response = whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template); @@ -122,7 +114,8 @@ void testCreateMessageTemplate() throws InterruptedException, JSONException { * Method under test: {@link WhatsappBusinessManagementApi#createMessageTemplate(String, MessageTemplate)} */ @Test - void testCreateMessageTemplate2() throws IOException, URISyntaxException, InterruptedException, JSONException { + void testCreateMessageTemplate2() throws IOException, URISyntaxException, InterruptedException, JSONException + { WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); @@ -137,13 +130,13 @@ void testCreateMessageTemplate2() throws IOException, URISyntaxException, Interr .setCategory(Category.TRANSACTIONAL)// .setLanguage(LanguageType.PT_BR)// .addComponent(new HeaderComponent()// - .setText("Código de confirmação")// - .setFormat(HeaderFormat.TEXT))// + .setText("Código de confirmação")// + .setFormat(HeaderFormat.TEXT))// .addComponent(new BodyComponent()// - .setText("Este é o seu código de confirmação: " + Formatter.bold("{{1}}."))// - .setExample(new Example()// - .addBodyTextExamples("1458425")// - ))// + .setText("Este é o seu código de confirmação: " + Formatter.bold("{{1}}."))// + .setExample(new Example()// + .addBodyTextExamples("1458425")// + ))// .addComponent(new FooterComponent().setText("Use este código para confirmar seu telefone.")); whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template); @@ -160,7 +153,8 @@ void testCreateMessageTemplate2() throws IOException, URISyntaxException, Interr * Method under test: {@link WhatsappBusinessManagementApi#createMessageTemplate(String, MessageTemplate)} */ @Test - void testCreateMessageTemplate3() throws IOException, URISyntaxException, InterruptedException, JSONException { + void testCreateMessageTemplate3() throws IOException, URISyntaxException, InterruptedException, JSONException + { WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); @@ -174,18 +168,19 @@ void testCreateMessageTemplate3() throws IOException, URISyntaxException, Interr .setCategory(Category.TRANSACTIONAL)// .setLanguage(LanguageType.PT_BR)// .addComponent(new HeaderComponent()// - .setText("Confirmação de Atendimento")// - .setFormat(HeaderFormat.TEXT))// + .setText("Confirmação de Atendimento")// + .setFormat(HeaderFormat.TEXT))// .addComponent(new BodyComponent()// - .setText("Olá " + Formatter.bold("{{1}}") + ", passando aqui para confirmar seu horário no dia " + Formatter.bold("{{2}}") + " as " + Formatter.bold("{{3}}h") + ".\nVocê confirma que comparecerá?")// - .setExample(new Example()// - .addBodyTextExamples("Maria", "04/11/2022", "13:30")// - ))// + .setText("Olá " + Formatter.bold("{{1}}") + ", passando aqui para confirmar seu horário no dia " + Formatter.bold("{{2}}") + " as " + Formatter.bold( + "{{3}}h") + ".\nVocê confirma que comparecerá?")// + .setExample(new Example()// + .addBodyTextExamples("Maria", "04/11/2022", "13:30")// + ))// .addComponent(new ButtonComponent()// - .addButton(new QuickReplyButton("SIM"))// - .addButton(new QuickReplyButton("NÃO"))// - .addButton(new QuickReplyButton("REMARCAR")// - ))// + .addButton(new QuickReplyButton("SIM"))// + .addButton(new QuickReplyButton("NÃO"))// + .addButton(new QuickReplyButton("REMARCAR")// + ))// .addComponent(new FooterComponent().setText("Utilize um dos botões abaixo para a confirmação")); var response = whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template); @@ -203,7 +198,8 @@ void testCreateMessageTemplate3() throws IOException, URISyntaxException, Interr * Method under test: {@link WhatsappBusinessManagementApi#createMessageTemplate(String, MessageTemplate)} */ @Test - void testCreateMessageTemplate4() throws IOException, URISyntaxException, InterruptedException, JSONException { + void testCreateMessageTemplate4() throws IOException, URISyntaxException, InterruptedException, JSONException + { WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); @@ -215,17 +211,18 @@ void testCreateMessageTemplate4() throws IOException, URISyntaxException, Interr .setCategory(Category.TRANSACTIONAL)// .setLanguage(LanguageType.PT_BR)// .addComponent(new HeaderComponent()// - .setText("Confirmação de Atendimento")// - .setFormat(HeaderFormat.TEXT))// + .setText("Confirmação de Atendimento")// + .setFormat(HeaderFormat.TEXT))// .addComponent(new BodyComponent()// - .setText("Olá " + Formatter.bold("{{1}}") + ", passando aqui para confirmar seu horário no dia " + Formatter.bold("{{2}}") + " as " + Formatter.bold("{{3}}h") + ".\nVocê confirma que comparecerá?")// - .setExample(new Example()// - .addBodyTextExamples("Maria", "04/11/2022", "13:30")// - ))// + .setText("Olá " + Formatter.bold("{{1}}") + ", passando aqui para confirmar seu horário no dia " + Formatter.bold("{{2}}") + " as " + Formatter.bold( + "{{3}}h") + ".\nVocê confirma que comparecerá?")// + .setExample(new Example()// + .addBodyTextExamples("Maria", "04/11/2022", "13:30")// + ))// .addComponent(new FooterComponent().setText("Utilize um dos botões abaixo para a confirmação"))// .addComponent(new ButtonComponent()// - .addButton(new QuickReplyButton("SIM"))// - .addButton(new QuickReplyButton("NÃO"))// + .addButton(new QuickReplyButton("SIM"))// + .addButton(new QuickReplyButton("NÃO"))// ); whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template); @@ -238,12 +235,12 @@ void testCreateMessageTemplate4() throws IOException, URISyntaxException, Interr JSONAssert.assertEquals(expectedJson, request.getBody().readUtf8(), JSONCompareMode.STRICT); } - /** * Method under test: {@link WhatsappBusinessManagementApi#createMessageTemplate(String, MessageTemplate)} */ @Test - void testCreateMessageTemplateUtility1() throws IOException, URISyntaxException, InterruptedException, JSONException { + void testCreateMessageTemplateUtility1() throws IOException, URISyntaxException, InterruptedException, JSONException + { WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); @@ -255,18 +252,19 @@ void testCreateMessageTemplateUtility1() throws IOException, URISyntaxException, .setCategory(Category.UTILITY)// .setLanguage(LanguageType.PT_BR)// .addComponent(new HeaderComponent()// - .setFormat(HeaderFormat.DOCUMENT).setExample(new Example().addHeaderHandleExamples("4::aW1hZ2UvanBlZw==:ARb0a9E9s7-LdErXAXQCwyh7Oy-_h9gBo4ljPynnXo53CKOyyhHYUjCCREvS4fB-0CwfSQbNn9fJC3ikLOJve1CfQO-9aeWYdMmkMUJgGJI0g:e:1680011044:3449853982404722:100007529143136:ARZMcC4QfmCW8V85Lco")))// + .setFormat(HeaderFormat.DOCUMENT).setExample(new Example().addHeaderHandleExamples( + "4::aW1hZ2UvanBlZw==:ARb0a9E9s7-LdErXAXQCwyh7Oy-_h9gBo4ljPynnXo53CKOyyhHYUjCCREvS4fB-0CwfSQbNn9fJC3ikLOJve1CfQO-9aeWYdMmkMUJgGJI0g:e:1680011044:3449853982404722:100007529143136:ARZMcC4QfmCW8V85Lco")))// .addComponent(new BodyComponent()// - .setText("Olá {{1}}, seu professou publicou novas aulas na plataforma de ensino.")// - .setExample(new Example()// - .addBodyTextExamples("Maria")// - ))// + .setText("Olá {{1}}, seu professou publicou novas aulas na plataforma de ensino.")// + .setExample(new Example()// + .addBodyTextExamples("Maria")// + ))// .addComponent(new FooterComponent().setText("Click on the button below to watch now"))// .addComponent(new ButtonComponent()// - .addButton(new UrlButton("Assistir agora")// - .setUrl("https://www.coursera.org/{{1}}")// - .setUrlExample(Collections.singletonList("https://www.coursera.org/?authMode=login"))// - )); + .addButton(new UrlButton("Assistir agora")// + .setUrl("https://www.coursera.org/{{1}}")// + .setUrlExample(Collections.singletonList("https://www.coursera.org/?authMode=login"))// + )); whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template); @@ -282,7 +280,8 @@ void testCreateMessageTemplateUtility1() throws IOException, URISyntaxException, * Method under test: {@link WhatsappBusinessManagementApi#createMessageTemplate(String, MessageTemplate)} */ @Test - void testCreateMessageTemplateUtility2() throws IOException, URISyntaxException, InterruptedException, JSONException { + void testCreateMessageTemplateUtility2() throws IOException, URISyntaxException, InterruptedException, JSONException + { WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); @@ -294,14 +293,15 @@ void testCreateMessageTemplateUtility2() throws IOException, URISyntaxException, .setCategory(Category.UTILITY)// .setLanguage(LanguageType.PT_BR)// .addComponent(new HeaderComponent()// - .setText("Problemas com a entrega do seu pedido")// - .setFormat(HeaderFormat.TEXT))// + .setText("Problemas com a entrega do seu pedido")// + .setFormat(HeaderFormat.TEXT))// .addComponent(new BodyComponent()// - .setText("Olá {{1}}, Tivemos um problema com a entrega do seu pedido {{2}}. Por favor, entre em contato com a central de atendimento para obter mais detalhes")// - .setExample(new Example()// - .addBodyTextExamples("Maria", "FE-15454T45001")))// + .setText( + "Olá {{1}}, Tivemos um problema com a entrega do seu pedido {{2}}. Por favor, entre em contato com a central de atendimento para obter mais detalhes")// + .setExample(new Example()// + .addBodyTextExamples("Maria", "FE-15454T45001")))// .addComponent(new ButtonComponent()// - .addButton(new PhoneNumberButton("Ligar agora", "16503087300"))// + .addButton(new PhoneNumberButton("Ligar agora", "16503087300"))// )// .addComponent(new FooterComponent().setText("Clique no botão abaixo para ligar agora.")); @@ -319,7 +319,8 @@ void testCreateMessageTemplateUtility2() throws IOException, URISyntaxException, * Method under test: {@link WhatsappBusinessManagementApi#createMessageTemplate(String, MessageTemplate)} */ @Test - void testCreateMessageTemplateAuthentication() throws IOException, URISyntaxException, InterruptedException, JSONException { + void testCreateMessageTemplateAuthentication() throws IOException, URISyntaxException, InterruptedException, JSONException + { WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); @@ -331,15 +332,15 @@ void testCreateMessageTemplateAuthentication() throws IOException, URISyntaxExce .setCategory(Category.AUTHENTICATION)// .setLanguage(LanguageType.EN_US)// .addComponent(new HeaderComponent()// - .setFormat(HeaderFormat.TEXT).setText("Your authentication code for {{1}}")// - .setExample(new Example().addHeaderTextExamples("App X")))// + .setFormat(HeaderFormat.TEXT).setText("Your authentication code for {{1}}")// + .setExample(new Example().addHeaderTextExamples("App X")))// .addComponent(new BodyComponent()// - .setText("Please use the code {{1}} to sign in to your account. Do not provide this code to third parties.")// - .setExample(new Example()// - .addBodyTextExamples("784-H45-7R4")))// + .setText("Please use the code {{1}} to sign in to your account. Do not provide this code to third parties.")// + .setExample(new Example()// + .addBodyTextExamples("784-H45-7R4")))// .addComponent(new FooterComponent().setText("Did you not request the code? Click on 'Not me'"))// .addComponent(new ButtonComponent()// - .addButton(new QuickReplyButton("Not me"))// + .addButton(new QuickReplyButton("Not me"))// ); whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template); @@ -352,12 +353,12 @@ void testCreateMessageTemplateAuthentication() throws IOException, URISyntaxExce JSONAssert.assertEquals(expectedJson, request.getBody().readUtf8(), JSONCompareMode.STRICT); } - /** * Method under test: {@link WhatsappBusinessManagementApi#createMessageTemplate(String, MessageTemplate)} */ @Test - void testCreateMessageTemplateMarketing2() throws IOException, URISyntaxException, InterruptedException, JSONException { + void testCreateMessageTemplateMarketing2() throws IOException, URISyntaxException, InterruptedException, JSONException + { WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); @@ -369,21 +370,21 @@ void testCreateMessageTemplateMarketing2() throws IOException, URISyntaxExceptio .setCategory(Category.MARKETING)// .setLanguage(LanguageType.PT_BR)// .addComponent(new HeaderComponent()// - .setFormat(HeaderFormat.IMAGE).setExample(new Example().addHeaderHandleExamples("4::aW1hZ2UvanBlZw==:ARZdpGlLrA9uwIGGZc-UFu5viAD1BkqTCYGL8je2d7xovDZphaWG8gJPTSJfekNchsL3SWdY8-jTA9ZRq_MWro-1wfJnApfbb0ByrUoDb6nNZA:e:1679805732:3449824985304722:100002914375136:ARauotmqlFdTcNENzt0")))// + .setFormat(HeaderFormat.IMAGE).setExample(new Example().addHeaderHandleExamples( + "4::aW1hZ2UvanBlZw==:ARZdpGlLrA9uwIGGZc-UFu5viAD1BkqTCYGL8je2d7xovDZphaWG8gJPTSJfekNchsL3SWdY8-jTA9ZRq_MWro-1wfJnApfbb0ByrUoDb6nNZA:e:1679805732:3449824985304722:100002914375136:ARauotmqlFdTcNENzt0")))// .addComponent(new BodyComponent()// - .setText("Venha aproveitar nossos cafés especiais em nossa super promoção. Nossos expressos são a partir de R${{1}}")// - .setExample(new Example()// - .addBodyTextExamples("15")// - ))// + .setText("Venha aproveitar nossos cafés especiais em nossa super promoção. Nossos expressos são a partir de R${{1}}")// + .setExample(new Example()// + .addBodyTextExamples("15")// + ))// .addComponent(new ButtonComponent()// - .addButton(new QuickReplyButton("Saiba mais"))// - .addButton(new QuickReplyButton("Parar promoções")// - ))// + .addButton(new QuickReplyButton("Saiba mais"))// + .addButton(new QuickReplyButton("Parar promoções")// + ))// .addComponent(new FooterComponent().setText("Sem interesse? Clique em parar promoções")); - whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template); var request = mockWebServer.takeRequest(); @@ -398,7 +399,8 @@ void testCreateMessageTemplateMarketing2() throws IOException, URISyntaxExceptio * Method under test: {@link WhatsappBusinessManagementApi#updateMessageTemplate(String, String, MessageTemplate)} */ @Test - void testUpdateMessageTemplate() throws IOException, URISyntaxException { + void testUpdateMessageTemplate() throws IOException, URISyntaxException + { WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); @@ -411,25 +413,25 @@ void testUpdateMessageTemplate() throws IOException, URISyntaxException { .setCategory(Category.TRANSACTIONAL)// .setLanguage(LanguageType.EN_US)// .addComponent(new HeaderComponent()// - .setText("Wellcome title")// - .setFormat(HeaderFormat.TEXT))// + .setText("Wellcome title")// + .setFormat(HeaderFormat.TEXT))// .addComponent(new BodyComponent()// - .setText("Hello {{1}}, welcome to our {{2}} test. ")// - .setExample(new Example()// - .addBodyTextExamples("Mr. José", "satisfaction")// - )); + .setText("Hello {{1}}, welcome to our {{2}} test. ")// + .setExample(new Example()// + .addBodyTextExamples("Mr. José", "satisfaction")// + )); var response = whatsappBusinessCloudApi.updateMessageTemplate(WABA_ID, "952305634123456", template); Assertions.assertEquals("952305634123456", response.id()); } - /** * Method under test: {@link WhatsappBusinessManagementApi#deleteMessageTemplate(String, String)} */ @Test - void testDeleteMessageTemplate() throws IOException, URISyntaxException { + void testDeleteMessageTemplate() throws IOException, URISyntaxException + { WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); @@ -443,7 +445,8 @@ void testDeleteMessageTemplate() throws IOException, URISyntaxException { } @Test - void testRetrieveMessageTemplate1() throws IOException, URISyntaxException, JSONException { + void testRetrieveMessageTemplate1() throws IOException, URISyntaxException, JSONException + { WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); var expectedJson = fromResource("/retTemplate1.json"); @@ -467,11 +470,11 @@ void testRetrieveMessageTemplate1() throws IOException, URISyntaxException, JSON Assertions.assertEquals(ButtonType.QUICK_REPLY, buttonComponent.getButtons().get(0).getType()); - } @Test - void testRetrieveMessageTemplate2() throws IOException, URISyntaxException { + void testRetrieveMessageTemplate2() throws IOException, URISyntaxException + { WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); @@ -479,7 +482,6 @@ void testRetrieveMessageTemplate2() throws IOException, URISyntaxException { var templates = whatsappBusinessCloudApi.retrieveTemplates(WABA_ID, 2); - Assertions.assertEquals(2, templates.data().size()); Assertions.assertEquals("welcome_template3", templates.data().get(0).name()); Assertions.assertEquals("Hello {{1}}, welcome to our {{2}} test.", templates.data().get(0).components().get(1).getText()); @@ -488,7 +490,8 @@ void testRetrieveMessageTemplate2() throws IOException, URISyntaxException { } @Test - void testRetrieveMessageTemplate3() throws IOException, URISyntaxException { + void testRetrieveMessageTemplate3() throws IOException, URISyntaxException + { WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); @@ -496,7 +499,6 @@ void testRetrieveMessageTemplate3() throws IOException, URISyntaxException { var templates = whatsappBusinessCloudApi.retrieveTemplates(WABA_ID, "welcome_template3"); - Assertions.assertEquals(1, templates.data().size()); Assertions.assertEquals("welcome_template3", templates.data().get(0).name()); Assertions.assertEquals("Hello {{1}}, welcome to our {{2}} test.", templates.data().get(0).components().get(1).getText()); @@ -504,7 +506,8 @@ void testRetrieveMessageTemplate3() throws IOException, URISyntaxException { } @Test - void testRetrieveMessageTemplate3WithLimit() throws IOException, URISyntaxException { + void testRetrieveMessageTemplate3WithLimit() throws IOException, URISyntaxException + { WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); @@ -512,7 +515,6 @@ void testRetrieveMessageTemplate3WithLimit() throws IOException, URISyntaxExcept var templates = whatsappBusinessCloudApi.retrieveTemplates(WABA_ID, 1, "10"); - Assertions.assertEquals(1, templates.data().size()); Assertions.assertEquals("welcome_template3", templates.data().get(0).name()); Assertions.assertEquals("Hello {{1}}, welcome to our {{2}} test.", templates.data().get(0).components().get(1).getText()); @@ -520,7 +522,8 @@ void testRetrieveMessageTemplate3WithLimit() throws IOException, URISyntaxExcept } @Test - void testRetrievePhoneNumber() throws IOException, URISyntaxException, InterruptedException { + void testRetrievePhoneNumber() throws IOException, URISyntaxException, InterruptedException + { mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/phone/phoneNumber.json"))); WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); @@ -537,12 +540,15 @@ void testRetrievePhoneNumber() throws IOException, URISyntaxException, Interrupt Assertions.assertNull(phoneNumber.nameStatus()); Assertions.assertEquals(QualityRatingType.GREEN, phoneNumber.qualityRating()); Assertions.assertEquals("NOT_VERIFIED", phoneNumber.codeVerificationStatus()); + Assertions.assertEquals(PlatformType.CLOUD_API, phoneNumber.platformType()); + Assertions.assertEquals(LevelType.STANDARD, phoneNumber.throughput().Level()); Assertions.assertEquals("109219645287979", phoneNumber.id()); } @Test - void testRetrievePhoneNumberWithSpecificFields() throws IOException, URISyntaxException, InterruptedException { + void testRetrievePhoneNumberWithSpecificFields() throws IOException, URISyntaxException, InterruptedException + { mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/phone/phoneWithSpecificFields.json"))); WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); @@ -564,7 +570,8 @@ void testRetrievePhoneNumberWithSpecificFields() throws IOException, URISyntaxEx } @Test - void testRetrievePhoneNumbers() throws IOException, URISyntaxException, InterruptedException { + void testRetrievePhoneNumbers() throws IOException, URISyntaxException, InterruptedException + { mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/phone/phoneNumbersList.json"))); WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); @@ -593,7 +600,8 @@ void testRetrievePhoneNumbers() throws IOException, URISyntaxException, Interrup } @Test - void testRetrievePhoneNumberNotFoundError() throws IOException, URISyntaxException, InterruptedException { + void testRetrievePhoneNumberNotFoundError() throws IOException, URISyntaxException, InterruptedException + { mockWebServer.enqueue(new MockResponse().setResponseCode(400).setBody(fromResource("/phone/phoneNumberNotFoundError.json"))); WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); @@ -606,7 +614,9 @@ void testRetrievePhoneNumberNotFoundError() throws IOException, URISyntaxExcepti Assertions.assertEquals("GET", recordedRequest.getMethod()); Assertions.assertEquals("/" + API_VERSION + "/" + "454545", recordedRequest.getPath()); - Assertions.assertEquals("Unsupported get request. Object with ID '454545' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api", ex.getMessage()); + Assertions.assertEquals( + "Unsupported get request. Object with ID '454545' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api", + ex.getMessage()); } @@ -614,7 +624,8 @@ void testRetrievePhoneNumberNotFoundError() throws IOException, URISyntaxExcepti * Method under test: {@link WhatsappBusinessManagementApi#requestCode(String, RequestCode)}} */ @Test - void requestCode() throws IOException, URISyntaxException, InterruptedException { + void requestCode() throws IOException, URISyntaxException, InterruptedException + { mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/reponse.json"))); WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); @@ -636,7 +647,8 @@ void requestCode() throws IOException, URISyntaxException, InterruptedException * Method under test: {@link WhatsappBusinessManagementApi#requestCode(String, RequestCode)}} */ @Test - void requestCodeError() throws IOException, URISyntaxException, InterruptedException { + void requestCodeError() throws IOException, URISyntaxException, InterruptedException + { mockWebServer.enqueue(new MockResponse().setResponseCode(400).setBody(fromResource("/phone/requestCodeError.json"))); WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); @@ -658,7 +670,8 @@ void requestCodeError() throws IOException, URISyntaxException, InterruptedExcep * Method under test: {@link WhatsappBusinessManagementApi#verifyCode(String, VerifyCode)} */ @Test - void verifyCode() throws IOException, URISyntaxException, InterruptedException { + void verifyCode() throws IOException, URISyntaxException, InterruptedException + { mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/reponse.json"))); WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); @@ -680,7 +693,8 @@ void verifyCode() throws IOException, URISyntaxException, InterruptedException { * Method under test: {@link WhatsappBusinessManagementApi#verifyCode(String, VerifyCode)} */ @Test - void verifyCodeError() throws IOException, URISyntaxException, InterruptedException { + void verifyCodeError() throws IOException, URISyntaxException, InterruptedException + { mockWebServer.enqueue(new MockResponse().setResponseCode(400).setBody(fromResource("/phone/verifyCodeError.json"))); WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); @@ -702,10 +716,11 @@ void verifyCodeError() throws IOException, URISyntaxException, InterruptedExcept * Method under test: {@link WhatsappBusinessManagementApi#getWhatsappCommerceSettings(String, String...)} */ @Test - void getWhatsappCommerceSettings() throws IOException, URISyntaxException, InterruptedException { + void getWhatsappCommerceSettings() throws IOException, URISyntaxException, InterruptedException + { mockWebServer.enqueue(new MockResponse() - .setResponseCode(200) - .setBody(fromResource("/config/commerceSettings.json"))); + .setResponseCode(200) + .setBody(fromResource("/config/commerceSettings.json"))); WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); @@ -726,10 +741,11 @@ void getWhatsappCommerceSettings() throws IOException, URISyntaxException, Inter * Method under test: {@link WhatsappBusinessManagementApi#updateWhatsappCommerceSettings(String, CommerceDataItem)} */ @Test - void updateWhatsappCommerceSettings() throws IOException, URISyntaxException, InterruptedException { + void updateWhatsappCommerceSettings() throws IOException, URISyntaxException, InterruptedException + { mockWebServer.enqueue(new MockResponse() - .setResponseCode(200) - .setBody(fromResource("/reponse.json")) + .setResponseCode(200) + .setBody(fromResource("/reponse.json")) ); WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); diff --git a/src/test/resources/phone/phoneNumber.json b/src/test/resources/phone/phoneNumber.json index 8898b9a48..2754d2261 100644 --- a/src/test/resources/phone/phoneNumber.json +++ b/src/test/resources/phone/phoneNumber.json @@ -3,5 +3,9 @@ "code_verification_status": "NOT_VERIFIED", "display_phone_number": "11111111111", "quality_rating": "GREEN", + "platform_type": "CLOUD_API", + "throughput": { + "level": "STANDARD" + }, "id": "109219645287979" } \ No newline at end of file