Skip to content

Commit

Permalink
feat: add username data field to metadata call response
Browse files Browse the repository at this point in the history
  • Loading branch information
am-hernandez committed Apr 23, 2024
1 parent cd6661f commit 777ac94
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
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',
},
],
});
});
});

0 comments on commit 777ac94

Please sign in to comment.