From 835e258c233ecf022d26d840ea2e31e076584129 Mon Sep 17 00:00:00 2001 From: Arvind Krishnakumar <61501885+arvindkrishnakumar-okta@users.noreply.github.com> Date: Wed, 10 Jun 2020 08:05:00 -0700 Subject: [PATCH] OKTA-289662: Add SMS Templates API Integration Tests (#395) --- .../okta/sdk/tests/it/ApplicationsIT.groovy | 2 +- .../okta/sdk/tests/it/SmsTemplateIT.groovy | 98 +++++++++++++++++++ 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 integration-tests/src/test/groovy/com/okta/sdk/tests/it/SmsTemplateIT.groovy diff --git a/integration-tests/src/test/groovy/com/okta/sdk/tests/it/ApplicationsIT.groovy b/integration-tests/src/test/groovy/com/okta/sdk/tests/it/ApplicationsIT.groovy index 5d09ba3f5f7..a3296186922 100644 --- a/integration-tests/src/test/groovy/com/okta/sdk/tests/it/ApplicationsIT.groovy +++ b/integration-tests/src/test/groovy/com/okta/sdk/tests/it/ApplicationsIT.groovy @@ -490,7 +490,7 @@ class ApplicationsIT extends ITSupport { // issue: listApplicationUsers() occasionally throws HTTP 404, Okta E0000007 - Resource not found error. // adding a sleep after createApplication() helps resolve the above issue. sleep(2000) - + AppUserList appUserList = app.listApplicationUsers() assertThat appUserList.iterator().size(), equalTo(0) diff --git a/integration-tests/src/test/groovy/com/okta/sdk/tests/it/SmsTemplateIT.groovy b/integration-tests/src/test/groovy/com/okta/sdk/tests/it/SmsTemplateIT.groovy new file mode 100644 index 00000000000..e653da49bbe --- /dev/null +++ b/integration-tests/src/test/groovy/com/okta/sdk/tests/it/SmsTemplateIT.groovy @@ -0,0 +1,98 @@ +/* + * Copyright 2020-Present Okta, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.okta.sdk.tests.it + +import com.okta.sdk.resource.SmsTemplateTranslations +import com.okta.sdk.resource.template.SmsTemplate +import com.okta.sdk.resource.template.SmsTemplateType +import com.okta.sdk.tests.it.util.ITSupport +import org.testng.annotations.Test + +import static com.okta.sdk.tests.it.util.Util.assertPresent +import static com.okta.sdk.tests.it.util.Util.assertNotPresent +import static org.hamcrest.MatcherAssert.assertThat +import static org.hamcrest.Matchers.* + +/** + * Tests for /api/v1/templates/sms + * @since 2.0.0 + */ +class SmsTemplateIT extends ITSupport { + + @Test + void customTemplatesCrudTest() { + def templateName = "template-" + UUID.randomUUID().toString() + + // create translations + SmsTemplateTranslations smsTemplateTranslations = client.instantiate(SmsTemplateTranslations) + smsTemplateTranslations.put("de", "\${org.name}: ihre bestätigungscode ist \${code}") + smsTemplateTranslations.put("it", "\${org.name}: il codice di verifica è \${code}") + + // create template + SmsTemplate smsTemplate = client.createSmsTemplate(client.instantiate(SmsTemplate) + .setName(templateName) + .setType(SmsTemplateType.CODE) + .setTemplate("\${org.name}: your verification code is \${code}") + .setTranslations(smsTemplateTranslations)) + registerForCleanup(smsTemplate) + + assertThat(smsTemplate.getId(), notNullValue()) + + // list templates + assertPresent(client.listSmsTemplates(), smsTemplate) + + // retrieve template + SmsTemplate retrievedSmsTemplate = client.getSmsTemplate(smsTemplate.getId()) + assertThat(retrievedSmsTemplate, notNullValue()) + assertThat(retrievedSmsTemplate.getTranslations().keySet(), hasSize(2)) + + // partial update template with 1 empty translation + SmsTemplateTranslations partialUpdateTranslations = client.instantiate(SmsTemplateTranslations) + partialUpdateTranslations.put("de", "") // supplying empty value here so it gets removed by partial update operation (by design) + + smsTemplate.setTranslations(partialUpdateTranslations) + + smsTemplate.partialUpdate() + assertThat(smsTemplate.getTranslations().keySet(), hasSize(1)) + + // partial update again with 2 new translations + smsTemplate.getTranslations().put("es", "\${org.name}: su código de inscripción es \${code}") + smsTemplate.getTranslations().put("fr", "\${org.name}: votre code d'inscription est \${code}",) + + smsTemplate.partialUpdate() + assertThat(smsTemplate.getTranslations().keySet(), hasSize(3)) + + // full update template + SmsTemplateTranslations fullUpdateTranslations = client.instantiate(SmsTemplateTranslations) + fullUpdateTranslations.put("de", "\${org.name}: Hier ist Ihr Registrierungscode: \${code}") + + smsTemplate.setName("new-" + templateName) + smsTemplate.setType(SmsTemplateType.CODE) + smsTemplate.setTemplate("\${org.name}: Here is your enrollment code: \${code}") + smsTemplate.setTranslations(fullUpdateTranslations) + + smsTemplate.update() + assertThat(smsTemplate.getName(), is("new-" + templateName)) + assertThat(smsTemplate.getTranslations().keySet(), hasSize(1)) + + // list templates + assertPresent(client.listSmsTemplates(), smsTemplate) + + // delete template + smsTemplate.delete() + assertNotPresent(client.listSmsTemplates(), smsTemplate) + } +}