Skip to content
Closed
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
15 changes: 15 additions & 0 deletions .oagen-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
"version": 2,
"language": "node",
"files": [
"src/admin-portal/admin-portal.spec.ts",
"src/admin-portal/admin-portal.ts",
"src/admin-portal/fixtures/generate-link.json",
"src/admin-portal/fixtures/portal-link-response.json",
"src/admin-portal/fixtures/revoke-link.json",
"src/admin-portal/interfaces/generate-link.interface.ts",
"src/admin-portal/interfaces/index.ts",
"src/admin-portal/interfaces/portal-link-response.interface.ts",
"src/admin-portal/interfaces/revoke-link-options.interface.ts",
"src/admin-portal/interfaces/revoke-link.interface.ts",
"src/admin-portal/serializers.spec.ts",
"src/admin-portal/serializers/generate-link.serializer.ts",
"src/admin-portal/serializers/index.ts",
"src/admin-portal/serializers/portal-link-response.serializer.ts",
"src/admin-portal/serializers/revoke-link.serializer.ts",
"src/api-keys/interfaces/create-validation-options.interface.ts",
"src/api-keys/interfaces/delete-api-key-options.interface.ts",
"src/connect/connect.spec.ts",
Expand Down
269 changes: 42 additions & 227 deletions src/admin-portal/admin-portal.spec.ts
Original file line number Diff line number Diff line change
@@ -1,244 +1,59 @@
// This file is auto-generated by oagen. Do not edit.

import fetch from 'jest-fetch-mock';
import { fetchBody, fetchOnce } from '../common/utils/test-utils';
import {
fetchOnce,
fetchURL,
fetchMethod,
fetchBody,
} from '../common/utils/test-utils';
import { WorkOS } from '../workos';
import generateLinkInvalid from './fixtures/generate-link-invalid.json';
import portalLinkResponse from './fixtures/portal-link-response.json';
import { GenerateLinkIntent } from '../common/interfaces';

import portalLinkResponseFixture from './fixtures/portal-link-response.json';

const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');

describe('AdminPortal', () => {
beforeEach(() => fetch.resetMocks());

describe('generateLink', () => {
describe('with a valid organization', () => {
describe('with the sso intent', () => {
it('returns an Admin Portal link', async () => {
fetchOnce(portalLinkResponse, { status: 201 });

const { link } = await workos.adminPortal.generateLink({
intent: GenerateLinkIntent.SSO,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
returnUrl: 'https://www.example.com',
});

expect(fetchBody()).toEqual({
intent: GenerateLinkIntent.SSO,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
return_url: 'https://www.example.com',
});
expect(link).toEqual(
'https://setup.workos.com?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
);
});
});

describe('with the domain_verification intent', () => {
it('returns an Admin Portal link', async () => {
fetchOnce(portalLinkResponse, { status: 201 });

const { link } = await workos.adminPortal.generateLink({
intent: GenerateLinkIntent.DomainVerification,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
returnUrl: 'https://www.example.com',
});

expect(fetchBody()).toEqual({
intent: GenerateLinkIntent.DomainVerification,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
return_url: 'https://www.example.com',
});
expect(link).toEqual(
'https://setup.workos.com?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
);
});
});

describe('with the dsync intent', () => {
it('returns an Admin Portal link', async () => {
fetchOnce(portalLinkResponse, { status: 201 });

const { link } = await workos.adminPortal.generateLink({
intent: GenerateLinkIntent.DSync,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
returnUrl: 'https://www.example.com',
});

expect(fetchBody()).toEqual({
intent: GenerateLinkIntent.DSync,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
return_url: 'https://www.example.com',
});
expect(link).toEqual(
'https://setup.workos.com?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
);
});
});

describe('with the `audit_logs` intent', () => {
it('returns an Admin Portal link', async () => {
fetchOnce(portalLinkResponse, { status: 201 });

const { link } = await workos.adminPortal.generateLink({
intent: GenerateLinkIntent.AuditLogs,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
returnUrl: 'https://www.example.com',
});

expect(fetchBody()).toEqual({
intent: GenerateLinkIntent.AuditLogs,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
return_url: 'https://www.example.com',
});
expect(link).toEqual(
'https://setup.workos.com?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
);
});
});

describe('with the `log_streams` intent', () => {
it('returns an Admin Portal link', async () => {
fetchOnce(portalLinkResponse, { status: 201 });

const { link } = await workos.adminPortal.generateLink({
intent: GenerateLinkIntent.LogStreams,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
returnUrl: 'https://www.example.com',
});

expect(fetchBody()).toEqual({
intent: GenerateLinkIntent.LogStreams,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
return_url: 'https://www.example.com',
});
expect(link).toEqual(
'https://setup.workos.com?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
);
});
});
describe('with the `certificate_renewal` intent', () => {
it('returns an Admin Portal link', async () => {
fetchOnce(portalLinkResponse, { status: 201 });

const { link } = await workos.adminPortal.generateLink({
intent: GenerateLinkIntent.CertificateRenewal,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
returnUrl: 'https://www.example.com',
});

expect(fetchBody()).toEqual({
intent: GenerateLinkIntent.CertificateRenewal,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
return_url: 'https://www.example.com',
});
expect(link).toEqual(
'https://setup.workos.com?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
);
});
});
describe('with the `bring_your_own_key` intent', () => {
it('returns an Admin Portal link', async () => {
fetchOnce(portalLinkResponse, { status: 201 });

const { link } = await workos.adminPortal.generateLink({
intent: GenerateLinkIntent.BringYourOwnKey,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
returnUrl: 'https://www.example.com',
});

expect(fetchBody()).toEqual({
intent: GenerateLinkIntent.BringYourOwnKey,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
return_url: 'https://www.example.com',
});
expect(link).toEqual(
'https://setup.workos.com?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
);
});
});

describe('with intentOptions and adminEmails', () => {
it('serializes the new parameters correctly', async () => {
fetchOnce(portalLinkResponse, { status: 201 });

const { link } = await workos.adminPortal.generateLink({
intent: GenerateLinkIntent.SSO,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
returnUrl: 'https://www.example.com',
intentOptions: {
sso: {
bookmarkSlug: 'chatgpt',
providerType: 'GoogleSAML',
},
},
adminEmails: ['admin@example.com'],
});

expect(fetchBody()).toEqual({
intent: 'sso',
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
return_url: 'https://www.example.com',
intent_options: {
sso: {
bookmark_slug: 'chatgpt',
provider_type: 'GoogleSAML',
},
},
admin_emails: ['admin@example.com'],
});
expect(link).toEqual(
'https://setup.workos.com?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
);
});
});
it('sends the correct request and returns result', async () => {
fetchOnce(portalLinkResponseFixture);

const result = await workos.adminPortal.generateLink({
organization: 'test_organization',
});

expect(fetchMethod()).toBe('POST');
expect(new URL(String(fetchURL())).pathname).toBe(
'/portal/generate_link',
);
expect(fetchBody()).toEqual(
expect.objectContaining({ organization: 'test_organization' }),
);
expect(result.link).toBe(
'https://setup.workos.com/init?apiToken=01EHZNVPK3SFK441A1RGBFSHRT',
);
});
});

describe('with an invalid organization', () => {
it('throws an error', async () => {
fetchOnce(generateLinkInvalid, {
status: 400,
headers: { 'X-Request-ID': 'a-request-id' },
});
describe('revokeLink', () => {
it('sends the request', async () => {
fetchOnce({});

await expect(
workos.adminPortal.generateLink({
intent: GenerateLinkIntent.SSO,
organization: 'bogus-id',
returnUrl: 'https://www.example.com',
}),
).rejects.toThrow(
'Could not find an organization with the id, bogus-id.',
);
expect(fetchBody()).toEqual({
intent: GenerateLinkIntent.SSO,
organization: 'bogus-id',
return_url: 'https://www.example.com',
});
await workos.adminPortal.revokeLink({
organization: 'test_organization',
externalUserId: 'external_user_id_01234',
});
});

describe('with an invalid organization', () => {
it('throws an error', async () => {
fetchOnce(generateLinkInvalid, {
status: 400,
headers: { 'X-Request-ID': 'a-request-id' },
});

await expect(
workos.adminPortal.generateLink({
intent: GenerateLinkIntent.SSO,
organization: 'bogus-id',
returnUrl: 'https://www.example.com',
}),
).rejects.toThrow(
'Could not find an organization with the id, bogus-id.',
);
expect(fetchBody()).toEqual({
intent: GenerateLinkIntent.SSO,
organization: 'bogus-id',
return_url: 'https://www.example.com',
});
});
expect(fetchMethod()).toBe('POST');
expect(new URL(String(fetchURL())).pathname).toBe('/portal/revoke_link');
expect(fetchBody()).toEqual(
expect.objectContaining({
organization: 'test_organization',
external_user_id: 'external_user_id_01234',
}),
);
});
});
});
Loading
Loading