Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add cluster tests for orgs api #1054

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
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_ORGS_USER_ID: ${{ secrets.TWILIO_ORGS_USER_ID }}
TWILIO_ORG_SID: ${{ secrets.TWILIO_ORG_SID }}
TWILIO_CLIENT_ID: ${{ secrets.TWILIO_CLIENT_ID }}
TWILIO_CLIENT_SECRET: ${{ secrets.TWILIO_CLIENT_SECRET }}
Expand Down
89 changes: 89 additions & 0 deletions spec/cluster/orgs_api.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
jest.setTimeout(15000);

import twilio from "twilio";

const clientId = process.env.TWILIO_ORGS_CLIENT_ID;
const clientSecret = process.env.TWILIO_ORGS_CLIENT_SECRET;
const organizationSid = process.env.TWILIO_ORG_SID;
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const userId = process.env.TWILIO_ORGS_USER_ID;

const client = twilio();
const orgsCredentialProvider = new twilio.OrgsCredentialProviderBuilder()
.setClientId(clientId)
.setClientSecret(clientSecret)
.build();
client.setCredentialProvider(orgsCredentialProvider);

test("Should generate access token", () => {
const noAuthClient = twilio();
noAuthClient.setCredentialProvider(new twilio.NoAuthCredentialProvider());
return noAuthClient.previewIam.v1.token
.create({
grantType: "client_credentials",
clientId: clientId,
clientSecret: clientSecret,
})
.then((token) => {
expect(token).not.toBeNull();
expect(token.accessToken).not.toBeUndefined();
expect(token.tokenType).toEqual("Bearer");
expect(token.expiresIn).toEqual(86400);
});
});

test("Should list accounts under an organization", () => {
return client.previewIam
.organization(organizationSid)
.accounts.list()
.then((accounts) => {
expect(accounts).not.toBeNull();
expect(accounts).not.toBeUndefined();
expect(accounts.length).toBeGreaterThanOrEqual(0);
});
});

test("Should fetch given account", () => {
return client.previewIam
.organization(organizationSid)
.accounts(accountSid)
.fetch()
.then((account) => {
expect(account).not.toBeNull();
expect(account).not.toBeUndefined();
expect(account.accountSid).toEqual(accountSid);
});
});

test("Should list users", () => {
return client.previewIam
.organization(organizationSid)
.users.list()
.then((users) => {
expect(users).not.toBeNull();
expect(users).not.toBeUndefined();
expect(users.length).toBeGreaterThanOrEqual(0);
});
});

test("Should fetch given user", () => {
return client.previewIam
.organization(organizationSid)
.users(userId)
.fetch()
.then((user) => {
expect(user).not.toBeNull();
expect(user).not.toBeUndefined();
expect(user.id).toEqual(userId);
});
});

test("Should list role assignments", () => {
client.previewIam
.organization(organizationSid)
.roleAssignments.list({ scope: accountSid })
.then((roles) => {
expect(roles).not.toBeNull();
expect(roles.length).toBeGreaterThanOrEqual(0);
});
});
Loading