Skip to content

Commit

Permalink
fix: adding cluster tests for orgs api (#804)
Browse files Browse the repository at this point in the history
* adding cluster tests for orgs api
  • Loading branch information
AsabuHere committed Jun 28, 2024
1 parent eecc0cb commit 6d80eb1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions src/test/java/com/twilio/ClusterTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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() {
Expand All @@ -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
Expand Down Expand Up @@ -107,4 +121,24 @@ public void testListParams() {
assertTrue(Sink.deleter(sink.getSid()).delete());
}

@Test
public void testOrgsApi(){

//Fetching the account information
ResourceSet<Account> 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<com.twilio.rest.previewiam.organizations.User>
userSet = com.twilio.rest.previewiam.organizations.User.reader(organisationSid).read();
assertNotNull(userSet);
String userId = userSet.iterator().next().getId().toString();
assertNotNull(userId);
}

}

0 comments on commit 6d80eb1

Please sign in to comment.