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: add username data field to metadata call response #127

Merged
merged 1 commit into from
Apr 23, 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
2 changes: 2 additions & 0 deletions src/modules/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class UsersModule extends BaseModule {
email: string | null;
oauth_provider: string | null;
phone_number: string | null;
username: string | null;
wallets: MagicWallet[] | null;
}>(`${this.sdk.apiBaseUrl}/v1/admin/auth/user/get`, this.sdk.secretApiKey, { issuer, wallet_type: walletType });

Expand All @@ -70,6 +71,7 @@ export class UsersModule extends BaseModule {
email: data.email ?? null,
oauthProvider: data.oauth_provider ?? null,
phoneNumber: data.phone_number ?? null,
username: data.username ?? null,
wallets: data.wallets ?? null,
};
}
Expand Down
1 change: 1 addition & 0 deletions src/types/sdk-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ export interface MagicUserMetadata {
email: string | null;
oauthProvider: string | null;
phoneNumber: string | null;
username: string | null;
wallets: MagicWallet[] | null;
}
36 changes: 23 additions & 13 deletions test/spec/modules/users/getMetadataByIssuer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import { createMagicAdminSDK } from '../../../lib/factories';
import { API_KEY } from '../../../lib/constants';
import { createApiKeyMissingError } from '../../../../src/core/sdk-exceptions';
import { get } from '../../../../src/utils/rest';
import { WalletType } from '../../../../src/types/wallet-types';
import { get } from '../../../../src/utils/rest';
import { API_KEY } from '../../../lib/constants';
import { createMagicAdminSDK } from '../../../lib/factories';

const successRes = Promise.resolve({
issuer: 'foo',
public_address: 'bar',
email: 'baz',
oauth_provider: 'foo1',
phone_number: '+1234',
username: 'buzz',
});
const successResWithWallets = Promise.resolve({
issuer: 'foo',
public_address: 'bar',
email: 'baz',
oauth_provider: 'foo1',
phone_number: '+1234',
username: 'buzz',
wallets: [
{
wallet_type: 'SOLANA',
network: 'MAINNET',
public_address: 'barxyz'
}
]
public_address: 'barxyz',
},
],
});
const nullRes = Promise.resolve({});

Expand All @@ -35,18 +37,22 @@ test('Successfully GETs to metadata endpoint via issuer', async () => {

const result = await sdk.users.getMetadataByIssuer('did:ethr:0x1234');

console.log(result);

const getArguments = getStub.mock.calls[0];
expect(getArguments).toEqual([
'https://example.com/v1/admin/auth/user/get',
API_KEY,
{ issuer: 'did:ethr:0x1234', wallet_type: 'NONE'},
{ issuer: 'did:ethr:0x1234', wallet_type: 'NONE' },
]);

expect(result).toEqual({
issuer: 'foo',
publicAddress: 'bar',
email: 'baz',
oauthProvider: 'foo1',
phoneNumber: '+1234',
username: 'buzz',
wallets: null,
});
});
Expand All @@ -71,6 +77,7 @@ test('Successfully GETs `null` metadata endpoint via issuer', async () => {
email: null,
oauthProvider: null,
phoneNumber: null,
username: null,
wallets: null,
});
});
Expand Down Expand Up @@ -108,10 +115,13 @@ test('Successfully GETs to metadata endpoint via issuer and wallet type', async
email: 'baz',
oauthProvider: 'foo1',
phoneNumber: '+1234',
wallets: [{
wallet_type: 'SOLANA',
network: 'MAINNET',
public_address: 'barxyz'
}],
username: 'buzz',
wallets: [
{
wallet_type: 'SOLANA',
network: 'MAINNET',
public_address: 'barxyz',
},
],
});
});
});
Loading