Skip to content

Commit

Permalink
fix: user constructor from viewer (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
RLesser authored Sep 5, 2024
1 parent 90dc24c commit a87d4fe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,15 @@ export class AtlasUser extends BaseAtlasClass<
needed to make API calls.
*/

// @deprecated
constructor(...args: ViewMakerArgs) {
constructor(...args: ViewMakerArgs | [AtlasViewer]) {
// For the time being, the AtlasUser can be constructed to created a viewer inside of it.
// As time goes on, this will be deprecated.
const viewer = new AtlasViewer(...args);
super(viewer);
if (args[0] instanceof AtlasViewer) {
super(args[0]);
} else {
const viewer = new AtlasViewer(...(args as ViewMakerArgs));
super(viewer);
}
}

protected endpoint() {
Expand Down
13 changes: 13 additions & 0 deletions tests/user.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { test } from 'uvu';
import * as assert from 'uvu/assert';
import { AtlasUser } from '../dist/user.js';
import { AtlasViewer } from '../dist/viewer.js';
import { AtlasOrganization } from '../dist/organization.js';

// TODO - should have a dedicated test account here
Expand Down Expand Up @@ -39,6 +40,18 @@ test('AtlasUser from api key', async () => {
assert.type(user.attr, 'object');
});

test('AtlasUser from AtlasViewer', async () => {
const key = process.env.ATLAS_API_KEY;
if (key === undefined) {
throw new Error('ATLAS_API_KEY not set');
}
const viewer = new AtlasViewer({
useEnvToken: true,
});
const user = await new AtlasUser(viewer).withLoadedAttributes();
assert.type(user.attr, 'object');
});

// TODO - tests for bearer token login
// TODO - tests for anon account

Expand Down

0 comments on commit a87d4fe

Please sign in to comment.