diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index ba2161ee98..401d942da7 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -50,6 +50,9 @@ jobs: TWILIO_API_SECRET: ${{ secrets.TWILIO_CLUSTER_TEST_API_KEY_SECRET }} TWILIO_FROM_NUMBER: ${{ secrets.TWILIO_FROM_NUMBER }} TWILIO_TO_NUMBER: ${{ secrets.TWILIO_TO_NUMBER }} + TWILIO_ORGS_CLIENT_ID: ${{ secrets.TWILIO_ORGS_CLIENT_ID }} + TWILIO_ORGS_CLIENT_SECRET: ${{ secrets.TWILIO_ORGS_CLIENT_SECRET }} + TWILIO_ORG_SID: ${{ secrets.TWILIO_ORG_SID }} run: mvn test -DTest="ClusterTest" -B - uses: actions/setup-java@v4 diff --git a/src/test/java/com/twilio/ClusterTest.java b/src/test/java/com/twilio/ClusterTest.java index 93a92c4cad..a4dc2e5337 100644 --- a/src/test/java/com/twilio/ClusterTest.java +++ b/src/test/java/com/twilio/ClusterTest.java @@ -1,6 +1,7 @@ package com.twilio; import com.twilio.base.Page; + import com.twilio.rest.api.v2010.account.IncomingPhoneNumber; import com.twilio.rest.api.v2010.account.IncomingPhoneNumberReader; import com.twilio.rest.api.v2010.account.Message; @@ -20,9 +21,16 @@ import static org.junit.Assert.*; +import com.twilio.rest.previewiam.organizations.Account; +import com.twilio.base.bearertoken.ResourceSet; + public class ClusterTest { String fromNumber; String toNumber; + String grantType; + String clientId; + String clientSecret; + String organisationSid; @Before public void setUp() { @@ -34,6 +42,12 @@ public void setUp() { String secret = System.getenv("TWILIO_API_SECRET"); String accountSid = System.getenv("TWILIO_ACCOUNT_SID"); Twilio.init(apiKey, secret, accountSid); + + grantType = "client_credentials"; + clientId = System.getenv("TWILIO_ORGS_CLIENT_ID"); + clientSecret = System.getenv("TWILIO_ORGS_CLIENT_SECRET"); + organisationSid = System.getenv("TWILIO_ORG_SID"); + TwilioOrgsTokenAuth.init(grantType, clientId, clientSecret); } @Test @@ -107,4 +121,24 @@ public void testListParams() { assertTrue(Sink.deleter(sink.getSid()).delete()); } + @Test + public void testOrgsApi(){ + + //Fetching the account information + ResourceSet accountSet = Account.reader(organisationSid).read(); + String accountSid = accountSet.iterator().next().getAccountSid(); + assertNotNull(accountSid); + + //Fetching specific account + Account account = Account.fetcher(organisationSid, accountSid).fetch(); + assertNotNull(account.getAccountSid()); + + //Fetching users of this organisation + ResourceSet + userSet = com.twilio.rest.previewiam.organizations.User.reader(organisationSid).read(); + assertNotNull(userSet); + String userId = userSet.iterator().next().getId().toString(); + assertNotNull(userId); + } + }