Skip to content

Commit

Permalink
fix(auth): update FetchDevicesOutput output type to include name attr…
Browse files Browse the repository at this point in the history
…ibute
  • Loading branch information
Ashwin Kumar committed Feb 3, 2025
1 parent 7b97855 commit 4d48969
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
18 changes: 17 additions & 1 deletion packages/auth/__tests__/providers/cognito/fetchDevices.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,23 @@ describe('fetchDevices', () => {
});

it('should fetch devices and parse client response correctly', async () => {
expect(await fetchDevices()).toEqual([apiOutputDevice]);
const {
id,
name,
attributes,
createDate,
lastAuthenticatedDate,
lastModifiedDate,
} = (await fetchDevices())[0];
expect(id).toEqual(apiOutputDevice.id);
expect(name).toEqual(apiOutputDevice.name);
expect(attributes).toEqual(apiOutputDevice.attributes);
expect(createDate).toEqual(apiOutputDevice.createDate);
expect(lastAuthenticatedDate).toEqual(
apiOutputDevice.lastAuthenticatedDate,
);
expect(lastModifiedDate).toEqual(apiOutputDevice.lastModifiedDate);

expect(mockListDevices).toHaveBeenCalledWith(
expect.objectContaining({ region: 'us-west-2' }),
expect.objectContaining({
Expand Down
6 changes: 4 additions & 2 deletions packages/auth/src/providers/cognito/apis/fetchDevices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
assertTokenProviderConfig,
} from '@aws-amplify/core/internals/utils';

import { FetchDevicesOutput } from '../types';
import { AWSAuthDevice, FetchDevicesOutput } from '../types';
import { DeviceType } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider/types';
import { assertAuthTokens } from '../utils/types';
import { getRegionFromUserPoolId } from '../../../foundation/parsers';
Expand Down Expand Up @@ -77,7 +77,7 @@ const parseDevicesResponse = async (
{},
);

return {
const result: AWSAuthDevice = {
id,
name: deviceName,
attributes,
Expand All @@ -91,6 +91,8 @@ const parseDevicesResponse = async (
? new Date(DeviceLastAuthenticatedDate * 1000)
: undefined,
};

return result;
},
);
};
1 change: 1 addition & 0 deletions packages/auth/src/types/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,5 @@ export interface AWSAuthUser {
*/
export interface AuthDevice {
id: string;
name?: string;
}

0 comments on commit 4d48969

Please sign in to comment.