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

feat: The errors module is now exposed as part of the default entry. This includes various utilities (and type guards) for interacting with responses from services. #166

Merged
merged 3 commits into from
May 13, 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
3 changes: 3 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
env:
PREVIEW_GLOBUS_ID_USERNAME: ${{ secrets.PREVIEW_GLOBUS_ID_USERNAME }}
PREVIEW_GLOBUS_ID_PASSWORD: ${{ secrets.PREVIEW_GLOBUS_ID_PASSWORD }}
- uses: actions/upload-artifact@v4
if: always()
with:
Expand Down
57 changes: 55 additions & 2 deletions e2e/umd.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test';

test('exports as "globus"', async ({ page }) => {
await page.goto('umd.html');
await page.goto('umd');
await expect(page).toHaveTitle('@globus/sdk');

expect(await page.evaluate(() => window.globus.logger)).toBeDefined();
Expand All @@ -19,8 +19,12 @@ test('exports as "globus"', async ({ page }) => {
expect(await page.evaluate(() => window.globus.webapp)).toBeDefined();
});

/**
* Basic E2E test to validate the creation of a AuthorizationManager and
* its ability to initiate the OAuth flow.
*/
test('authorization', async ({ page }) => {
await page.goto('umd-authorization.html');
await page.goto('umd-authorization');
await expect(page).toHaveTitle('@globus/sdk');
await expect(page.getByRole('button')).toHaveText('Sign In');
await page.getByRole('button').click();
Expand All @@ -34,3 +38,52 @@ test('authorization', async ({ page }) => {
expect(url).toContain('scope=openid+profile+email+offline_access');
expect(url).toContain('%26redirect_uri%3Dexample%253A%252F%252Fredirect%26');
});

/**
* Validates the creation of an AuthorizationManager, authentication
* via Globus ID and a basic `ls`.
*/
test('ls', async ({ page }) => {
const USERNAME = process.env.PREVIEW_GLOBUS_ID_USERNAME;
const PASSWORD = process.env.PREVIEW_GLOBUS_ID_PASSWORD;

expect(
USERNAME,
`process.env.PREVIEW_GLOBUS_ID_USERNAME is required to run this test.`,
).toBeDefined();
expect(
PASSWORD,
`process.env.PREVIEW_GLOBUS_ID_PASSWORD is required to run this test.`,
).toBeDefined();

await page.goto('umd-transfer-ls');
await expect(page).toHaveTitle('@globus/sdk');
await expect(page.getByRole('button')).toHaveText('Sign In');

await page.getByRole('button').click();

/**
* Globus Auth – Log In (Account Select)
*/
await page.getByText('Globus ID to sign in').click();
/**
* Globus ID – Log In
*/
await page.getByRole('textbox', { name: 'username' }).fill(USERNAME);
await page.getByRole('textbox', { name: 'password' }).fill(PASSWORD);
await page.getByRole('button', { name: 'Log In' }).click();
/**
* AuthenticationManager bootstrapped to the authenticated state.
*/
await expect(page.getByRole('button')).toHaveText('Sign Out', {
timeout: 10000,
});
/**
* User information was loaded from the token.
*/
await expect(page.locator('#user-information')).not.toBeEmpty();
/**
* The `ls` returned a response.
*/
await expect(page.locator('#ls-response')).not.toBeEmpty();
});
1 change: 1 addition & 0 deletions e2e/www/dist
2 changes: 0 additions & 2 deletions e2e/www/umd-authorization.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
<button id="sign-out" style="display: none">Sign Out</button>
<code><pre id="user-information"></pre></code>
<script>
globus.logger.setLogger(console);
globus.logger.setLogLevel('DEBUG');
const manager = globus.authorization.create({
client: '938f3dce-6782-40e7-872d-2ef94c7b24e7',
redirect: 'example://redirect',
Expand Down
92 changes: 92 additions & 0 deletions e2e/www/umd-transfer-ls.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@globus/sdk</title>
<script src="../../dist/umd/globus.production.js"></script>
</head>
<body>
<body>
<button id="sign-in" style="display: none">Sign In</button>
<button id="sign-out" style="display: none">Sign Out</button>
<code>
<pre id="user-information"></pre>
<pre id="ls-response"></pre>
</code>
<script>
/**
* Use `preview` environment
*/
globalThis.GLOBUS_SDK_ENVIRONMENT = 'preview';

const manager = globus.authorization.create({
// https://app.preview.globus.org/settings/developers/projects/920de059-1f67-42e5-a70f-aef148ad4efe/apps
client: 'cae06dd5-6db5-4013-a7e0-b5b2dc4d5fa9',
redirect: 'http://127.0.0.1:3000/umd-transfer-ls',
scopes: 'urn:globus:auth:scope:transfer.api.globus.org:all',
useRefreshTokens: true,
});

manager.handleCodeRedirect();

const UI = {
SIGN_IN: document.getElementById('sign-in'),
SIGN_OUT: document.getElementById('sign-out'),
USER_INFO: document.getElementById('user-information'),
LS_RESPONSE: document.getElementById('ls-response'),
};

UI.SIGN_IN.addEventListener('click', () => {
manager.login();
});
UI.SIGN_OUT.addEventListener('click', () => {
manager.revoke();
UI.USER_INFO.innerText = '';
UI.SIGN_IN.style.display = 'block';
UI.SIGN_OUT.style.display = 'none';
UI.LS_RESPONSE.innerText = '';
});
if (manager.authenticated) {
UI.USER_INFO.innerText = JSON.stringify(manager.user, null, 2);
UI.SIGN_OUT.style.display = 'block';
/**
* Perform a basic `ls` on a Globus Tutorial Collection
*/
globus.transfer.fileOperations
.ls('dc20d9c0-1fb7-4aee-91e9-2d301197d126', {
headers: {
Authorization: `Bearer ${manager.tokens.transfer.access_token}`,
},
})
.then((response) => response.json())
.then((json) => {
/**
* Update the UI with the raw `ls` response
*/
UI.LS_RESPONSE.innerText = JSON.stringify(json, null, 2);
const isError = globus.errors.isErrorWellFormed(json);
if (isError) {
/**
* If the error is well-formed, the SDK will be able to provide
* default handling. We'll avoid the handler executing automatically
* and instead bind it to the `onclick` event of a new `<button>`.
*/
const handler = manager.handleErrorResponse(json, false);
/**
* If there was an identified error, with a handler, render
* a button that will call the handler on click.
*/
const btn = document.createElement('button');
btn.innerText = 'Handle';
btn.onclick = handler;
document.body.appendChild(btn);
}
});
} else {
UI.SIGN_IN.style.display = 'block';
}
</script>
</body>
</body>
</html>
Loading
Loading